Salome HOME
Revert "Synchronize adm files"
[samples/component.git] / src / TestFunctions / TestFunctionsMemory4.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 //  SuperVisionTest TestFunctionsMemory : Check of memory leaks ...
24 //  File   : TestFunctionsMemory.cxx
25 //  Author : Jean Rahuel
26 //  Module : SuperVisionTest
27 //
28 #include <iostream>
29 #include <fstream>
30 #ifndef WIN32
31 #include <unistd.h>
32 #endif
33
34 #include <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(AddComponent)
36 #include CORBA_CLIENT_HEADER(SALOME_Component)
37
38 #include "utilities.h"
39 #include "SALOME_NamingService.hxx"
40 #include "SALOME_LifeCycleCORBA.hxx"
41 #include <OpUtil.hxx>
42
43 #include "DynInvoke.hxx"
44
45 using namespace std;
46
47 int main(int argc, char **argv) {
48   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
49   CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
50   PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
51   SALOME_NamingService _NS(orb) ;
52   SALOME_LifeCycleCORBA _LCC(&_NS) ;
53
54   Engines::EngineComponent_var AddComponent = _LCC.FindOrLoad_Component( "FactoryServer" ,
55                                                                          "AddComponent");
56   SuperVisionTest::AddComponent_var AddInterface ;
57   AddInterface = SuperVisionTest::AddComponent::_narrow( AddComponent );
58
59   SuperVisionTest::Adder_var Adder1 ;
60   bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
61
62   int ninParams = 0 ;
63   ServicesAnyData * inParams = NULL ;
64   int noutParams = 2 ;
65   ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
66   bool b = 0 ;
67   outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
68   outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
69   DynInvoke( AddInterface , "AdditionObjRef1" , inParams , ninParams ,
70                                                 outParams , noutParams ) ;
71   outParams[ 0 ].Value >>= sts1 ;
72   CORBA::Object_ptr objptr ;
73   outParams[ 1 ].Value >>= objptr ;
74   SuperVisionTest::Adder_var DynAdder1 ;
75   DynAdder1 = SuperVisionTest::Adder::_narrow( objptr ) ;
76
77   SuperVisionTest::Adder_var Adder2 ;
78   bool sts2 ;
79   AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
80
81   outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
82   outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
83   DynInvoke( AddInterface , "AdditionObjRef2" , inParams , ninParams ,
84                                                 outParams , noutParams ) ;
85   outParams[ 0 ].Value >>= sts2 ;
86   outParams[ 1 ].Value >>= objptr ;
87   SuperVisionTest::Adder_var DynAdder2 ;
88   DynAdder2 = SuperVisionTest::Adder::_narrow( objptr ) ;
89
90   delete [] outParams ;
91
92   int i ;
93   for ( i = 0 ; i < 10000 ; i++ ) {
94
95     int ninParams = 2 ;
96     ServicesAnyData * inParams = new ServicesAnyData[ninParams] ;
97     int noutParams = 2 ;
98     ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
99
100 // Direct call to AdditionObjRef1
101     double d1 = 1. ;
102     inParams[0].Name = string( "x1" ) ;
103     inParams[0].Value <<= d1 ;
104     double d2 = 2. ;
105     inParams[1].Name = string( "y1" ) ;
106     inParams[1].Value <<= d2 ;
107     double Func1 = 0. ;
108     outParams[ 0 ].Name = string( "Func1" ) ;
109     outParams[ 0 ].Value <<= Func1 ;
110     double z1 = 0. ;
111     outParams[ 1 ].Name = string( "z1" ) ;
112     outParams[ 1 ].Value <<= z1 ;
113     DynInvoke( Adder1 , "AddWithoutSleep" , inParams , ninParams ,
114                                             outParams , noutParams ) ;
115     outParams[ 0 ].Value >>= Func1 ;
116     outParams[ 1 ].Value >>= z1 ;
117     cout << i << ". TestFunctionsMemory " << " Func1 " << Func1 << " z1 " << z1 << endl ;
118
119 // Call to AdditionObjRef1 via dynamic invocation
120     Func1 = 0. ;
121     outParams[ 0 ].Value <<= Func1 ;
122     z1 = 0. ;
123     outParams[ 1 ].Value <<= z1 ;
124     DynInvoke( DynAdder1 , "AddWithoutSleep" , inParams , ninParams ,
125                                                outParams , noutParams ) ;
126     outParams[ 0 ].Value >>= Func1 ;
127     outParams[ 1 ].Value >>= z1 ;
128     Func1 = DynAdder1->AddWithoutSleep( 1. , 2. , z1 ) ;
129     cout << i << ". TestFunctionsMemory DynInvoke " << " Func1 " << Func1 << " z1 " << z1
130          << endl ;
131
132 // Direct call to AdditionObjRef2
133     inParams[0].Name = string( "x2" ) ;
134     inParams[1].Name = string( "y2" ) ;
135     double Func2 = 0. ;
136     outParams[ 0 ].Name = string( "Func2" ) ;
137     outParams[ 0 ].Value <<= Func2 ;
138     double z2 = 0. ;
139     outParams[ 1 ].Name = string( "z2" ) ;
140     outParams[ 1 ].Value <<= z2 ;
141     DynInvoke( Adder2 , "AddWithoutSleep" , inParams , ninParams ,
142                                             outParams , noutParams ) ;
143     outParams[ 0 ].Value >>= Func2 ;
144     outParams[ 1 ].Value >>= z2 ;
145     cout << i << ". TestFunctions " << " Func2 " << Func2 << " z2 " << z2 << endl ;
146
147 // Call to AdditionObjRef2 via dynamic invocation
148     outParams[ 0 ].Value <<= Func2 ;
149     outParams[ 1 ].Value <<= z2 ;
150     DynInvoke( DynAdder2 , "AddWithoutSleep" , inParams , ninParams ,
151                                                outParams , noutParams ) ;
152     outParams[ 0 ].Value >>= Func2 ;
153     outParams[ 1 ].Value >>= z2 ;
154     cout << i << ". TestFunctionsMemory DynInvoke " << " Func2 " << Func2 << " z2 " << z2
155          << endl ;
156
157     delete [] inParams ;
158     delete [] outParams ;
159
160   }
161
162   Adder1->destroy() ;
163   DynAdder1->destroy() ;
164   Adder2->destroy() ;
165   DynAdder2->destroy() ;
166
167   return 0;
168 }