1 // Copyright (C) 2007-2013 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
23 // SALOME TestContainer : test of container creation and its life cycle
24 // File : TestContainer.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 #include "utilities.h"
34 #include <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(SALOME_Component)
36 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
38 #include "SALOME_NamingService.hxx"
39 #include "NamingService_WaitForServerReadiness.hxx"
40 #include "Basics_Utils.hxx"
41 #include "Utils_ORB_INIT.hxx"
42 #include "Utils_SINGLETON.hxx"
43 #include "Utils_SALOME_Exception.hxx"
44 #include "Utils_CommException.hxx"
46 static std::ostream& operator<<(std::ostream& os, const CORBA::Exception& e)
50 CORBA::TypeCode_var tc = tmp.type();
51 const char *p = tc->name();
52 os<<"Test blocking exception was catch of the kind : ";
63 Engines::TestComponent_ptr create_instance(Engines::Container_ptr iGenFact,
64 std::string componenttName)
67 #if defined(_DEBUG_) || defined(_DEBUG)
69 iGenFact->load_component_Library(componenttName.c_str(),reason);
72 iGenFact->load_component_Library(componenttName.c_str(),reason);
74 CORBA::string_free(reason);
75 CORBA::Object_var obj = iGenFact->create_component_instance(componenttName.c_str(), 0);
76 Engines::TestComponent_var anInstance = Engines::TestComponent::_narrow(obj);
77 MESSAGE("create anInstance");
78 SCRUTE(anInstance->instanceName());
79 return anInstance._retn();
82 int main (int argc, char * argv[])
84 // Initializing omniORB
85 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
86 CORBA::ORB_ptr orb = init( argc , argv ) ;
87 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
91 SALOME_NamingService _NS(orb) ;
92 std::string containerName = "/Containers/" ;
93 std::string hostName = Kernel_Utils::GetHostname();
94 containerName += hostName + "/FactoryServer";
95 NamingService_WaitForServerReadiness(&_NS,containerName);
97 CORBA::Object_var obj = _NS.Resolve(containerName.c_str()) ;
98 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
103 std::vector<Engines::TestComponent_var> instances(nbInstances);
105 MESSAGE("------------------------------- create instances ");
106 for (int iter = 0; iter < nbInstances ; iter++)
108 instances[iter] = create_instance(iGenFact,"SalomeTestComponent");
111 MESSAGE("------------------------------ set env instances ");
112 for (int iter = 0; iter < nbInstances ; iter++)
114 Engines::TestComponent_var anInstance = instances[iter];
115 SCRUTE(anInstance->instanceName());
116 Engines::FieldsDict_var dico = new Engines::FieldsDict;
118 dico[0].key=CORBA::string_dup("key_0");
119 dico[0].value <<="value_0";
120 dico[1].key=CORBA::string_dup("key_1");
121 dico[1].value <<=(CORBA::UShort)72;
122 dico[2].key=CORBA::string_dup("key_2");
123 dico[2].value <<=(CORBA::ULong)iter;
124 anInstance->setProperties(dico);
125 MESSAGE("Coucou " << anInstance->Coucou(iter));
126 anInstance->Setenv();
129 MESSAGE("---------------------------------- get instances ");
130 for (int iter = 0; iter < nbInstances ; iter++)
132 Engines::TestComponent_var anInstance = instances[iter];
133 SCRUTE(anInstance->instanceName());
134 Engines::FieldsDict_var dico2 = anInstance->getProperties();
135 for (CORBA::ULong i=0; i<dico2->length(); i++)
137 MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
138 MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
139 if (dico2[i].value.type()->kind() == CORBA::tk_string)
142 dico2[i].value >>= value;
143 MESSAGE("dico2["<<i<<"].value="<<value);
148 MESSAGE("------------------------------- remove instances ");
149 for (int iter = 0; iter < nbInstances ; iter++)
151 Engines::TestComponent_var anInstance = instances[iter];
152 SCRUTE(anInstance->instanceName());
153 iGenFact->remove_impl(anInstance) ;
154 //iGenFact->finalize_removal() ; // unpredictable results ...
156 MESSAGE("------------------------------- PYTHON ");
159 // iGenFact->load_component_Library("SALOME_TestComponentPy");
161 // CORBA::Object_var obj =
162 // iGenFact->create_component_instance("SALOME_TestComponentPy",
164 // Engines::TestComponent_var anInstance =
165 // Engines::TestComponent::_narrow(obj);
166 // MESSAGE("create anInstance");
167 // SCRUTE(anInstance->instanceName());
168 MESSAGE("------------------------------- create instances ");
169 for (int iter = 0; iter < nbInstances ; iter++)
171 instances[iter] = create_instance(iGenFact,"SALOME_TestComponentPy");
174 MESSAGE("---------------------------------- get instances ");
175 for (int iter = 0; iter < nbInstances ; iter++)
177 Engines::TestComponent_var anInstance = instances[iter];
178 SCRUTE(anInstance->instanceName());
179 MESSAGE("Coucou " << anInstance->Coucou(iter));
184 iGenFact->finalize_removal() ;
187 catch(CORBA::COMM_FAILURE& ex) {
188 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
190 catch(CORBA::SystemException& e) {
191 INFOS("Caught a CORBA::SystemException."<<e)
193 catch(CORBA::Exception& e) {
194 INFOS("Caught CORBA::Exception."<<e)
196 catch(ServiceUnreachable& e) {
197 INFOS("Caught Exception. "<<e)
200 INFOS("Caught unknown exception.")
203 // delete myThreadTrace;