1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SuperVisionTest TestFunctionsMemory : Check of memory leaks ...
24 // File : TestFunctionsMemory.cxx
25 // Author : Jean Rahuel
26 // Module : SuperVisionTest
34 #include <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(AddComponent)
36 #include CORBA_CLIENT_HEADER(SALOME_Component)
38 #include "utilities.h"
39 #include "SALOME_NamingService.hxx"
40 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "DynInvoke.hxx"
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) ;
54 Engines::EngineComponent_var AddComponent = _LCC.FindOrLoad_Component( "FactoryServer" ,
56 SuperVisionTest::AddComponent_var AddInterface ;
57 AddInterface = SuperVisionTest::AddComponent::_narrow( AddComponent );
59 SuperVisionTest::Adder_var Adder1 ;
60 bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
63 ServicesAnyData * inParams = NULL ;
65 ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
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 ) ;
77 SuperVisionTest::Adder_var Adder2 ;
79 AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
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 ) ;
93 for ( i = 0 ; i < 10000 ; i++ ) {
96 ServicesAnyData * inParams = new ServicesAnyData[ninParams] ;
98 ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
100 // Direct call to AdditionObjRef1
102 inParams[0].Name = string( "x1" ) ;
103 inParams[0].Value <<= d1 ;
105 inParams[1].Name = string( "y1" ) ;
106 inParams[1].Value <<= d2 ;
108 outParams[ 0 ].Name = string( "Func1" ) ;
109 outParams[ 0 ].Value <<= Func1 ;
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 ;
119 // Call to AdditionObjRef1 via dynamic invocation
121 outParams[ 0 ].Value <<= Func1 ;
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
132 // Direct call to AdditionObjRef2
133 inParams[0].Name = string( "x2" ) ;
134 inParams[1].Name = string( "y2" ) ;
136 outParams[ 0 ].Name = string( "Func2" ) ;
137 outParams[ 0 ].Value <<= Func2 ;
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 ;
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
158 delete [] outParams ;
163 DynAdder1->destroy() ;
165 DynAdder2->destroy() ;