Salome HOME
Copyright update 2021
[samples/component.git] / src / TestFunctions / TestFunctionsMemory.cxx
1 // Copyright (C) 2007-2021  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
31 #ifndef WIN32
32 #include <unistd.h>
33 #endif
34
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(AddComponent)
37 #include CORBA_CLIENT_HEADER(SALOME_Component)
38
39 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "SALOME_LifeCycleCORBA.hxx"
42 #include <OpUtil.hxx>
43
44 #include "DynInvoke.hxx"
45
46 using namespace std;
47
48 int main(int argc, char **argv) {
49   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
50   CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
51   PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
52   SALOME_NamingService _NS(orb) ;
53   SALOME_LifeCycleCORBA _LCC(&_NS) ;
54
55   Engines::EngineComponent_var AddComponent = _LCC.FindOrLoad_Component( "FactoryServer" ,
56                                                                          "AddComponent");
57   SuperVisionTest::AddComponent_var AddInterface ;
58   AddInterface = SuperVisionTest::AddComponent::_narrow( AddComponent );
59
60   int i ;
61   for ( i = 0 ; i < 10000 ; i++ ) {
62
63 // Direct call to AdditionObjRef1
64     SuperVisionTest::Adder_var Adder1 ;
65     bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
66     double Func1 , z1 ;
67     Func1 = Adder1->AddWithoutSleep( 1. , 2. , z1 ) ;
68     cout << i << ". TestFunctionsMemory sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1 << endl ;
69     Adder1->destroy() ;
70
71 // Call to AdditionObjRef1 via dynamic invocation
72     int ninParams = 0 ;
73     ServicesAnyData * inParams = NULL ;
74     int noutParams = 2 ;
75     ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
76     bool b = 0 ;
77     outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
78     outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
79     DynInvoke( AddInterface , "AdditionObjRef1" , inParams , ninParams ,
80                                                 outParams , noutParams ) ;
81     outParams[ 0 ].Value >>= sts1 ;
82     CORBA::Object_ptr objptr ;
83     outParams[ 1 ].Value >>= objptr ;
84     SuperVisionTest::Adder_var DynAdder1 ;
85     DynAdder1 = SuperVisionTest::Adder::_narrow( objptr ) ;
86     CORBA::release( objptr ) ;
87     Func1 = DynAdder1->AddWithoutSleep( 1. , 2. , z1 ) ;
88     cout << i << ". TestFunctionsMemory DynInvoke sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1
89          << endl ;
90     DynAdder1->destroy() ;
91
92 // Direct call to AdditionObjRef2
93     SuperVisionTest::Adder_var Adder2 ;
94     bool sts2 ;
95     AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
96     double Func2 , z2 ;
97     Func2 = Adder2->AddWithoutSleep( 1. , 2. , z2 ) ;
98     cout << i << ". TestFunctions sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2 << endl ;
99     Adder2->destroy() ;
100
101 // Call to AdditionObjRef2 via dynamic invocation
102     outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
103     outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
104     DynInvoke( AddInterface , "AdditionObjRef2" , inParams , ninParams ,
105                                                 outParams , noutParams ) ;
106     outParams[ 0 ].Value >>= sts2 ;
107     outParams[ 1 ].Value >>= objptr ;
108     SuperVisionTest::Adder_var DynAdder2 ;
109     DynAdder2 = SuperVisionTest::Adder::_narrow( objptr ) ;
110     CORBA::release( objptr ) ;
111     Func2 = DynAdder2->AddWithoutSleep( 1. , 2. , z2 ) ;
112     cout << i << ". TestFunctionsMemory DynInvoke sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2
113          << endl ;
114     DynAdder2->destroy() ;
115
116     delete [] outParams ;
117   }
118
119   return 0;
120 }