Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[samples/component.git] / src / TestFunctions / TestFunctionsMemory.cxx
1 //  SuperVisionTest TestFunctionsMemory : Check of memory leaks ...
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : TestFunctionsMemory.cxx
25 //  Author : Jean Rahuel
26 //  Module : SuperVisionTest
27
28 #include <iostream>
29 #include <fstream>
30 #include <unistd.h>
31
32 #include <SALOMEconfig.h>
33 #include CORBA_CLIENT_HEADER(AddComponent)
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35
36 #include "utilities.h"
37 #include "SALOME_NamingService.hxx"
38 #include "SALOME_LifeCycleCORBA.hxx"
39 #include <OpUtil.hxx>
40
41 #include "DynInvoke.hxx"
42
43 using namespace std;
44
45 int main(int argc, char **argv) {
46   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
47   CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
48   PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
49   SALOME_NamingService _NS(orb) ;
50   SALOME_LifeCycleCORBA _LCC(&_NS) ;
51
52   Engines::Component_var AddComponent = _LCC.FindOrLoad_Component( "FactoryServer" ,
53                                                                    "AddComponent");
54   SuperVisionTest::AddComponent_var AddInterface ;
55   AddInterface = SuperVisionTest::AddComponent::_narrow( AddComponent );
56
57   int i ;
58   for ( i = 0 ; i < 10000 ; i++ ) {
59
60 // Direct call to AdditionObjRef1
61     SuperVisionTest::Adder_var Adder1 ;
62     bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
63     double Func1 , z1 ;
64     Func1 = Adder1->AddWithoutSleep( 1. , 2. , z1 ) ;
65     cout << i << ". TestFunctionsMemory sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1 << endl ;
66     Adder1->destroy() ;
67
68 // Call to AdditionObjRef1 via dynamic invocation
69     int ninParams = 0 ;
70     ServicesAnyData * inParams = NULL ;
71     int noutParams = 2 ;
72     ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
73     bool b = 0 ;
74     outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
75     outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
76     DynInvoke( AddInterface , "AdditionObjRef1" , inParams , ninParams ,
77                                                 outParams , noutParams ) ;
78     outParams[ 0 ].Value >>= sts1 ;
79     CORBA::Object_ptr objptr ;
80     outParams[ 1 ].Value >>= objptr ;
81     SuperVisionTest::Adder_var DynAdder1 ;
82     DynAdder1 = SuperVisionTest::Adder::_narrow( objptr ) ;
83     CORBA::release( objptr ) ;
84     Func1 = DynAdder1->AddWithoutSleep( 1. , 2. , z1 ) ;
85     cout << i << ". TestFunctionsMemory DynInvoke sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1
86          << endl ;
87     DynAdder1->destroy() ;
88
89 // Direct call to AdditionObjRef2
90     SuperVisionTest::Adder_var Adder2 ;
91     bool sts2 ;
92     AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
93     double Func2 , z2 ;
94     Func2 = Adder2->AddWithoutSleep( 1. , 2. , z2 ) ;
95     cout << i << ". TestFunctions sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2 << endl ;
96     Adder2->destroy() ;
97
98 // Call to AdditionObjRef2 via dynamic invocation
99     outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
100     outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
101     DynInvoke( AddInterface , "AdditionObjRef2" , inParams , ninParams ,
102                                                 outParams , noutParams ) ;
103     outParams[ 0 ].Value >>= sts2 ;
104     outParams[ 1 ].Value >>= objptr ;
105     SuperVisionTest::Adder_var DynAdder2 ;
106     DynAdder2 = SuperVisionTest::Adder::_narrow( objptr ) ;
107     CORBA::release( objptr ) ;
108     Func2 = DynAdder2->AddWithoutSleep( 1. , 2. , z2 ) ;
109     cout << i << ". TestFunctionsMemory DynInvoke sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2
110          << endl ;
111     DynAdder2->destroy() ;
112
113     delete [] outParams ;
114   }
115
116   return 0;
117 }
118