Back to index

salome-kernel  6.5.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
NamingServiceTest Class Reference

#include <NamingServiceTest.hxx>

Collaboration diagram for NamingServiceTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void setUp ()
 Set Trace mecanism.
void tearDown ()
void testConstructorDefault ()
 Test default constructor: must be followed by a call to init_orb(ORB)
void testConstructorOrb ()
 Test constructor with ORB parameter.
void testRegisterResolveAbsNoPath ()
 Test Register and resolve of a single CORBA object with absolute pathname, without subdirectories.
void testRegisterResolveRelativeNoPath ()
 Test Register and resolve of a single CORBA object with relative pathname, without subdirectories.
void testRegisterResolveAbsWithPath ()
 Test Register and resolve of a single CORBA object with absolute pathname, in a subdirectory.
void testRegisterResolveRelativeWithPath ()
 Test Register and resolve of a single CORBA object with relative pathname, in a subdirectory.
void testResolveBadName ()
 Test resolve with a name not known.
void testResolveBadNameRelative ()
 Test resolve with a name not known, with a relative path.
void testResolveFirst ()
void testResolveFirstRelative ()
 Test register and resolve multiple objects, test resolveFirst, relative path Register a few objects in /nstestfirstrel/echo_n where n is the object id.
void testResolveFirstUnknown ()
 Test resolveFirst with unknown name.
void testResolveFirstUnknownRelative ()
 Test resolveFirst with unknown name, relative Path.
void testResolveComponentOK ()
 Test ResolveComponent works as specified.
void testResolveComponentEmptyHostname ()
 Test ResolveComponent gives nil pointer if hostname is not given (empty)
void testResolveComponentUnknownHostname ()
 Test ResolveComponent gives nil pointer if hostname is unknown.
void testResolveComponentEmptyContainerName ()
 Test ResolveComponent when containerName is empty.
void testResolveComponentUnknownContainerName ()
 Test.
void testResolveComponentEmptyComponentName ()
 Test.
void testResolveComponentUnknownComponentName ()
 Test.
void testResolveComponentFalseNbproc ()
 Test with a false number nbproc.
void testContainerName ()
 Test.
void testContainerNameParams ()
 Test.
void testBuildContainerNameForNS ()
 Test.
void testBuildContainerNameForNSParams ()
 Test.
void testFind ()
 Test.
void testCreateDirectory ()
 Test.
void testChangeDirectory ()
 Test.
void testCurrentDirectory ()
 Test.
void testList ()
 Test.
void testListDirectory ()
 Test.
void testListDirectoryRecurs ()
 Test.
void testListSubdirs ()
 Test.
void testDestroyName ()
 Test.
void testDestroyDirectory ()
 Test.
void testDestroyFullDirectory ()
void testGetIorAddr ()
 Test.

Protected Member Functions

void _destroyDirectoryRecurs (std::string path)
 DestroyFullDirectory is not recursive Need Housekeeping of /Containers for further tests !

Protected Attributes

CORBA::ORB_var _orb
SALOME_NamingService _NS
PortableServer::POA_var _root_poa
PortableServer::POAManager_var _pman
PortableServer::ObjectId_var _myFactoryId
NSTEST_aFactory_i_myFactory
CORBA::Object_var _factoryRef

Private Member Functions

 CPPUNIT_TEST_SUITE (NamingServiceTest)
 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 (testListSubdirs)
 CPPUNIT_TEST (testDestroyName)
 CPPUNIT_TEST (testDestroyDirectory)
 CPPUNIT_TEST (testDestroyFullDirectory)
 CPPUNIT_TEST (testGetIorAddr)
 CPPUNIT_TEST_SUITE_END ()

Detailed Description

Definition at line 55 of file NamingServiceTest.hxx.


Member Function Documentation

void NamingServiceTest::_destroyDirectoryRecurs ( std::string  path) [protected]

DestroyFullDirectory is not recursive Need Housekeeping of /Containers for further tests !

Definition at line 1166 of file NamingServiceTest.cxx.

{
  std::string current = path;
  SCRUTE(path);
  if (_NS.Change_Directory(path.c_str()))
    {
      std::vector<std::string> subdirs = _NS.list_subdirs();
      for (int i=0; i<subdirs.size(); i++)
        {
          std::string subpath=path + "/" +subdirs[i];
          _destroyDirectoryRecurs(subpath);
        }
      if (_NS.Change_Directory(path.c_str()))
        {
          _NS.Destroy_FullDirectory(path.c_str());
        }
    }
}

Here is the caller graph for this function:

