Salome HOME
7a95f44386321243485b0db5bff497fa8601e8f9
[samples/component.git] / src / TestFunctions / TestFunctionsMemory2.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   SuperVisionTest::Adder_var Adder1 ;
58   bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
59
60   int ninParams = 0 ;
61   ServicesAnyData * inParams = NULL ;
62   int noutParams = 2 ;
63   ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
64   bool b = 0 ;
65   outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
66   outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
67   DynInvoke( AddInterface , "AdditionObjRef1" , inParams , ninParams ,
68                                                 outParams , noutParams ) ;
69   outParams[ 0 ].Value >>= sts1 ;
70   CORBA::Object_ptr objptr ;
71   outParams[ 1 ].Value >>= objptr ;
72   SuperVisionTest::Adder_var DynAdder1 ;
73   DynAdder1 = SuperVisionTest::Adder::_narrow( objptr ) ;
74
75   SuperVisionTest::Adder_var Adder2 ;
76   bool sts2 ;
77   AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
78
79   outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
80   outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
81   DynInvoke( AddInterface , "AdditionObjRef2" , inParams , ninParams ,
82                                                 outParams , noutParams ) ;
83   outParams[ 0 ].Value >>= sts2 ;
84   outParams[ 1 ].Value >>= objptr ;
85   SuperVisionTest::Adder_var DynAdder2 ;
86   DynAdder2 = SuperVisionTest::Adder::_narrow( objptr ) ;
87
88   delete [] outParams ;
89
90   int i ;
91   for ( i = 0 ; i < 10000 ; i++ ) {
92
93     int ninParams = 2 ;
94     ServicesAnyData * inParams = new ServicesAnyData[ninParams] ;
95     int noutParams = 2 ;
96     ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
97
98 // Direct call to AdditionObjRef1
99     double d1 = 1. ;
100     inParams[0].Value <<= d1 ;
101     double d2 = 2. ;
102     inParams[1].Value <<= d2 ;
103     double Func1 = 0. ;
104     outParams[ 0 ].Value <<= Func1 ;
105     double z1 = 0. ;
106     outParams[ 1 ].Value <<= z1 ;
107     DynInvoke( Adder1 , "AddWithoutSleep" , inParams , ninParams ,
108                                             outParams , noutParams ) ;
109     outParams[ 0 ].Value >>= Func1 ;
110     outParams[ 1 ].Value >>= z1 ;
111     cout << i << ". TestFunctionsMemory " << " Func1 " << Func1 << " z1 " << z1 << endl ;
112
113 // Call to AdditionObjRef1 via dynamic invocation
114     Func1 = 0. ;
115     outParams[ 0 ].Value <<= Func1 ;
116     z1 = 0. ;
117     outParams[ 1 ].Value <<= z1 ;
118     DynInvoke( DynAdder1 , "AddWithoutSleep" , inParams , ninParams ,
119                                                outParams , noutParams ) ;
120     outParams[ 0 ].Value >>= Func1 ;
121     outParams[ 1 ].Value >>= z1 ;
122     Func1 = DynAdder1->AddWithoutSleep( 1. , 2. , z1 ) ;
123     cout << i << ". TestFunctionsMemory DynInvoke " << " Func1 " << Func1 << " z1 " << z1
124          << endl ;
125
126 // Direct call to AdditionObjRef2
127     double Func2 = 0. ;
128     outParams[ 0 ].Value <<= Func2 ;
129     double z2 = 0. ;
130     outParams[ 1 ].Value <<= z2 ;
131     DynInvoke( Adder2 , "AddWithoutSleep" , inParams , ninParams ,
132                                             outParams , noutParams ) ;
133     outParams[ 0 ].Value >>= Func2 ;
134     outParams[ 1 ].Value >>= z2 ;
135     cout << i << ". TestFunctions " << " Func2 " << Func2 << " z2 " << z2 << endl ;
136
137 // Call to AdditionObjRef2 via dynamic invocation
138     outParams[ 0 ].Value <<= Func2 ;
139     outParams[ 1 ].Value <<= z2 ;
140     DynInvoke( DynAdder2 , "AddWithoutSleep" , inParams , ninParams ,
141                                                outParams , noutParams ) ;
142     outParams[ 0 ].Value >>= Func2 ;
143     outParams[ 1 ].Value >>= z2 ;
144     cout << i << ". TestFunctionsMemory DynInvoke " << " Func2 " << Func2 << " z2 " << z2
145          << endl ;
146
147     delete [] inParams ;
148     delete [] outParams ;
149
150   }
151
152   Adder1->destroy() ;
153   DynAdder1->destroy() ;
154   Adder2->destroy() ;
155   DynAdder2->destroy() ;
156
157   return 0;
158 }
159