X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FNamingService%2FTest%2FNamingServiceTest.cxx;h=310b0dd6a725684699b07dc07ac4508b15c7faa3;hb=9099891d41576c1359123b6f25e4c19aff0b91bd;hp=deedb2b6141ae49ade7df9a69a365b21c9cfaf02;hpb=8d460095eb020326e642fd2021c1f613e785b744;p=modules%2Fkernel.git diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx index deedb2b61..310b0dd6a 100644 --- a/src/NamingService/Test/NamingServiceTest.cxx +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -1,7 +1,31 @@ +// Copyright (C) 2007-2015 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. +// +// 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 +// #include "NamingServiceTest.hxx" #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" +#include "Basics_Utils.hxx" +#include "SALOME_LifeCycleCORBA.hxx" +#include "utilities.h" #include #include @@ -9,7 +33,6 @@ #include #include -using namespace std; // --- uncomment to have some traces on standard error // (useful only when adding new tests...) @@ -23,6 +46,10 @@ using namespace std; #define DEVTRACE(msg) #endif +#ifdef WIN32 +#define setenv Kernel_Utils::setenv +#endif + #define TRACEFILE "/tmp/traceUnitTest.log" // ============================================================================ @@ -70,6 +97,7 @@ NSTEST::echo_ptr NSTEST_aFactory_i::createInstance() NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num); _num++; NSTEST::echo_var anEchoRef = anEcho->_this(); + anEcho->_remove_ref(); return anEchoRef._retn(); } @@ -91,17 +119,17 @@ NamingServiceTest::setUp() bp1->deleteInstance(bp1); // --- trace on file - char *theFileName = TRACEFILE; + const char *theFileName = TRACEFILE; - string s = "file:"; + std::string s = "file:"; s += theFileName; //s="local"; //s="with_logger"; CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite - ofstream traceFile; + std::ofstream traceFile; // traceFile.open(theFileName, ios::out | ios::trunc); - traceFile.open(theFileName, ios::out | ios::app); + traceFile.open(theFileName, std::ios::out | std::ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); @@ -111,7 +139,7 @@ NamingServiceTest::setUp() // --- Get or initialize the orb int _argc = 1; - char* _argv[] = {""}; + char* _argv[] = {(char*)""}; ORB_INIT &init = *SINGLETON_::Instance() ; ASSERT(SINGLETON_::IsAlreadyExisting()); _orb = init(_argc , _argv ) ; @@ -130,6 +158,7 @@ NamingServiceTest::setUp() _myFactoryId = _root_poa->activate_object(_myFactory); _factoryRef = _myFactory->_this(); _pman->activate(); + _myFactory->_remove_ref(); } @@ -161,7 +190,7 @@ NamingServiceTest::testConstructorDefault() //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception); NS.init_orb(_orb); - char *root = NS.getIORaddr(); + CORBA::String_var root = NS.getIORaddr(); CORBA::Object_var obj = _orb->string_to_object(root); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); @@ -180,7 +209,7 @@ void NamingServiceTest::testConstructorOrb() { SALOME_NamingService NS(_orb); - char *root = NS.getIORaddr(); + CORBA::String_var root = NS.getIORaddr(); CORBA::Object_var obj = _orb->string_to_object(root); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); @@ -394,7 +423,7 @@ NamingServiceTest::testResolveFirst() { NSTEST::echo_var anEchoRef = myFactory->createInstance(); ref[i] = anEchoRef->getId(); - string name = "/nstestfirst/echo_"; + std::string name = "/nstestfirst/echo_"; char anum[10]; sprintf(anum,"%d",ref[i]); name += anum; @@ -403,7 +432,7 @@ NamingServiceTest::testResolveFirst() for (int i=0; igetId() == ref[i]); } - string name = "/nstestfirst/echo"; + std::string name = "/nstestfirst/echo"; obj = _NS.ResolveFirst(name.c_str()); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj); @@ -446,7 +475,7 @@ NamingServiceTest::testResolveFirstRelative() { NSTEST::echo_var anEchoRef = myFactory->createInstance(); ref[i] = anEchoRef->getId(); - string name = "/nstestfirstrel/echo_"; + std::string name = "/nstestfirstrel/echo_"; char anum[10]; sprintf(anum,"%d",ref[i]); name += anum; @@ -456,7 +485,7 @@ NamingServiceTest::testResolveFirstRelative() for (int i=0; icreateInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); obj = _NS.ResolveComponent("theHostName", - "theContainerName", - "theComponentName"); + "theContainerName", + "theComponentName"); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj); CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa)); @@ -549,12 +578,12 @@ NamingServiceTest::testResolveComponentOK() NSTEST::echo_var anEchoRef2 = myFactory->createInstance(); _NS.Register(anEchoRef2, - "/Containers/theHostName/theContainerName_2/theComponentName"); + "/Containers/theHostName/theContainerName_2/theComponentName"); obj = _NS.ResolveComponent("theHostName", - "theContainerName", - "theComponentName", - 2); + "theContainerName", + "theComponentName", + 2); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj); CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb)); @@ -577,11 +606,11 @@ NamingServiceTest::testResolveComponentEmptyHostname() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); obj = _NS.ResolveComponent("", - "theContainerName", - "theComponentName"); + "theContainerName", + "theComponentName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); } @@ -601,11 +630,11 @@ NamingServiceTest::testResolveComponentUnknownHostname() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); obj = _NS.ResolveComponent("anUnknownHostName", - "theContainerName", - "theComponentName"); + "theContainerName", + "theComponentName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); } @@ -629,24 +658,24 @@ NamingServiceTest::testResolveComponentEmptyContainerName() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); NSTEST::echo_var anEchoRef2 = myFactory->createInstance(); _NS.Register(anEchoRef2, - "/Containers/theHostName/aContainerName/aComponentName"); + "/Containers/theHostName/aContainerName/aComponentName"); NSTEST::echo_var anEchoRef3 = myFactory->createInstance(); _NS.Register(anEchoRef3, - "/Containers/theHostName/otherContainerName/theComponentName"); + "/Containers/theHostName/otherContainerName/theComponentName"); obj = _NS.ResolveComponent("anUnknownHostName", - "", - "theComponentName"); + "", + "theComponentName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); obj = _NS.ResolveComponent("theHostName", - "", - "theComponentName"); + "", + "theComponentName"); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj); CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa)); @@ -669,19 +698,19 @@ NamingServiceTest::testResolveComponentUnknownContainerName() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); NSTEST::echo_var anEchoRef2 = myFactory->createInstance(); _NS.Register(anEchoRef2, - "/Containers/theHostName/aContainerName/aComponentName"); + "/Containers/theHostName/aContainerName/aComponentName"); NSTEST::echo_var anEchoRef3 = myFactory->createInstance(); _NS.Register(anEchoRef3, - "/Containers/theHostName/otherContainerName/theComponentName"); + "/Containers/theHostName/otherContainerName/theComponentName"); obj = _NS.ResolveComponent("theHostName", - "anUnknownContainerName", - "theComponentName"); + "anUnknownContainerName", + "theComponentName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); } @@ -701,15 +730,15 @@ NamingServiceTest::testResolveComponentEmptyComponentName() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); NSTEST::echo_var anEchoRef2 = myFactory->createInstance(); _NS.Register(anEchoRef2, - "/Containers/theHostName/EmptyContainerName/"); + "/Containers/theHostName/EmptyContainerName/"); obj = _NS.ResolveComponent("theHostName", - "EmptyContainerName", - ""); + "EmptyContainerName", + ""); CPPUNIT_ASSERT(CORBA::is_nil(obj)); } @@ -729,11 +758,11 @@ NamingServiceTest::testResolveComponentUnknownComponentName() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContaine:rName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); obj = _NS.ResolveComponent("theHostName", - "theContainerName", - "anUnknownComponentName"); + "theContainerName", + "anUnknownComponentName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); } @@ -755,18 +784,18 @@ NamingServiceTest::testResolveComponentFalseNbproc() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); obj = _NS.ResolveComponent("theHostName", - "theContainerName", - "theComponentName", - 25); + "theContainerName", + "theComponentName", + 25); CPPUNIT_ASSERT(CORBA::is_nil(obj)); obj = _NS.ResolveComponent("theHostName", - "theContainerName", - "theComponentName", - -25); + "theContainerName", + "theComponentName", + -25); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); } @@ -779,8 +808,8 @@ NamingServiceTest::testResolveComponentFalseNbproc() void NamingServiceTest::testContainerName() { - string ref0 = "FactoryServer"; - string ret = _NS.ContainerName(""); + std::string ref0 = "FactoryServer"; + std::string ret = _NS.ContainerName(""); CPPUNIT_ASSERT(ret == ref0); ref0 = "MyContainerName"; @@ -797,18 +826,11 @@ NamingServiceTest::testContainerName() void NamingServiceTest::testContainerNameParams() { - Engines::MachineParameters params; - params.container_name = ""; - params.hostname = ""; - params.OS = ""; - params.mem_mb = 0; - params.cpu_clock = 0; - params.nb_proc_per_node = 0; - params.nb_node = 0; - params.isMPI = false; - - string ref0 = "FactoryServer"; - string ret = _NS.ContainerName(params); + Engines::ContainerParameters params; + SALOME_LifeCycleCORBA::preSet(params); + + std::string ref0 = "FactoryServer"; + std::string ret = _NS.ContainerName(params); CPPUNIT_ASSERT(ret == ref0); ref0 = "MyContainerName"; @@ -826,8 +848,8 @@ NamingServiceTest::testContainerNameParams() void NamingServiceTest::testBuildContainerNameForNS() { - string ref0 = "/Containers/theHostName/theContainerName"; - string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName"); + std::string ref0 = "/Containers/theHostName/theContainerName"; + std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName"); CPPUNIT_ASSERT(ret == ref0); ref0 = "/Containers/theHostName/FactoryServer"; @@ -844,19 +866,12 @@ NamingServiceTest::testBuildContainerNameForNS() void NamingServiceTest::testBuildContainerNameForNSParams() { - Engines::MachineParameters params; - params.container_name = ""; - params.hostname = ""; - params.OS = ""; - params.mem_mb = 0; - params.cpu_clock = 0; - params.nb_proc_per_node = 0; - params.nb_node = 0; - params.isMPI = false; + Engines::ContainerParameters params; + SALOME_LifeCycleCORBA::preSet(params); params.container_name = "theContainerName"; - string ref0 = "/Containers/theHostName/theContainerName"; - string ret = _NS.BuildContainerNameForNS(params,"theHostName"); + std::string ref0 = "/Containers/theHostName/theContainerName"; + std::string ret = _NS.BuildContainerNameForNS(params,"theHostName"); CPPUNIT_ASSERT(ret == ref0); params.container_name = ""; @@ -881,19 +896,19 @@ NamingServiceTest::testFind() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); NSTEST::echo_var anEchoRef2 = myFactory->createInstance(); _NS.Register(anEchoRef2, - "/Containers/theHostName/aContainerName/aComponentName"); + "/Containers/theHostName/aContainerName/aComponentName"); NSTEST::echo_var anEchoRef3 = myFactory->createInstance(); _NS.Register(anEchoRef3, - "/Containers/theHostName/otherContainerName/theComponentName"); + "/Containers/theHostName/otherContainerName/theComponentName"); NSTEST::echo_var anEchoRef4 = myFactory->createInstance(); _NS.Register(anEchoRef4, - "/Containers/anHostName/oneContainerName/theComponentName"); + "/Containers/anHostName/oneContainerName/theComponentName"); _NS.Change_Directory("/Containers"); int occ= _NS.Find("theComponentName"); @@ -928,13 +943,13 @@ NamingServiceTest::testCreateDirectory() _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee"); NSTEST::echo_var anEchoRef = myFactory->createInstance(); int val = anEchoRef->getId(); - string name = "echo_"; + std::string name = "echo_"; char anum[10]; sprintf(anum,"%d",val); name += anum; _NS.Register(anEchoRef,name.c_str()); - string dirname = "/aaa/bbb/ccc/ddd/eee/"; + std::string dirname = "/aaa/bbb/ccc/ddd/eee/"; dirname += name; obj = _NS.Resolve(dirname.c_str()); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); @@ -971,19 +986,19 @@ NamingServiceTest::testChangeDirectory() NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, - "/Containers/theHostName/theContainerName/theComponentName"); + "/Containers/theHostName/theContainerName/theComponentName"); NSTEST::echo_var anEchoRef2 = myFactory->createInstance(); _NS.Register(anEchoRef2, - "/Containers/theHostName/aContainerName/aComponentName"); + "/Containers/theHostName/aContainerName/aComponentName"); NSTEST::echo_var anEchoRef3 = myFactory->createInstance(); _NS.Register(anEchoRef3, - "/Containers/theHostName/otherContainerName/theComponentName"); + "/Containers/theHostName/otherContainerName/theComponentName"); NSTEST::echo_var anEchoRef4 = myFactory->createInstance(); _NS.Register(anEchoRef4, - "/Containers/anHostName/oneContainerName/theComponentName"); + "/Containers/anHostName/oneContainerName/theComponentName"); _NS.Change_Directory("/Containers/theHostName/otherContainerName"); obj = _NS.Resolve("theComponentName"); @@ -1003,12 +1018,14 @@ NamingServiceTest::testChangeDirectory() void NamingServiceTest::testCurrentDirectory() { - string path = "/aaa/bbb/ccc/ddd/eee"; + std::string path = "/aaa/bbb/ccc/ddd/eee"; bool ret = _NS.Create_Directory(path.c_str()); CPPUNIT_ASSERT(ret); _NS.Change_Directory(path.c_str()); - string curdir = _NS.Current_Directory(); + char* acurdir = _NS.Current_Directory(); + std::string curdir = acurdir; + free(acurdir); CPPUNIT_ASSERT(curdir == path); } @@ -1090,7 +1107,7 @@ NamingServiceTest::testDestroyName() NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj); CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); - string path = "/Containers/theHostName/theContainerName/theComponentName"; + std::string path = "/Containers/theHostName/theContainerName/theComponentName"; NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, path.c_str()); @@ -1117,7 +1134,7 @@ NamingServiceTest::testDestroyDirectory() NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj); CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); - string path = "/Containers/theHostName/theContainerName/theComponentName"; + std::string path = "/Containers/theHostName/theContainerName/theComponentName"; NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef, path.c_str()); @@ -1134,16 +1151,44 @@ NamingServiceTest::testDestroyDirectory() // ============================================================================ /*! - * Test + * DestroyFullDirectory is not recursive + * Need Housekeeping of /Containers for further tests ! */ // ============================================================================ +void NamingServiceTest::_destroyDirectoryRecurs(std::string path) +{ + std::string current = path; + SCRUTE(path); + if (_NS.Change_Directory(path.c_str())) + { + std::vector subdirs = _NS.list_subdirs(); + for (int i=0; i subdirs = _NS.list_subdirs(); + CPPUNIT_ASSERT(subdirs.size() >0); + _NS.list_directory_recurs(); + std::string path = "/Containers"; + _destroyDirectoryRecurs(path); + CPPUNIT_ASSERT( ! _NS.Change_Directory("/Containers")); _NS.Change_Directory("/"); _NS.list_subdirs(); + _NS.list_directory_recurs(); } // ============================================================================ @@ -1155,7 +1200,7 @@ NamingServiceTest::testDestroyFullDirectory() void NamingServiceTest::testGetIorAddr() { - char *root = _NS.getIORaddr(); + CORBA::String_var root = _NS.getIORaddr(); CORBA::Object_var obj = _orb->string_to_object(root); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); }