Set Trace mecanism.

  • delete preexisting trace classes if any
  • set trace on file Get or initialize the orb Create a SALOME_NamingService instance

Definition at line 108 of file NamingServiceTest.cxx.

{
  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1);
  bp1->deleteInstance(bp1);

  // --- trace on file
  const char *theFileName = TRACEFILE;

  std::string s = "file:";
  s += theFileName;
  //s="local";
  //s="with_logger";
  CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite

  std::ofstream traceFile;
  //  traceFile.open(theFileName, ios::out | ios::trunc);
  traceFile.open(theFileName, std::ios::out | std::ios::app);
  CPPUNIT_ASSERT(traceFile); // file created empty, then closed
  traceFile.close();

  bp1 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1);

  // --- Get or initialize the orb

  int _argc = 1;
  char* _argv[] = {(char*)""};
  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
  _orb = init(_argc , _argv ) ;

  // --- Create a SALOME_NamingService instance

  _NS.init_orb(_orb) ;

  // --- Create an NSTEST::factory

  CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
  ASSERT(!CORBA::is_nil(obj));
  _root_poa = PortableServer::POA::_narrow(obj);
  _pman = _root_poa->the_POAManager();
  _myFactory  = new NSTEST_aFactory_i();
  _myFactoryId = _root_poa->activate_object(_myFactory);
  _factoryRef = _myFactory->_this();
  _pman->activate();
  _myFactory->_remove_ref();
  
}
  • delete trace classes

Definition at line 165 of file NamingServiceTest.cxx.

{

  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1);
  bp1->deleteInstance(bp1);
}

Test.

Definition at line 849 of file NamingServiceTest.cxx.

{
  std::string ref0 = "/Containers/theHostName/theContainerName";
  std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
  CPPUNIT_ASSERT(ret == ref0);

  ref0 = "/Containers/theHostName/FactoryServer";
  ret = _NS.BuildContainerNameForNS("","theHostName");
  CPPUNIT_ASSERT(ret == ref0);
}

Test.

Definition at line 867 of file NamingServiceTest.cxx.

{
  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;

  params.container_name = "theContainerName";
  std::string ref0 = "/Containers/theHostName/theContainerName";
  std::string ret = _NS.BuildContainerNameForNS(params,"theHostName");
  CPPUNIT_ASSERT(ret == ref0);

  params.container_name = "";
  ref0 = "/Containers/theHostName/FactoryServer";
  ret = _NS.BuildContainerNameForNS(params,"theHostName");
  CPPUNIT_ASSERT(ret == ref0);
}

Test.

Definition at line 987 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,
               "/Containers/theHostName/aContainerName/aComponentName");

  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
  _NS.Register(anEchoRef3,
               "/Containers/theHostName/otherContainerName/theComponentName");

  NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
  _NS.Register(anEchoRef4,
               "/Containers/anHostName/oneContainerName/theComponentName");
  
  _NS.Change_Directory("/Containers/theHostName/otherContainerName");
  obj = _NS.Resolve("theComponentName");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  
  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
  CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId());
}

Test default constructor: must be followed by a call to init_orb(ORB)

Definition at line 180 of file NamingServiceTest.cxx.

{
  SALOME_NamingService  NS;
  //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
  NS.init_orb(_orb);

  CORBA::String_var root = NS.getIORaddr();
  CORBA::Object_var obj = _orb->string_to_object(root);
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));

  CosNaming::NamingContext_var rootContext =
    CosNaming::NamingContext::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
}

Test constructor with ORB parameter.

Definition at line 202 of file NamingServiceTest.cxx.

{
  SALOME_NamingService  NS(_orb);
  CORBA::String_var root = NS.getIORaddr();
  CORBA::Object_var obj = _orb->string_to_object(root);
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));

  CosNaming::NamingContext_var rootContext =
    CosNaming::NamingContext::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
}

Test.

Definition at line 802 of file NamingServiceTest.cxx.

{
  std::string ref0 = "FactoryServer";
  std::string ret = _NS.ContainerName("");
  CPPUNIT_ASSERT(ret == ref0);

  ref0 = "MyContainerName";
  ret = _NS.ContainerName(ref0.c_str());
  CPPUNIT_ASSERT(ret == ref0);
}

Test.

Definition at line 820 of file NamingServiceTest.cxx.

{
  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;

  std::string ref0 = "FactoryServer";
  std::string ret = _NS.ContainerName(params);
  CPPUNIT_ASSERT(ret == ref0);

  ref0 = "MyContainerName";
  params.container_name = ref0.c_str();
  ret = _NS.ContainerName(params);
  CPPUNIT_ASSERT(ret == ref0);
}

