1 // SALOME TestContainer : test of container creation and its life cycle
3 // Copyright (C) 2003 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.
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
24 // File : TestContainer.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 #include "utilities.h"
32 #include <SALOMEconfig.h>
33 #include CORBA_CLIENT_HEADER(SALOME_Component)
34 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
36 #include "SALOME_NamingService.hxx"
37 #include "NamingService_WaitForServerReadiness.hxx"
39 #include "Utils_ORB_INIT.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "Utils_SALOME_Exception.hxx"
42 #include "Utils_CommException.hxx"
45 static ostream& operator<<(ostream& os, const CORBA::Exception& e)
49 CORBA::TypeCode_var tc = tmp.type();
50 const char *p = tc->name();
51 os<<"Test blocking exception was catch of the kind : ";
62 Engines::TestComponent_ptr create_instance(Engines::Container_ptr iGenFact,
63 string componenttName)
66 iGenFact->load_component_Library(componenttName.c_str());
67 // iGenFact->load_component_Library("SalomeTestComponent");
69 CORBA::Object_var obj =
70 // iGenFact->create_component_instance("SalomeTestComponent",
71 iGenFact->create_component_instance(componenttName.c_str(),
73 Engines::TestComponent_var anInstance = Engines::TestComponent::_narrow(obj);
74 MESSAGE("create anInstance");
75 SCRUTE(anInstance->instanceName());
76 return anInstance._retn();
79 int main (int argc, char * argv[])
81 // Initializing omniORB
82 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
83 CORBA::ORB_ptr orb = init( argc , argv ) ;
84 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
88 SALOME_NamingService _NS(orb) ;
89 string containerName = "/Containers/" ;
90 string hostName = GetHostname();
91 containerName += hostName + "/FactoryServer";
92 NamingService_WaitForServerReadiness(&_NS,containerName);
94 CORBA::Object_var obj = _NS.Resolve(containerName.c_str()) ;
95 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
100 vector<Engines::TestComponent_var> instances(nbInstances);
102 MESSAGE("------------------------------- create instances ");
103 for (int iter = 0; iter < nbInstances ; iter++)
105 instances[iter] = create_instance(iGenFact,"SalomeTestComponent");
108 MESSAGE("------------------------------ set env instances ");
109 for (int iter = 0; iter < nbInstances ; iter++)
111 Engines::TestComponent_var anInstance = instances[iter];
112 SCRUTE(anInstance->instanceName());
113 Engines::FieldsDict_var dico = new Engines::FieldsDict;
115 dico[0].key=CORBA::string_dup("key_0");
116 dico[0].value <<="value_0";
117 dico[1].key=CORBA::string_dup("key_1");
118 dico[1].value <<=(CORBA::UShort)72;
119 dico[2].key=CORBA::string_dup("key_2");
120 dico[2].value <<=(CORBA::ULong)iter;
121 anInstance->setProperties(dico);
122 MESSAGE("Coucou " << anInstance->Coucou(iter));
123 anInstance->Setenv();
126 MESSAGE("---------------------------------- get instances ");
127 for (int iter = 0; iter < nbInstances ; iter++)
129 Engines::TestComponent_var anInstance = instances[iter];
130 SCRUTE(anInstance->instanceName());
131 Engines::FieldsDict_var dico2 = anInstance->getProperties();
132 for (CORBA::ULong i=0; i<dico2->length(); i++)
134 MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
135 MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
136 if (dico2[i].value.type()->kind() == CORBA::tk_string)
139 dico2[i].value >>= value;
140 MESSAGE("dico2["<<i<<"].value="<<value);
145 MESSAGE("------------------------------- remove instances ");
146 for (int iter = 0; iter < nbInstances ; iter++)
148 Engines::TestComponent_var anInstance = instances[iter];
149 SCRUTE(anInstance->instanceName());
150 iGenFact->remove_impl(anInstance) ;
151 //iGenFact->finalize_removal() ; // unpredictable results ...
153 MESSAGE("------------------------------- PYTHON ");
156 // iGenFact->load_component_Library("SALOME_TestComponentPy");
158 // CORBA::Object_var obj =
159 // iGenFact->create_component_instance("SALOME_TestComponentPy",
161 // Engines::TestComponent_var anInstance =
162 // Engines::TestComponent::_narrow(obj);
163 // MESSAGE("create anInstance");
164 // SCRUTE(anInstance->instanceName());
165 MESSAGE("------------------------------- create instances ");
166 for (int iter = 0; iter < nbInstances ; iter++)
168 instances[iter] = create_instance(iGenFact,"SALOME_TestComponentPy");
171 MESSAGE("---------------------------------- get instances ");
172 for (int iter = 0; iter < nbInstances ; iter++)
174 Engines::TestComponent_var anInstance = instances[iter];
175 SCRUTE(anInstance->instanceName());
176 MESSAGE("Coucou " << anInstance->Coucou(iter));
181 iGenFact->finalize_removal() ;
184 catch(CORBA::COMM_FAILURE& ex) {
185 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
187 catch(CORBA::SystemException& e) {
188 INFOS("Caught a CORBA::SystemException."<<e)
190 catch(CORBA::Exception& e) {
191 INFOS("Caught CORBA::Exception."<<e)
193 catch(ServiceUnreachable& e) {
194 INFOS("Caught Exception. "<<e)
197 INFOS("Caught unknown exception.")
200 // delete myThreadTrace;