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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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"
43 #include "SALOMETraceCollector.hxx"
46 static ostream& operator<<(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_intance(Engines::Container_ptr iGenFact)
66 iGenFact->load_component_Library("SalomeTestComponent");
68 CORBA::Object_var obj =
69 iGenFact->create_component_instance("SalomeTestComponent",
71 Engines::TestComponent_var anInstance = Engines::TestComponent::_narrow(obj);
72 MESSAGE("create anInstance");
73 SCRUTE(anInstance->instanceName());
74 return anInstance._retn();
77 int main (int argc, char * argv[])
79 // Initializing omniORB
80 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
81 CORBA::ORB_var &orb = init( argc , argv ) ;
82 SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
86 SALOME_NamingService _NS(orb) ;
87 string containerName = "/Containers/" ;
88 string hostName = GetHostname();
89 containerName += hostName + "/FactoryServer";
90 NamingService_WaitForServerReadiness(&_NS,containerName);
92 CORBA::Object_var obj = _NS.Resolve(containerName.c_str()) ;
93 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
97 vector<Engines::TestComponent_var> instances(nbInstances);
99 MESSAGE("------------------------------- create instances ");
100 for (int iter = 0; iter < nbInstances ; iter++)
102 instances[iter] = create_intance(iGenFact);
105 MESSAGE("------------------------------ set env instances ");
106 for (int iter = 0; iter < nbInstances ; iter++)
108 Engines::TestComponent_var anInstance = instances[iter];
109 SCRUTE(anInstance->instanceName());
110 Engines::FieldsDict_var dico = new Engines::FieldsDict;
112 dico[0].key=CORBA::string_dup("key_0");
113 dico[0].value <<="value_0";
114 dico[1].key=CORBA::string_dup("key_1");
115 dico[1].value <<=(CORBA::UShort)72;
116 dico[2].key=CORBA::string_dup("key_2");
117 dico[2].value <<=(CORBA::ULong)iter;
118 anInstance->setProperties(dico);
119 MESSAGE("Coucou " << anInstance->Coucou(iter));
120 anInstance->Setenv();
123 MESSAGE("---------------------------------- get instances ");
124 for (int iter = 0; iter < nbInstances ; iter++)
126 Engines::TestComponent_var anInstance = instances[iter];
127 SCRUTE(anInstance->instanceName());
128 Engines::FieldsDict_var dico2 = anInstance->getProperties();
129 for (CORBA::ULong i=0; i<dico2->length(); i++)
131 MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
132 MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
133 if (dico2[i].value.type()->kind() == CORBA::tk_string)
136 dico2[i].value >>= value;
137 MESSAGE("dico2["<<i<<"].value="<<value);
142 MESSAGE("------------------------------- remove instances ");
143 for (int iter = 0; iter < nbInstances ; iter++)
145 Engines::TestComponent_var anInstance = instances[iter];
146 SCRUTE(anInstance->instanceName());
147 iGenFact->remove_impl(anInstance) ;
148 //iGenFact->finalize_removal() ; // unpredictable results ...
152 iGenFact->finalize_removal() ;
155 catch(CORBA::COMM_FAILURE& ex) {
156 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
158 catch(CORBA::SystemException& e) {
159 INFOS("Caught a CORBA::SystemException."<<e)
161 catch(CORBA::Exception& e) {
162 INFOS("Caught CORBA::Exception."<<e)
165 INFOS("Caught unknown exception.")
168 delete myThreadTrace;