Test.

Definition at line 940 of file NamingServiceTest.cxx.

{
  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));

  bool ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
  CPPUNIT_ASSERT(ret);

  _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  int val = anEchoRef->getId();
  std::string name = "echo_";
  char anum[10];
  sprintf(anum,"%d",val);
  name += anum;
  _NS.Register(anEchoRef,name.c_str());

  std::string dirname = "/aaa/bbb/ccc/ddd/eee/";
  dirname += name;
  obj = _NS.Resolve(dirname.c_str());
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());

  ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
  CPPUNIT_ASSERT(ret);

  _NS.Change_Directory("/aaa/bbb");
  ret = _NS.Create_Directory("cccccc/dddddd/eeeeee");
  _NS.Register(anEchoRef,"echo_abcde");

  CPPUNIT_ASSERT(ret);
  _NS.Change_Directory("/aaa/bbb/cccccc/dddddd/eeeeee");
  obj = _NS.Resolve("echo_abcde");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
}

Test.

Definition at line 1026 of file NamingServiceTest.cxx.

{
  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());
  char* acurdir = _NS.Current_Directory();
  std::string curdir = acurdir;
  free(acurdir);
  CPPUNIT_ASSERT(curdir == path);
}

Test.

Definition at line 1137 of file NamingServiceTest.cxx.

{
  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));

  std::string path = "/Containers/theHostName/theContainerName/theComponentName";

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef, path.c_str());

  _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
  obj=_NS.Resolve(path.c_str());
  CPPUNIT_ASSERT(!CORBA::is_nil(obj)); // directory not empty: not destroyed

  _NS.Destroy_Name(path.c_str());
  _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
  _NS.Change_Directory("/Containers/theHostName");
  _NS.list_subdirs();
}

Definition at line 1186 of file NamingServiceTest.cxx.

{
  _NS.Destroy_FullDirectory("/Containers");
  CPPUNIT_ASSERT(_NS.Change_Directory("/Containers"));
  std::vector<std::string> 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();
}

Here is the call graph for this function:

Test.

Definition at line 1110 of file NamingServiceTest.cxx.

{
  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));

  std::string path = "/Containers/theHostName/theContainerName/theComponentName";

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef, path.c_str());

  obj=_NS.Resolve(path.c_str());
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));

  _NS.Destroy_Name(path.c_str());
  obj=_NS.Resolve(path.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test.

Definition at line 897 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,
               "/Containers/theHostName/aContainerName/aComponentName");

  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
  _NS.Register(anEchoRef3,
               "/Containers/theHostName/otherContainerName/theComponentName");

  NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
  _NS.Register(anEchoRef4,
               "/Containers/anHostName/oneContainerName/theComponentName");

  _NS.Change_Directory("/Containers");
  int occ= _NS.Find("theComponentName");
  CPPUNIT_ASSERT(occ >= 3); // see previous tests

  _NS.Change_Directory("/Containers");
  occ= _NS.Find("aComponentName");
  CPPUNIT_ASSERT(occ == 1);

  _NS.Change_Directory("/Containers");
  occ= _NS.Find("UnknownCompnentName");
  CPPUNIT_ASSERT(occ == 0);
}

Test.

Definition at line 1208 of file NamingServiceTest.cxx.

{
  CORBA::String_var root = _NS.getIORaddr();
  CORBA::Object_var obj = _orb->string_to_object(root);
  CPPUNIT_ASSERT(!CORBA::is_nil(obj)); 
}

Test.

Definition at line 1046 of file NamingServiceTest.cxx.

{
  _NS.Change_Directory("/Containers/theHostName/theContainerName");
  _NS.list();
  _NS.Change_Directory("/Containers");
  _NS.list();
}

Test.

Definition at line 1061 of file NamingServiceTest.cxx.

{
  _NS.Change_Directory("/Containers/theHostName/theContainerName");
  _NS.list_directory();
  _NS.Change_Directory("/Containers");
  _NS.list_directory();
}

Test.

Definition at line 1076 of file NamingServiceTest.cxx.

{
  _NS.Change_Directory("/Containers/theHostName/theContainerName");
  _NS.list_directory_recurs();
  _NS.Change_Directory("/Containers");
  _NS.list_directory_recurs();
  _NS.Change_Directory("/");
  _NS.list_directory_recurs();
}

Test.

Definition at line 1094 of file NamingServiceTest.cxx.

