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"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
40 #include "Utils_SALOME_Exception.hxx"
41 #include "Utils_CommException.hxx"
42 #include "SALOMETraceCollector.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 : ";
63 int main (int argc, char * argv[])
66 // Initializing omniORB
67 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
68 CORBA::ORB_var &orb = init( argc , argv ) ;
69 SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
76 // use IOR to find container
77 //if (argc != 2) { return 1; }
78 //CORBA::Object_var obj = orb->string_to_object(argv[1]);
79 //Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
81 // Obtain a reference to the root POA
83 long TIMESleep = 250000000;
84 int NumberOfTries = 40;
87 ts_req.tv_nsec=TIMESleep;
92 CosNaming::NamingContext_var inc;
93 PortableServer::POA_var poa;
94 CORBA::Object_var theObj;
95 CORBA::Object_var obj;
96 CORBA::Object_var object;
97 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
99 const char * Env = getenv("USE_LOGGER");
101 if ((Env!=NULL) && (strlen(Env)))
103 CosNaming::Name name;
105 name[0].id=CORBA::string_dup("Logger");
106 PortableServer::POAManager_var manager;
107 for (int i = 1; i<=NumberOfTries; i++)
110 a=nanosleep(&ts_req,&ts_rem);
113 obj = orb->resolve_initial_references("RootPOA");
114 if(!CORBA::is_nil(obj))
115 poa = PortableServer::POA::_narrow(obj);
116 if(!CORBA::is_nil(poa))
117 manager = poa->the_POAManager();
118 if(!CORBA::is_nil(orb))
119 theObj = orb->resolve_initial_references("NameService");
120 if (!CORBA::is_nil(theObj))
121 inc = CosNaming::NamingContext::_narrow(theObj);
123 catch( CORBA::SystemException& )
125 INFOS( "Test Container: CORBA::SystemException: Unable to contact the Naming Service" )
127 if(!CORBA::is_nil(inc))
129 MESSAGE( "Test Container: Naming Service was found" )
132 for(int j=1; j<=NumberOfTries; j++)
135 a=nanosleep(&ts_req, &ts_rem);
138 object = inc->resolve(name);
140 catch(CosNaming::NamingContext::NotFound)
142 INFOS( "Test Container: Logger Server wasn't found" );
146 INFOS( "Test Container: Unknown exception" );
148 if (!CORBA::is_nil(object))
150 MESSAGE( "Test Container: Loger Server was found" );
157 if ((TEST_CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
161 // Use Name Service to find container
162 SALOME_NamingService _NS(orb) ;
163 string containerName = "/Containers/" ;
164 string hostName = GetHostname();
165 containerName += hostName + "/FactoryServer";
167 obj = _NS.Resolve(containerName.c_str()) ;
168 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
170 Engines::TestComponent_var m1;
172 for (int iter = 0; iter < 3 ; iter++)
174 MESSAGE("----------------------------------------------------" << iter);
175 string dirn = getenv("KERNEL_ROOT_DIR");
176 dirn += "/lib/salome/libSalomeTestComponentEngine.so";
177 obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
178 m1 = Engines::TestComponent::_narrow(obj);
180 SCRUTE(m1->instanceName());
182 Engines::FieldsDict_var dico = new Engines::FieldsDict;
184 dico[0].key=CORBA::string_dup("key_0");
185 dico[0].value <<="value_0";
186 dico[1].key=CORBA::string_dup("key_1");
187 dico[1].value <<=(CORBA::UShort)72;
188 dico[2].key=CORBA::string_dup("key_2");
189 dico[2].value <<="value_2";
190 m1->setProperties(dico);
192 MESSAGE("Coucou " << m1->Coucou(1L));
196 Engines::FieldsDict_var dico2 = m1->getProperties();
197 for (CORBA::ULong i=0; i<dico2->length(); i++)
199 MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
200 MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
201 if (dico2[i].value.type()->kind() == CORBA::tk_string)
204 dico2[i].value >>= value;
205 MESSAGE("dico2["<<i<<"].value="<<value);
209 iGenFact->remove_impl(m1) ;
210 //iGenFact->finalize_removal() ; // unpredictable results ...
214 iGenFact->finalize_removal() ;
217 catch(CORBA::COMM_FAILURE& ex) {
218 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
220 catch(CORBA::SystemException& e) {
221 INFOS("Caught a CORBA::SystemException."<<e)
223 catch(CORBA::Exception& e) {
224 INFOS("Caught CORBA::Exception."<<e)
227 INFOS("Caught unknown exception.")
230 delete myThreadTrace;