From: prascle Date: Tue, 8 Nov 2005 18:16:59 +0000 (+0000) Subject: PR: Naming service Unit tests, complements... X-Git-Tag: BR_UT_V310a2_20051115~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8e7852be5a40b0ee91e934abb96e57c48da1934f;p=modules%2Fkernel.git PR: Naming service Unit tests, complements... --- diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 9a9511ef7..2acc7c85f 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -109,7 +109,7 @@ void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb) * \param ObjRef CORBA object reference to associate to the path. * \param Path A relative or absolute pathname to store the object reference. * If the pathname begins with a '/', pathname is taken - * as an absolute oathname. Else, pathname is taken as a relative + * as an absolute pathname. Else, pathname is taken as a relative * path, to current context. Prefer absolute pathname, relative * pathname are not safe, when SALOME_NamingService object is * shared or use in multithreaded context. @@ -334,12 +334,12 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef, } // ============================================================================ -/*! \brief get the CORBA object reference associated to a name +/*! \brief get the CORBA object reference associated to a name. * * get the CORBA object reference associated to a complete name with a path. * If the NamingService is out, the exception ServiceUnreachable is thrown * \param Path pathname. If the pathname begins with a '/', pathname is taken - * as an absolute oathname. Else, pathname is taken as a relative + * as an absolute pathname. Else, pathname is taken as a relative * path, to current context. Prefer absolute pathname, relative * pathname are not safe, when SALOME_NamingService object is * shared or use in multithreaded context. @@ -447,7 +447,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path) } // ============================================================================ -/*! \brief get the CORBA object reference associated to an uncomplete name +/*! \brief get the CORBA object reference associated to an uncomplete name. * * get the CORBA object reference associated to an uncomplete name with a * path. Look for the first occurence of name*. @@ -508,7 +508,7 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path) // ============================================================================ /*! \brief find a component instance from hostname, containername, - * componentName and number of processors + * componentName and number of processors. * * find a component instance from hostname, containername, componentName and * number of processors. @@ -582,7 +582,7 @@ SALOME_NamingService::ResolveComponent(const char* hostname, } // ============================================================================ -/*! \brief provide a default container name if empty +/*! \brief provide a default container name if empty. * * the given container name is returned unchanged, unless it is empty. * \param containerName diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx index dd5dbdf76..583cec105 100644 --- a/src/NamingService/Test/NamingServiceTest.cxx +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -27,7 +27,7 @@ using namespace std; // ============================================================================ /*! - * + * a basic CORBA object implementation for use with namingService tests */ // ============================================================================ @@ -50,6 +50,12 @@ CORBA::Long NSTEST_echo_i::getId() return _num; } +// ============================================================================ +/*! + * a factory of CORBA objects for use with namingService tests + */ +// ============================================================================ + NSTEST_aFactory_i::NSTEST_aFactory_i() { _num=0; @@ -197,6 +203,32 @@ NamingServiceTest::testRegisterResolveAbsNoPath() CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); } +// ============================================================================ +/*! + * Test Register and resolve of a single CORBA object with relative pathname, + * without subdirectories + */ +// ============================================================================ + +void +NamingServiceTest::testRegisterResolveRelativeNoPath() +{ + CORBA::Object_var obj = _NS.Resolve("/nstest_factory"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj)); + NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj); + CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); + _NS.Create_Directory("/myContext"); + _NS.Change_Directory("/myContext"); + NSTEST::echo_var anEchoRef = myFactory->createInstance(); + _NS.Register(anEchoRef,"echo_0"); + CORBA::Object_var obj2 = _NS.Resolve("echo_0"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj2)); + NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj2); + CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2)); + CORBA::Object_var obj3 = _NS.Resolve("/myContext/echo_0"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj3)); +} + // ============================================================================ /*! * Test Register and resolve of a single CORBA object with absolute pathname, @@ -213,10 +245,38 @@ NamingServiceTest::testRegisterResolveAbsWithPath() CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); NSTEST::echo_var anEchoRef = myFactory->createInstance(); _NS.Register(anEchoRef,"/nstest/echo_0"); - obj = _NS.Resolve("/nstest/echo_0"); + CORBA::Object_var obj2 = _NS.Resolve("/nstest/echo_0"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj2)); + NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj2); + CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2)); +} + +// ============================================================================ +/*! + * Test Register and resolve of a single CORBA object with relative pathname, + * in a subdirectory. + * Relative Path is changed to the created subdirectory when Register() + */ +// ============================================================================ + +void +NamingServiceTest::testRegisterResolveRelativeWithPath() +{ + CORBA::Object_var obj = _NS.Resolve("/nstest_factory"); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); - NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj); + NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj); + CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); + _NS.Create_Directory("/myContext"); + _NS.Change_Directory("/myContext"); + NSTEST::echo_var anEchoRef = myFactory->createInstance(); + _NS.Register(anEchoRef,"subdir/echo_0"); + //CORBA::Object_var obj2 = _NS.Resolve("subdir/echo_0"); + CORBA::Object_var obj2 = _NS.Resolve("echo_0"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj2)); + NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj2); CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2)); + CORBA::Object_var obj3 = _NS.Resolve("/myContext/subdir/echo_0"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj3)); } // ============================================================================ @@ -230,12 +290,33 @@ NamingServiceTest::testResolveBadName() { CORBA::Object_var obj = _NS.Resolve("/notRegisteredName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); - obj = _NS.Resolve("/nstest/notRegisteredName"); - CPPUNIT_ASSERT(CORBA::is_nil(obj)); - obj = _NS.Resolve("/unknownPath/notRegisteredName"); - CPPUNIT_ASSERT(CORBA::is_nil(obj)); - obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName"); + CORBA::Object_var obj2 = _NS.Resolve("/nstest/notRegisteredName"); + CPPUNIT_ASSERT(CORBA::is_nil(obj2)); + CORBA::Object_var obj3 = _NS.Resolve("/unknownPath/notRegisteredName"); + CPPUNIT_ASSERT(CORBA::is_nil(obj3)); + CORBA::Object_var obj4 = + _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName"); + CPPUNIT_ASSERT(CORBA::is_nil(obj4)); +} + +// ============================================================================ +/*! + * Test resolve with a name not known, with a relative path + */ +// ============================================================================ + +void +NamingServiceTest::testResolveBadNameRelative() +{ + _NS.Create_Directory("/myContext"); + _NS.Change_Directory("/myContext"); + CORBA::Object_var obj = _NS.Resolve("notRegisteredName"); CPPUNIT_ASSERT(CORBA::is_nil(obj)); + CORBA::Object_var obj2 = _NS.Resolve("unknownPath/notRegisteredName"); + CPPUNIT_ASSERT(CORBA::is_nil(obj2)); + CORBA::Object_var obj3 = + _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName"); + CPPUNIT_ASSERT(CORBA::is_nil(obj3)); } // ============================================================================ @@ -270,16 +351,391 @@ NamingServiceTest::testResolveFirst() char anum[10]; sprintf(anum,"%d",ref[i]); name += anum; - CORBA::Object_var obj = _NS.Resolve(name.c_str()); - CPPUNIT_ASSERT(!CORBA::is_nil(obj)); - NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj); + CORBA::Object_var obj2 = _NS.Resolve(name.c_str()); + CPPUNIT_ASSERT(!CORBA::is_nil(obj2)); + NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj2); CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef)); CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]); } string name = "/nstestfirst/echo"; - obj = _NS.ResolveFirst(name.c_str()); - CPPUNIT_ASSERT(!CORBA::is_nil(obj)); - NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj); - CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef)); - CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]); + CORBA::Object_var obj3 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(!CORBA::is_nil(obj3)); + NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj3); + CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2)); + CPPUNIT_ASSERT(anEchoRef2->getId() == ref[0]); } + +// ============================================================================ +/*! + * Test register and resolve multiple objects, test resolveFirst, relative path + * Result not guaranteed + */ +// ============================================================================ + +void +NamingServiceTest::testResolveFirstRelative() +{ + CORBA::Object_var obj = _NS.Resolve("/nstest_factory"); + CPPUNIT_ASSERT(!CORBA::is_nil(obj)); + NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj); + CPPUNIT_ASSERT(!CORBA::is_nil(myFactory)); + int ref[NB_OBJS]; + for (int i=0; icreateInstance(); + ref[i] = anEchoRef->getId(); + string name = "/nstestfirstrel/echo_"; + char anum[10]; + sprintf(anum,"%d",ref[i]); + name += anum; + _NS.Register(anEchoRef,name.c_str()); + } + for (int i=0; igetId() == ref[i]); + } + _NS.Change_Directory("/nstestfirstrel"); + string name = "echo"; + CORBA::Object_var obj3 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj3)); +} + +// ============================================================================ +/*! + * Test resolveFirst with unknown name + */ +// ============================================================================ + +void +NamingServiceTest::testResolveFirstUnknown() +{ + string name = "/notYeyRegistered"; + CORBA::Object_var obj2 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj2)); + name = "/nstestfirst/notYeyRegistered"; + CORBA::Object_var obj3 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj3)); + name = "/rrr/sss/ttt/notYeyRegistered"; + CORBA::Object_var obj4 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj4)); +} + +// ============================================================================ +/*! + * Test resolveFirst with unknown name, relative Path + */ +// ============================================================================ + +void +NamingServiceTest::testResolveFirstUnknownRelative() +{ + _NS.Create_Directory("/myContext"); + _NS.Change_Directory("/myContext"); + string name = "RelnotYeyRegistered"; + CORBA::Object_var obj2 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj2)); + name = "Relnstestfirst/notYeyRegistered"; + CORBA::Object_var obj3 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj3)); + name = "Relrrr/sss/ttt/notYeyRegistered"; + CORBA::Object_var obj4 = _NS.ResolveFirst(name.c_str()); + CPPUNIT_ASSERT(CORBA::is_nil(obj4)); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentOK() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentEmptyHostname() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentUnknownHostname() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentEmptyContainerName() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentUnknownContainerName() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentEmptyComponentName() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentUnknownComponentName() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testResolveComponentFalseNbproc() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testContainerName() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testContainerNameParams() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testBuildContainerNameForNS() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testBuildContainerNameForNSParams() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testFind() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testCreateDirectory() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testChangeDirectory() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testCurrentDirectory() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testList() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testListDirectory() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testListDirectoryRecurs() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testDestroyName() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testDestroyDirectory() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testDestroyFullDirectory() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +void +NamingServiceTest::testGetIorAddr() +{ + CPPUNIT_ASSERT(0); +} + +// ============================================================================ +/*! + * Test + */ +// ============================================================================ + +// void +// NamingServiceTest::() +// { +// CPPUNIT_ASSERT(0); +// } + diff --git a/src/NamingService/Test/NamingServiceTest.hxx b/src/NamingService/Test/NamingServiceTest.hxx index e44ed8ea5..cd07f1332 100644 --- a/src/NamingService/Test/NamingServiceTest.hxx +++ b/src/NamingService/Test/NamingServiceTest.hxx @@ -37,9 +37,42 @@ class NamingServiceTest : public CppUnit::TestFixture CPPUNIT_TEST( testConstructorDefault ); CPPUNIT_TEST( testConstructorOrb ); CPPUNIT_TEST( testRegisterResolveAbsNoPath ); + CPPUNIT_TEST( testRegisterResolveRelativeNoPath ); CPPUNIT_TEST( testRegisterResolveAbsWithPath ); + CPPUNIT_TEST( testRegisterResolveRelativeWithPath ); CPPUNIT_TEST( testResolveBadName ); + CPPUNIT_TEST( testResolveBadNameRelative ); CPPUNIT_TEST( testResolveFirst ); + CPPUNIT_TEST( testResolveFirstRelative ); + CPPUNIT_TEST( testResolveFirstUnknown ); + CPPUNIT_TEST( testResolveFirstUnknownRelative ); + CPPUNIT_TEST( testResolveComponentOK ); + CPPUNIT_TEST( testResolveComponentEmptyHostname ); + CPPUNIT_TEST( testResolveComponentUnknownHostname ); + CPPUNIT_TEST( testResolveComponentEmptyContainerName ); + CPPUNIT_TEST( testResolveComponentUnknownContainerName ); + CPPUNIT_TEST( testResolveComponentEmptyComponentName ); + CPPUNIT_TEST( testResolveComponentUnknownComponentName ); + CPPUNIT_TEST( testResolveComponentFalseNbproc ); + CPPUNIT_TEST( testContainerName ); + CPPUNIT_TEST( testContainerNameParams ); + CPPUNIT_TEST( testBuildContainerNameForNS ); + CPPUNIT_TEST( testBuildContainerNameForNSParams ); + CPPUNIT_TEST( testFind ); + CPPUNIT_TEST( testCreateDirectory ); + CPPUNIT_TEST( testChangeDirectory ); + CPPUNIT_TEST( testCurrentDirectory ); + CPPUNIT_TEST( testList ); + CPPUNIT_TEST( testListDirectory ); + CPPUNIT_TEST( testListDirectoryRecurs ); + CPPUNIT_TEST( testDestroyName ); + CPPUNIT_TEST( testDestroyDirectory ); + CPPUNIT_TEST( testDestroyFullDirectory ); + CPPUNIT_TEST( testGetIorAddr ); +// CPPUNIT_TEST( ); +// CPPUNIT_TEST( ); +// CPPUNIT_TEST( ); + CPPUNIT_TEST_SUITE_END(); public: @@ -50,9 +83,38 @@ public: void testConstructorDefault(); void testConstructorOrb(); void testRegisterResolveAbsNoPath(); + void testRegisterResolveRelativeNoPath(); void testRegisterResolveAbsWithPath(); + void testRegisterResolveRelativeWithPath(); void testResolveBadName(); + void testResolveBadNameRelative(); void testResolveFirst(); + void testResolveFirstRelative(); + void testResolveFirstUnknown(); + void testResolveFirstUnknownRelative(); + void testResolveComponentOK(); + void testResolveComponentEmptyHostname(); + void testResolveComponentUnknownHostname(); + void testResolveComponentEmptyContainerName(); + void testResolveComponentUnknownContainerName(); + void testResolveComponentEmptyComponentName(); + void testResolveComponentUnknownComponentName(); + void testResolveComponentFalseNbproc(); + void testContainerName(); + void testContainerNameParams(); + void testBuildContainerNameForNS(); + void testBuildContainerNameForNSParams(); + void testFind(); + void testCreateDirectory(); + void testChangeDirectory(); + void testCurrentDirectory(); + void testList(); + void testListDirectory(); + void testListDirectoryRecurs(); + void testDestroyName(); + void testDestroyDirectory(); + void testDestroyFullDirectory(); + void testGetIorAddr(); protected: CORBA::ORB_var _orb;