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