Salome HOME
e8c4ae3e4abaa7d876698a98c35cf9ae401d2b25
[samples/component.git] / src / TestFunctions / TestFunctionsMemory.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   int i ;
57   for ( i = 0 ; i < 10000 ; i++ ) {
58
59 // Direct call to AdditionObjRef1
60     SuperVisionTest::Adder_var Adder1 ;
61     bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
62     double Func1 , z1 ;
63     Func1 = Adder1->AddWithoutSleep( 1. , 2. , z1 ) ;
64     cout << i << ". TestFunctionsMemory sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1 << endl ;
65     Adder1->destroy() ;
66
67 // Call to AdditionObjRef1 via dynamic invocation
68     int ninParams = 0 ;
69     ServicesAnyData * inParams = NULL ;
70     int noutParams = 2 ;
71     ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
72     bool b = 0 ;
73     outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
74     outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
75     DynInvoke( AddInterface , "AdditionObjRef1" , inParams , ninParams ,
76                                                 outParams , noutParams ) ;
77     outParams[ 0 ].Value >>= sts1 ;
78     CORBA::Object_ptr objptr ;
79     outParams[ 1 ].Value >>= objptr ;
80     SuperVisionTest::Adder_var DynAdder1 ;
81     DynAdder1 = SuperVisionTest::Adder::_narrow( objptr ) ;
82     CORBA::release( objptr ) ;
83     Func1 = DynAdder1->AddWithoutSleep( 1. , 2. , z1 ) ;
84     cout << i << ". TestFunctionsMemory DynInvoke sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1
85          << endl ;
86     DynAdder1->destroy() ;
87
88 // Direct call to AdditionObjRef2
89     SuperVisionTest::Adder_var Adder2 ;
90     bool sts2 ;
91     AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
92     double Func2 , z2 ;
93     Func2 = Adder2->AddWithoutSleep( 1. , 2. , z2 ) ;
94     cout << i << ". TestFunctions sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2 << endl ;
95     Adder2->destroy() ;
96
97 // Call to AdditionObjRef2 via dynamic invocation
98     outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
99     outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
100     DynInvoke( AddInterface , "AdditionObjRef2" , inParams , ninParams ,
101                                                 outParams , noutParams ) ;
102     outParams[ 0 ].Value >>= sts2 ;
103     outParams[ 1 ].Value >>= objptr ;
104     SuperVisionTest::Adder_var DynAdder2 ;
105     DynAdder2 = SuperVisionTest::Adder::_narrow( objptr ) ;
106     CORBA::release( objptr ) ;
107     Func2 = DynAdder2->AddWithoutSleep( 1. , 2. , z2 ) ;
108     cout << i << ". TestFunctionsMemory DynInvoke sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2
109          << endl ;
110     DynAdder2->destroy() ;
111
112     delete [] outParams ;
113   }
114
115   return 0;
116 }
117