{
  _NS.Change_Directory("/Containers/theHostName/theContainerName");
  _NS.list_subdirs();
  _NS.Change_Directory("/Containers");
  _NS.list_subdirs();
  _NS.Change_Directory("/");
  _NS.list_subdirs();
}

Test Register and resolve of a single CORBA object with absolute pathname, without subdirectories.

Definition at line 222 of file NamingServiceTest.cxx.

{
  _NS.Register(_factoryRef,"/nstest_factory");
  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));
}

Test Register and resolve of a single CORBA object with absolute pathname, in a subdirectory.

Definition at line 273 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,"/nstest/echo_0");

  obj = _NS.Resolve("/nstest/echo_0");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRefa->getId());

  NSTEST::echo_var anEchoRef1 = myFactory->createInstance();
  _NS.Register(anEchoRef1,"/nstest2/rep2/rep3/echo_1");
  CPPUNIT_ASSERT(anEchoRef->getId() != anEchoRef1->getId());

  obj = _NS.Resolve("/nstest2/rep2/rep3/echo_1");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef1a = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef1a));
  CPPUNIT_ASSERT(anEchoRef1->getId() == anEchoRef1a->getId());

  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,"/nstest2/1/2/3/4/echo_1");

  obj = _NS.Resolve("/nstest2/1/2/3/4/echo_1");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef2a = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2a));
  CPPUNIT_ASSERT(anEchoRef2->getId() == anEchoRef2a->getId());
}

Test Register and resolve of a single CORBA object with relative pathname, without subdirectories.

Definition at line 239 of file NamingServiceTest.cxx.

{
  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");

  obj = _NS.Resolve("echo_0");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());

  obj = _NS.Resolve("/myContext/echo_0");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
}

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()

Definition at line 318 of file NamingServiceTest.cxx.

{
  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,"subdir/echo_0");

  obj = _NS.Resolve("echo_0");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));

  obj = _NS.Resolve("/myContext/subdir/echo_0");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());

  _NS.Change_Directory("/myContext");
  obj = _NS.Resolve("subdir/echo_0");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRef4 = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef4));
  CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef4->getId());
}

Test resolve with a name not known.

Definition at line 356 of file NamingServiceTest.cxx.

{
  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");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test resolve with a name not known, with a relative path.

Definition at line 378 of file NamingServiceTest.cxx.

{
  _NS.Create_Directory("/myContext");
  _NS.Change_Directory("/myContext");

  CORBA::Object_var obj = _NS.Resolve("notRegisteredName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  obj = _NS.Resolve("unknownPath/notRegisteredName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  obj = _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test.

Definition at line 717 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,
               "/Containers/theHostName/EmptyContainerName/");

  obj = _NS.ResolveComponent("theHostName",
                             "EmptyContainerName",
                             "");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test ResolveComponent when containerName is empty.

check bad hostname gives nil pointer. If componentName registered on a container from hostname, a component reference is found (the first one). Else give nil pointer.

Definition at line 645 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,
               "/Containers/theHostName/aContainerName/aComponentName");

  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
  _NS.Register(anEchoRef3,
               "/Containers/theHostName/otherContainerName/theComponentName");

  obj = _NS.ResolveComponent("anUnknownHostName",
                             "",
                             "theComponentName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  obj = _NS.ResolveComponent("theHostName",
                             "",
                             "theComponentName");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
  CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
}

Test ResolveComponent gives nil pointer if hostname is not given (empty)

Definition at line 593 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  obj = _NS.ResolveComponent("",
                             "theContainerName",
                             "theComponentName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test with a false number nbproc.

A positive number not corresponding to a registered component gives nil ref. A negative number is not taken into account and may give a non nil ref.

Definition at line 771 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  obj = _NS.ResolveComponent("theHostName",
                             "theContainerName",
                             "theComponentName",
                             25);
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  obj = _NS.ResolveComponent("theHostName",
                             "theContainerName",
                             "theComponentName",
                             -25);
  CPPUNIT_ASSERT(! CORBA::is_nil(obj));
}

Test ResolveComponent works as specified.

Definition at line 552 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  obj = _NS.ResolveComponent("theHostName",
                             "theContainerName",
                             "theComponentName");
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
  CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());


  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,
               "/Containers/theHostName/theContainerName_2/theComponentName");

  obj = _NS.ResolveComponent("theHostName",
                             "theContainerName",
                             "theComponentName",
                             2);
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
  NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
  CPPUNIT_ASSERT(anEchoRefb->getId() == anEchoRef2->getId());
}

