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"
44 static ostream& operator<<(ostream& os, const CORBA::Exception& e)
48 CORBA::TypeCode_var tc = tmp.type();
49 const char *p = tc->name();
50 os<<"Test blocking exception was catch of the kind : ";
62 int main (int argc, char * argv[])
67 // Initializing omniORB
68 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
70 // use IOR to find container
71 //if (argc != 2) { return 1; }
72 //CORBA::Object_var obj = orb->string_to_object(argv[1]);
73 //Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
75 // Obtain a reference to the root POA
77 long TIMESleep = 250000000;
78 int NumberOfTries = 40;
81 ts_req.tv_nsec=TIMESleep;
86 CosNaming::NamingContext_var inc;
87 PortableServer::POA_var poa;
88 CORBA::Object_var theObj;
89 CORBA::Object_var obj;
90 CORBA::Object_var object;
91 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
93 const char * Env = getenv("USE_LOGGER");
95 if ((Env!=NULL) && (strlen(Env)))
99 name[0].id=CORBA::string_dup("Logger");
100 PortableServer::POAManager_var manager;
101 for (int i = 1; i<=NumberOfTries; i++)
104 a=nanosleep(&ts_req,&ts_rem);
107 obj = orb->resolve_initial_references("RootPOA");
108 if(!CORBA::is_nil(obj))
109 poa = PortableServer::POA::_narrow(obj);
110 if(!CORBA::is_nil(poa))
111 manager = poa->the_POAManager();
112 if(!CORBA::is_nil(orb))
113 theObj = orb->resolve_initial_references("NameService");
114 if (!CORBA::is_nil(theObj))
115 inc = CosNaming::NamingContext::_narrow(theObj);
117 catch( CORBA::COMM_FAILURE& )
119 INFOS( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
121 if(!CORBA::is_nil(inc))
123 MESSAGE( "Test Container: Naming Service was found" )
126 for(int j=1; j<=NumberOfTries; j++)
129 a=nanosleep(&ts_req, &ts_rem);
132 object = inc->resolve(name);
134 catch(CosNaming::NamingContext::NotFound)
136 INFOS( "Test Container: Logger Server wasn't found" );
140 INFOS( "Test Container: Unknown exception" );
142 if (!CORBA::is_nil(object))
144 MESSAGE( "Test Container: Loger Server was found" );
151 if ((TEST_CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
155 // Use Name Service to find container
156 SALOME_NamingService _NS(orb) ;
157 string containerName = "/Containers/" ;
158 string hostName = GetHostname();
159 containerName += hostName + "/FactoryServer";
161 obj = _NS.Resolve(containerName.c_str()) ;
162 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
164 Engines::TestComponent_var m1;
166 for (int iter = 0; iter < 3 ; iter++)
168 MESSAGE("----------------------------------------------------" << iter);
169 string dirn = getenv("KERNEL_ROOT_DIR");
170 dirn += "/lib/salome/libSalomeTestComponentEngine.so";
171 obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
172 m1 = Engines::TestComponent::_narrow(obj);
174 SCRUTE(m1->instanceName());
176 Engines::FieldsDict_var dico = new Engines::FieldsDict;
178 dico[0].key=CORBA::string_dup("key_0");
179 dico[0].value <<="value_0";
180 dico[1].key=CORBA::string_dup("key_1");
181 dico[1].value <<=(CORBA::UShort)72;
182 dico[2].key=CORBA::string_dup("key_2");
183 dico[2].value <<="value_2";
184 m1->setProperties(dico);
186 MESSAGE("Coucou " << m1->Coucou(1L));
190 Engines::FieldsDict_var dico2 = m1->getProperties();
191 for (CORBA::ULong i=0; i<dico2->length(); i++)
193 MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
194 MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
195 if (dico2[i].value.type()->kind() == CORBA::tk_string)
198 dico2[i].value >>= value;
199 MESSAGE("dico2["<<i<<"].value="<<value);
203 iGenFact->remove_impl(m1) ;
204 //iGenFact->finalize_removal() ; // unpredictable results ...
208 iGenFact->finalize_removal() ;
211 catch(CORBA::COMM_FAILURE& ex) {
212 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
214 catch(CORBA::SystemException& e) {
215 INFOS("Caught a CORBA::SystemException."<<e)
217 catch(CORBA::Exception& e) {
218 INFOS("Caught CORBA::Exception."<<e)
221 INFOS("Caught unknown exception.")