X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FTestContainer%2FTestContainer.cxx;h=2f86fd9420edce0a2038e4d7ec2eb7d11e060371;hb=a63265d524e8436588a7bb82147a69812c153b1b;hp=3ebb10ee22dd1d415df54c0efbba365c13df06ea;hpb=6dd1af68fb168b4df7558ebf8e7ffe6c4abbfc5b;p=modules%2Fkernel.git diff --git a/src/TestContainer/TestContainer.cxx b/src/TestContainer/TestContainer.cxx index 3ebb10ee2..2f86fd942 100644 --- a/src/TestContainer/TestContainer.cxx +++ b/src/TestContainer/TestContainer.cxx @@ -1,181 +1,205 @@ -// SALOME TestContainer : test of container creation and its life cycle +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + +// SALOME TestContainer : test of container creation and its life cycle // File : TestContainer.cxx // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA // Module : SALOME // $Header$ - +// #include "utilities.h" #include +#ifndef WIN32 #include +#endif #include #include CORBA_CLIENT_HEADER(SALOME_Component) #include CORBA_CLIENT_HEADER(SALOME_TestComponent) #include "SALOME_NamingService.hxx" -#include "OpUtil.hxx" +#include "NamingService_WaitForServerReadiness.hxx" +#include "Basics_Utils.hxx" #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "Utils_SALOME_Exception.hxx" #include "Utils_CommException.hxx" -using namespace std; + +static std::ostream& operator<<(std::ostream& os, const CORBA::Exception& e) +{ + CORBA::Any tmp; + tmp<<= e; + CORBA::TypeCode_var tc = tmp.type(); + const char *p = tc->name(); + os<<"Test blocking exception was catch of the kind : "; + if ( *p != '\0' ) { + os<id(); + } + + return os; +} + +Engines::TestComponent_ptr create_instance(Engines::Container_ptr iGenFact, + std::string componenttName) +{ + char* reason; +#if defined(_DEBUG_) || defined(_DEBUG) + bool isLib = + iGenFact->load_component_Library(componenttName.c_str(),reason); + ASSERT(isLib); +#else + iGenFact->load_component_Library(componenttName.c_str(),reason); +#endif + CORBA::string_free(reason); + CORBA::Object_var obj = iGenFact->create_component_instance(componenttName.c_str(), 0); + Engines::TestComponent_var anInstance = Engines::TestComponent::_narrow(obj); + MESSAGE("create anInstance"); + SCRUTE(anInstance->instanceName()); + return anInstance._retn(); +} int main (int argc, char * argv[]) { + // Initializing omniORB + ORB_INIT &init = *SINGLETON_::Instance() ; + CORBA::ORB_ptr orb = init( argc , argv ) ; + // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); try { - // Initializing omniORB - CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); - - // use IOR to find container - //if (argc != 2) { return 1; } - //CORBA::Object_var obj = orb->string_to_object(argv[1]); - //Engines::Container_var iGenFact = Engines::Container::_narrow(obj); - - // Obtain a reference to the root POA - // - long TIMESleep = 250000000; - int NumberOfTries = 40; - int a; - timespec ts_req; - ts_req.tv_nsec=TIMESleep; - ts_req.tv_sec=0; - timespec ts_rem; - ts_rem.tv_nsec=0; - ts_rem.tv_sec=0; - CosNaming::NamingContext_var inc; - PortableServer::POA_var poa; - CORBA::Object_var theObj; - CORBA::Object_var obj; - CORBA::Object_var object; - SALOME_NamingService &naming = *SINGLETON_::Instance() ; - int TEST_CONTAINER=0; - const char * Env = getenv("USE_LOGGER"); - int EnvL =0; - if ((Env!=NULL) && (strlen(Env))) - EnvL=1; - CosNaming::Name name; - name.length(1); - name[0].id=CORBA::string_dup("Logger"); - PortableServer::POAManager_var manager; - for (int i = 1; i<=NumberOfTries; i++) - { - if (i!=1) - a=nanosleep(&ts_req,&ts_rem); - try - { - obj = orb->resolve_initial_references("RootPOA"); - if(!CORBA::is_nil(obj)) - poa = PortableServer::POA::_narrow(obj); - if(!CORBA::is_nil(poa)) - manager = poa->the_POAManager(); - if(!CORBA::is_nil(orb)) - theObj = orb->resolve_initial_references("NameService"); - if (!CORBA::is_nil(theObj)) - inc = CosNaming::NamingContext::_narrow(theObj); - } - catch( CORBA::COMM_FAILURE& ) - { - MESSAGE( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ) - } - if(!CORBA::is_nil(inc)) - { - MESSAGE( "Test Container: Naming Service was found" ) - if(EnvL==1) - { - for(int j=1; j<=NumberOfTries; j++) - { - if (j!=1) - a=nanosleep(&ts_req, &ts_rem); - try - { - object = inc->resolve(name); - } - catch(CosNaming::NamingContext::NotFound) - { - MESSAGE( "Test Container: Logger Server wasn't found" ); - } - catch(...) - { - MESSAGE( "Test Container: Unknown exception" ); - } - if (!CORBA::is_nil(object)) - { - MESSAGE( "Test Container: Loger Server was found" ); - TEST_CONTAINER=1; - break; - } - } - } - } - if ((TEST_CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc)))) - break; - } - - // Use Name Service to find container SALOME_NamingService _NS(orb) ; - string containerName = "/Containers/" ; - string hostName = GetHostname(); + std::string containerName = "/Containers/" ; + std::string hostName = Kernel_Utils::GetHostname(); containerName += hostName + "/FactoryServer"; + NamingService_WaitForServerReadiness(&_NS,containerName); - obj = _NS.Resolve(containerName.c_str()) ; + CORBA::Object_var obj = _NS.Resolve(containerName.c_str()) ; Engines::Container_var iGenFact = Engines::Container::_narrow(obj); + iGenFact->ping() ; + + int nbInstances = 5; - Engines::TestComponent_var m1; + std::vector instances(nbInstances); - for (int iter = 0; iter < 3 ; iter++) - { - INFOS("----------------------------------------------------" << iter); - string dirn = getenv("KERNEL_ROOT_DIR"); - dirn += "/lib/salome/libSalomeTestComponentEngine.so"; - obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str()); - m1 = Engines::TestComponent::_narrow(obj); - INFOS("recup m1"); - SCRUTE(m1->instanceName()); - INFOS("Coucou " << m1->Coucou(1L)); - iGenFact->remove_impl(m1) ; - //iGenFact->finalize_removal() ; // unpredictable results ... - sleep(5); - } + MESSAGE("------------------------------- create instances "); + for (int iter = 0; iter < nbInstances ; iter++) + { + instances[iter] = create_instance(iGenFact,"SalomeTestComponent"); + } + + MESSAGE("------------------------------ set env instances "); + for (int iter = 0; iter < nbInstances ; iter++) + { + Engines::TestComponent_var anInstance = instances[iter]; + SCRUTE(anInstance->instanceName()); + Engines::FieldsDict_var dico = new Engines::FieldsDict; + dico->length(3); + dico[0].key=CORBA::string_dup("key_0"); + dico[0].value <<="value_0"; + dico[1].key=CORBA::string_dup("key_1"); + dico[1].value <<=(CORBA::UShort)72; + dico[2].key=CORBA::string_dup("key_2"); + dico[2].value <<=(CORBA::ULong)iter; + anInstance->setProperties(dico); + MESSAGE("Coucou " << anInstance->Coucou(iter)); + anInstance->Setenv(); + } + + MESSAGE("---------------------------------- get instances "); + for (int iter = 0; iter < nbInstances ; iter++) + { + Engines::TestComponent_var anInstance = instances[iter]; + SCRUTE(anInstance->instanceName()); + Engines::FieldsDict_var dico2 = anInstance->getProperties(); + for (CORBA::ULong i=0; ilength(); i++) + { + MESSAGE("dico2["<instanceName()); + iGenFact->remove_impl(anInstance) ; + //iGenFact->finalize_removal() ; // unpredictable results ... + } + MESSAGE("------------------------------- PYTHON "); + { +// bool isLib = +// iGenFact->load_component_Library("SALOME_TestComponentPy"); +// ASSERT(isLib); +// CORBA::Object_var obj = +// iGenFact->create_component_instance("SALOME_TestComponentPy", +// 0); +// Engines::TestComponent_var anInstance = +// Engines::TestComponent::_narrow(obj); +// MESSAGE("create anInstance"); +// SCRUTE(anInstance->instanceName()); + MESSAGE("------------------------------- create instances "); + for (int iter = 0; iter < nbInstances ; iter++) + { + instances[iter] = create_instance(iGenFact,"SALOME_TestComponentPy"); + } + + MESSAGE("---------------------------------- get instances "); + for (int iter = 0; iter < nbInstances ; iter++) + { + Engines::TestComponent_var anInstance = instances[iter]; + SCRUTE(anInstance->instanceName()); + MESSAGE("Coucou " << anInstance->Coucou(iter)); + } + } + // Clean-up. iGenFact->finalize_removal() ; - orb->destroy(); + orb->shutdown(0); } catch(CORBA::COMM_FAILURE& ex) { INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.") } - catch(CORBA::SystemException&) { - INFOS("Caught a CORBA::SystemException.") + catch(CORBA::SystemException& e) { + INFOS("Caught a CORBA::SystemException."<