1 // Copyright (C) 2007-2008 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.
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
22 // SALOME TestContainer : test of container creation and its life cycle
23 // File : TestContainer.cxx
24 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
28 #include "utilities.h"
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
37 #include "SALOME_NamingService.hxx"
38 #include "NamingService_WaitForServerReadiness.hxx"
39 #include "Basics_Utils.hxx"
40 #include "Utils_ORB_INIT.hxx"
41 #include "Utils_SINGLETON.hxx"
42 #include "Utils_SALOME_Exception.hxx"
43 #include "Utils_CommException.hxx"
45 static std::ostream& operator<<(std::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 std::string componenttName)
65 #if defined(_DEBUG_) || defined(_DEBUG)
67 iGenFact->load_component_Library(componenttName.c_str());
68 // iGenFact->load_component_Library("SalomeTestComponent");
71 iGenFact->load_component_Library(componenttName.c_str());
73 CORBA::Object_var obj =
74 // iGenFact->create_component_instance("SalomeTestComponent",
75 iGenFact->create_component_instance(componenttName.c_str(),
77 Engines::TestComponent_var anInstance = Engines::TestComponent::_narrow(obj);
78 MESSAGE("create anInstance");
79 SCRUTE(anInstance->instanceName());
80 return anInstance._retn();
83 int main (int argc, char * argv[])
85 // Initializing omniORB
86 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
87 CORBA::ORB_ptr orb = init( argc , argv ) ;
88 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
92 SALOME_NamingService _NS(orb) ;
93 std::string containerName = "/Containers/" ;
94 std::string hostName = Kernel_Utils::GetHostname();
95 containerName += hostName + "/FactoryServer";
96 NamingService_WaitForServerReadiness(&_NS,containerName);
98 CORBA::Object_var obj = _NS.Resolve(containerName.c_str()) ;
99 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
104 std::vector<Engines::TestComponent_var> instances(nbInstances);
106 MESSAGE("------------------------------- create instances ");
107 for (int iter = 0; iter < nbInstances ; iter++)
109 instances[iter] = create_instance(iGenFact,"SalomeTestComponent");
112 MESSAGE("------------------------------ set env instances ");
113 for (int iter = 0; iter < nbInstances ; iter++)
115 Engines::TestComponent_var anInstance = instances[iter];
116 SCRUTE(anInstance->instanceName());
117 Engines::FieldsDict_var dico = new Engines::FieldsDict;
119 dico[0].key=CORBA::string_dup("key_0");
120 dico[0].value <<="value_0";
121 dico[1].key=CORBA::string_dup("key_1");
122 dico[1].value <<=(CORBA::UShort)72;
123 dico[2].key=CORBA::string_dup("key_2");
124 dico[2].value <<=(CORBA::ULong)iter;
125 anInstance->setProperties(dico);
126 MESSAGE("Coucou " << anInstance->Coucou(iter));
127 anInstance->Setenv();
130 MESSAGE("---------------------------------- get instances ");
131 for (int iter = 0; iter < nbInstances ; iter++)
133 Engines::TestComponent_var anInstance = instances[iter];
134 SCRUTE(anInstance->instanceName());
135 Engines::FieldsDict_var dico2 = anInstance->getProperties();
136 for (CORBA::ULong i=0; i<dico2->length(); i++)
138 MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
139 MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
140 if (dico2[i].value.type()->kind() == CORBA::tk_string)
143 dico2[i].value >>= value;
144 MESSAGE("dico2["<<i<<"].value="<<value);
149 MESSAGE("------------------------------- remove instances ");
150 for (int iter = 0; iter < nbInstances ; iter++)
152 Engines::TestComponent_var anInstance = instances[iter];
153 SCRUTE(anInstance->instanceName());
154 iGenFact->remove_impl(anInstance) ;
155 //iGenFact->finalize_removal() ; // unpredictable results ...
157 MESSAGE("------------------------------- PYTHON ");
160 // iGenFact->load_component_Library("SALOME_TestComponentPy");
162 // CORBA::Object_var obj =
163 // iGenFact->create_component_instance("SALOME_TestComponentPy",
165 // Engines::TestComponent_var anInstance =
166 // Engines::TestComponent::_narrow(obj);
167 // MESSAGE("create anInstance");
168 // SCRUTE(anInstance->instanceName());
169 MESSAGE("------------------------------- create instances ");
170 for (int iter = 0; iter < nbInstances ; iter++)
172 instances[iter] = create_instance(iGenFact,"SALOME_TestComponentPy");
175 MESSAGE("---------------------------------- get instances ");
176 for (int iter = 0; iter < nbInstances ; iter++)
178 Engines::TestComponent_var anInstance = instances[iter];
179 SCRUTE(anInstance->instanceName());
180 MESSAGE("Coucou " << anInstance->Coucou(iter));
185 iGenFact->finalize_removal() ;
188 catch(CORBA::COMM_FAILURE& ex) {
189 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
191 catch(CORBA::SystemException& e) {
192 INFOS("Caught a CORBA::SystemException."<<e)
194 catch(CORBA::Exception& e) {
195 INFOS("Caught CORBA::Exception."<<e)
197 catch(ServiceUnreachable& e) {
198 INFOS("Caught Exception. "<<e)
201 INFOS("Caught unknown exception.")
204 // delete myThreadTrace;