Test.

Definition at line 745 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  obj = _NS.ResolveComponent("theHostName",
                             "theContainerName",
                             "anUnknownComponentName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test.

Definition at line 685 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
  _NS.Register(anEchoRef2,
               "/Containers/theHostName/aContainerName/aComponentName");

  NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
  _NS.Register(anEchoRef3,
               "/Containers/theHostName/otherContainerName/theComponentName");

  obj = _NS.ResolveComponent("theHostName",
                             "anUnknownContainerName",
                             "theComponentName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test ResolveComponent gives nil pointer if hostname is unknown.

Definition at line 617 of file NamingServiceTest.cxx.

{
  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));

  NSTEST::echo_var anEchoRef = myFactory->createInstance();
  _NS.Register(anEchoRef,
               "/Containers/theHostName/theContainerName/theComponentName");

  obj = _NS.ResolveComponent("anUnknownHostName",
                             "theContainerName",
                             "theComponentName");
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Definition at line 406 of file NamingServiceTest.cxx.

{
  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; i<NB_OBJS; i++)
    {
      NSTEST::echo_var anEchoRef = myFactory->createInstance();
      ref[i] = anEchoRef->getId();
      std::string name = "/nstestfirst/echo_";
      char anum[10];
      sprintf(anum,"%d",ref[i]);
      name += anum;
      _NS.Register(anEchoRef,name.c_str());
    }

  for (int i=0; i<NB_OBJS; i++)
    {
      std::string name = "/nstestfirst/echo_";
      char anum[10];
      sprintf(anum,"%d",ref[i]);
      name += anum;
      obj = _NS.Resolve(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[i]);
    }

  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);
  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
  CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
}

Test register and resolve multiple objects, test resolveFirst, relative path Register a few objects in /nstestfirstrel/echo_n where n is the object id.

Resolve all the objects. ResolveFirst echo with a relative path /nstestfirstrel must give /nstestfirst/echo_i, corresponding to the first object.

Definition at line 458 of file NamingServiceTest.cxx.

{
  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; i<NB_OBJS; i++)
    {
      NSTEST::echo_var anEchoRef = myFactory->createInstance();
      ref[i] = anEchoRef->getId();
      std::string name = "/nstestfirstrel/echo_";
      char anum[10];
      sprintf(anum,"%d",ref[i]);
      name += anum;
      _NS.Register(anEchoRef,name.c_str());
    }

  for (int i=0; i<NB_OBJS; i++)
    {
      _NS.Change_Directory("/nstestfirstrel");
      std::string name = "echo_";
      char anum[10];
      sprintf(anum,"%d",ref[i]);
      name += anum;
      obj = _NS.Resolve(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[i]);
    }

  _NS.Change_Directory("/nstestfirstrel");
  std::string name = "echo";
  obj = _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
}

Test resolveFirst with unknown name.

Definition at line 505 of file NamingServiceTest.cxx.

{
  std::string name = "/notYeyRegistered";
  CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  name = "/nstestfirst/notYeyRegistered";
  obj = _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  name = "/rrr/sss/ttt/notYeyRegistered";
  obj = _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Test resolveFirst with unknown name, relative Path.

Definition at line 527 of file NamingServiceTest.cxx.

{
  _NS.Create_Directory("/myContext");
  _NS.Change_Directory("/myContext");

  std::string name = "RelnotYeyRegistered";
  CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  name = "Relnstestfirst/notYeyRegistered";
  obj = _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));

  name = "Relrrr/sss/ttt/notYeyRegistered";
  obj = _NS.ResolveFirst(name.c_str());
  CPPUNIT_ASSERT(CORBA::is_nil(obj));
}

Member Data Documentation

CORBA::Object_var NamingServiceTest::_factoryRef [protected]

Definition at line 152 of file NamingServiceTest.hxx.

Definition at line 151 of file NamingServiceTest.hxx.

PortableServer::ObjectId_var NamingServiceTest::_myFactoryId [protected]

Definition at line 150 of file NamingServiceTest.hxx.

Definition at line 146 of file NamingServiceTest.hxx.

CORBA::ORB_var NamingServiceTest::_orb [protected]

Definition at line 145 of file NamingServiceTest.hxx.

PortableServer::POAManager_var NamingServiceTest::_pman [protected]

Definition at line 149 of file NamingServiceTest.hxx.

PortableServer::POA_var NamingServiceTest::_root_poa [protected]

Definition at line 148 of file NamingServiceTest.hxx.


The documentation for this class was generated from the following files: