Back to index

salome-kernel  6.5.0
NamingServiceTest.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "NamingServiceTest.hxx"
00024 #include "Utils_ORB_INIT.hxx"
00025 #include "Utils_SINGLETON.hxx"
00026 
00027 #include <iostream>
00028 #include <fstream>
00029 #include <string>
00030 #include <cstdlib>
00031 #include <cstdio>
00032 
00033 
00034 // --- uncomment to have some traces on standard error
00035 //     (useful only when adding new tests...)
00036 //#define _DEVDEBUG_
00037 
00038 #ifdef _DEVDEBUG_
00039 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
00040 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
00041 #else
00042 #define MYDEVTRACE
00043 #define DEVTRACE(msg)
00044 #endif
00045 
00046 #define TRACEFILE "/tmp/traceUnitTest.log"
00047 
00048 // ============================================================================
00052 // ============================================================================
00053 
00054 NSTEST_echo_i::NSTEST_echo_i()
00055 {
00056   _num=-1;
00057 }
00058 
00059 NSTEST_echo_i::NSTEST_echo_i(CORBA::Long num)
00060 {
00061   _num=num;
00062 }
00063 
00064 NSTEST_echo_i::~NSTEST_echo_i()
00065 {
00066 }
00067 
00068 CORBA::Long NSTEST_echo_i::getId()
00069 {
00070   return _num;
00071 }
00072 
00073 // ============================================================================
00077 // ============================================================================
00078 
00079 NSTEST_aFactory_i::NSTEST_aFactory_i()
00080 {
00081   _num=0;
00082 }
00083 
00084 NSTEST_aFactory_i::~NSTEST_aFactory_i()
00085 {
00086 }
00087 
00088 NSTEST::echo_ptr NSTEST_aFactory_i::createInstance()
00089 {
00090   NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
00091   _num++;
00092   NSTEST::echo_var anEchoRef = anEcho->_this();
00093   anEcho->_remove_ref();
00094   return anEchoRef._retn();
00095 }
00096 
00097 // ============================================================================
00105 // ============================================================================
00106 
00107 void 
00108 NamingServiceTest::setUp()
00109 {
00110   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
00111   CPPUNIT_ASSERT(bp1);
00112   bp1->deleteInstance(bp1);
00113 
00114   // --- trace on file
00115   const char *theFileName = TRACEFILE;
00116 
00117   std::string s = "file:";
00118   s += theFileName;
00119   //s="local";
00120   //s="with_logger";
00121   CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
00122 
00123   std::ofstream traceFile;
00124   //  traceFile.open(theFileName, ios::out | ios::trunc);
00125   traceFile.open(theFileName, std::ios::out | std::ios::app);
00126   CPPUNIT_ASSERT(traceFile); // file created empty, then closed
00127   traceFile.close();
00128 
00129   bp1 = LocalTraceBufferPool::instance();
00130   CPPUNIT_ASSERT(bp1);
00131 
00132   // --- Get or initialize the orb
00133 
00134   int _argc = 1;
00135   char* _argv[] = {(char*)""};
00136   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00137   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
00138   _orb = init(_argc , _argv ) ;
00139 
00140   // --- Create a SALOME_NamingService instance
00141 
00142   _NS.init_orb(_orb) ;
00143 
00144   // --- Create an NSTEST::factory
00145 
00146   CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
00147   ASSERT(!CORBA::is_nil(obj));
00148   _root_poa = PortableServer::POA::_narrow(obj);
00149   _pman = _root_poa->the_POAManager();
00150   _myFactory  = new NSTEST_aFactory_i();
00151   _myFactoryId = _root_poa->activate_object(_myFactory);
00152   _factoryRef = _myFactory->_this();
00153   _pman->activate();
00154   _myFactory->_remove_ref();
00155   
00156 }
00157 
00158 // ============================================================================
00162 // ============================================================================
00163 
00164 void 
00165 NamingServiceTest::tearDown()
00166 {
00167 
00168   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
00169   CPPUNIT_ASSERT(bp1);
00170   bp1->deleteInstance(bp1);
00171 }
00172 
00173 // ============================================================================
00177 // ============================================================================
00178 
00179 void
00180 NamingServiceTest::testConstructorDefault()
00181 {
00182   SALOME_NamingService  NS;
00183   //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
00184   NS.init_orb(_orb);
00185 
00186   CORBA::String_var root = NS.getIORaddr();
00187   CORBA::Object_var obj = _orb->string_to_object(root);
00188   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00189 
00190   CosNaming::NamingContext_var rootContext =
00191     CosNaming::NamingContext::_narrow(obj);
00192   CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
00193 }
00194 
00195 // ============================================================================
00199 // ============================================================================
00200 
00201 void
00202 NamingServiceTest::testConstructorOrb()
00203 {
00204   SALOME_NamingService  NS(_orb);
00205   CORBA::String_var root = NS.getIORaddr();
00206   CORBA::Object_var obj = _orb->string_to_object(root);
00207   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00208 
00209   CosNaming::NamingContext_var rootContext =
00210     CosNaming::NamingContext::_narrow(obj);
00211   CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
00212 }
00213 
00214 // ============================================================================
00219 // ============================================================================
00220 
00221 void
00222 NamingServiceTest::testRegisterResolveAbsNoPath()
00223 {
00224   _NS.Register(_factoryRef,"/nstest_factory");
00225   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00226   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00227   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00228   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00229 }
00230 
00231 // ============================================================================
00236 // ============================================================================
00237 
00238 void
00239 NamingServiceTest::testRegisterResolveRelativeNoPath()
00240 {
00241   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00242   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00243   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00244   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00245 
00246   _NS.Create_Directory("/myContext");
00247   _NS.Change_Directory("/myContext");
00248 
00249   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00250   _NS.Register(anEchoRef,"echo_0");
00251 
00252   obj = _NS.Resolve("echo_0");
00253   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00254   NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
00255   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
00256   CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
00257 
00258   obj = _NS.Resolve("/myContext/echo_0");
00259   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00260   NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
00261   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
00262   CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
00263 }
00264 
00265 // ============================================================================
00270 // ============================================================================
00271 
00272 void
00273 NamingServiceTest::testRegisterResolveAbsWithPath()
00274 {
00275   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00276   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00277   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00278   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00279 
00280   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00281   _NS.Register(anEchoRef,"/nstest/echo_0");
00282 
00283   obj = _NS.Resolve("/nstest/echo_0");
00284   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00285   NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
00286   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
00287   CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRefa->getId());
00288 
00289   NSTEST::echo_var anEchoRef1 = myFactory->createInstance();
00290   _NS.Register(anEchoRef1,"/nstest2/rep2/rep3/echo_1");
00291   CPPUNIT_ASSERT(anEchoRef->getId() != anEchoRef1->getId());
00292 
00293   obj = _NS.Resolve("/nstest2/rep2/rep3/echo_1");
00294   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00295   NSTEST::echo_var anEchoRef1a = NSTEST::echo::_narrow(obj);
00296   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef1a));
00297   CPPUNIT_ASSERT(anEchoRef1->getId() == anEchoRef1a->getId());
00298 
00299   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00300   _NS.Register(anEchoRef2,"/nstest2/1/2/3/4/echo_1");
00301 
00302   obj = _NS.Resolve("/nstest2/1/2/3/4/echo_1");
00303   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00304   NSTEST::echo_var anEchoRef2a = NSTEST::echo::_narrow(obj);
00305   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2a));
00306   CPPUNIT_ASSERT(anEchoRef2->getId() == anEchoRef2a->getId());
00307 }
00308 
00309 // ============================================================================
00315 // ============================================================================
00316 
00317 void
00318 NamingServiceTest::testRegisterResolveRelativeWithPath()
00319 {
00320   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00321   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00322   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00323   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00324   _NS.Create_Directory("/myContext");
00325   _NS.Change_Directory("/myContext");
00326 
00327   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00328   _NS.Register(anEchoRef,"subdir/echo_0");
00329 
00330   obj = _NS.Resolve("echo_0");
00331   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00332   NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
00333   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
00334 
00335   obj = _NS.Resolve("/myContext/subdir/echo_0");
00336   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00337   NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
00338   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
00339   CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
00340 
00341   _NS.Change_Directory("/myContext");
00342   obj = _NS.Resolve("subdir/echo_0");
00343   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00344   NSTEST::echo_var anEchoRef4 = NSTEST::echo::_narrow(obj);
00345   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef4));
00346   CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef4->getId());
00347 }
00348 
00349 // ============================================================================
00353 // ============================================================================
00354 
00355 void
00356 NamingServiceTest::testResolveBadName()
00357 {
00358   CORBA::Object_var obj = _NS.Resolve("/notRegisteredName");
00359   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00360 
00361   obj = _NS.Resolve("/nstest/notRegisteredName");
00362   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00363 
00364   obj = _NS.Resolve("/unknownPath/notRegisteredName");
00365   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00366 
00367   obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName");
00368   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00369 }
00370 
00371 // ============================================================================
00375 // ============================================================================
00376 
00377 void
00378 NamingServiceTest::testResolveBadNameRelative()
00379 {
00380   _NS.Create_Directory("/myContext");
00381   _NS.Change_Directory("/myContext");
00382 
00383   CORBA::Object_var obj = _NS.Resolve("notRegisteredName");
00384   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00385 
00386   obj = _NS.Resolve("unknownPath/notRegisteredName");
00387   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00388 
00389   obj = _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName");
00390   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00391 }
00392 
00393 // ============================================================================
00401 // ============================================================================
00402 
00403 #define NB_OBJS 10
00404 
00405 void
00406 NamingServiceTest::testResolveFirst()
00407 {
00408   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00409   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00410   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00411   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00412 
00413   int ref[NB_OBJS];
00414 
00415   for (int i=0; i<NB_OBJS; i++)
00416     {
00417       NSTEST::echo_var anEchoRef = myFactory->createInstance();
00418       ref[i] = anEchoRef->getId();
00419       std::string name = "/nstestfirst/echo_";
00420       char anum[10];
00421       sprintf(anum,"%d",ref[i]);
00422       name += anum;
00423       _NS.Register(anEchoRef,name.c_str());
00424     }
00425 
00426   for (int i=0; i<NB_OBJS; i++)
00427     {
00428       std::string name = "/nstestfirst/echo_";
00429       char anum[10];
00430       sprintf(anum,"%d",ref[i]);
00431       name += anum;
00432       obj = _NS.Resolve(name.c_str());
00433       CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00434       NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
00435       CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
00436       CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
00437     }
00438 
00439   std::string name = "/nstestfirst/echo";
00440   obj = _NS.ResolveFirst(name.c_str());
00441   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00442   NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
00443   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
00444   CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
00445 }
00446 
00447 // ============================================================================
00455 // ============================================================================
00456 
00457 void
00458 NamingServiceTest::testResolveFirstRelative()
00459 {
00460   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00461   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00462   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00463   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00464 
00465   int ref[NB_OBJS];
00466 
00467   for (int i=0; i<NB_OBJS; i++)
00468     {
00469       NSTEST::echo_var anEchoRef = myFactory->createInstance();
00470       ref[i] = anEchoRef->getId();
00471       std::string name = "/nstestfirstrel/echo_";
00472       char anum[10];
00473       sprintf(anum,"%d",ref[i]);
00474       name += anum;
00475       _NS.Register(anEchoRef,name.c_str());
00476     }
00477 
00478   for (int i=0; i<NB_OBJS; i++)
00479     {
00480       _NS.Change_Directory("/nstestfirstrel");
00481       std::string name = "echo_";
00482       char anum[10];
00483       sprintf(anum,"%d",ref[i]);
00484       name += anum;
00485       obj = _NS.Resolve(name.c_str());
00486       CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00487       NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
00488       CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
00489       CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
00490     }
00491 
00492   _NS.Change_Directory("/nstestfirstrel");
00493   std::string name = "echo";
00494   obj = _NS.ResolveFirst(name.c_str());
00495   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00496 }
00497 
00498 // ============================================================================
00502 // ============================================================================
00503 
00504 void
00505 NamingServiceTest::testResolveFirstUnknown()
00506 {
00507   std::string name = "/notYeyRegistered";
00508   CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
00509   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00510 
00511   name = "/nstestfirst/notYeyRegistered";
00512   obj = _NS.ResolveFirst(name.c_str());
00513   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00514 
00515   name = "/rrr/sss/ttt/notYeyRegistered";
00516   obj = _NS.ResolveFirst(name.c_str());
00517   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00518 }
00519 
00520 // ============================================================================
00524 // ============================================================================
00525 
00526 void
00527 NamingServiceTest::testResolveFirstUnknownRelative()
00528 {
00529   _NS.Create_Directory("/myContext");
00530   _NS.Change_Directory("/myContext");
00531 
00532   std::string name = "RelnotYeyRegistered";
00533   CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
00534   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00535 
00536   name = "Relnstestfirst/notYeyRegistered";
00537   obj = _NS.ResolveFirst(name.c_str());
00538   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00539 
00540   name = "Relrrr/sss/ttt/notYeyRegistered";
00541   obj = _NS.ResolveFirst(name.c_str());
00542   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00543 }
00544 
00545 // ============================================================================
00549 // ============================================================================
00550 
00551 void
00552 NamingServiceTest::testResolveComponentOK()
00553 {
00554   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00555   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00556   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00557   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00558 
00559   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00560   _NS.Register(anEchoRef,
00561                "/Containers/theHostName/theContainerName/theComponentName");
00562 
00563   obj = _NS.ResolveComponent("theHostName",
00564                              "theContainerName",
00565                              "theComponentName");
00566   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00567   NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
00568   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
00569   CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
00570 
00571 
00572   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00573   _NS.Register(anEchoRef2,
00574                "/Containers/theHostName/theContainerName_2/theComponentName");
00575 
00576   obj = _NS.ResolveComponent("theHostName",
00577                              "theContainerName",
00578                              "theComponentName",
00579                              2);
00580   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00581   NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
00582   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
00583   CPPUNIT_ASSERT(anEchoRefb->getId() == anEchoRef2->getId());
00584 }
00585 
00586 // ============================================================================
00590 // ============================================================================
00591 
00592 void
00593 NamingServiceTest::testResolveComponentEmptyHostname()
00594 {
00595   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00596   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00597   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00598   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00599 
00600   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00601   _NS.Register(anEchoRef,
00602                "/Containers/theHostName/theContainerName/theComponentName");
00603 
00604   obj = _NS.ResolveComponent("",
00605                              "theContainerName",
00606                              "theComponentName");
00607   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00608 }
00609 
00610 // ============================================================================
00614 // ============================================================================
00615 
00616 void
00617 NamingServiceTest::testResolveComponentUnknownHostname()
00618 {
00619   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00620   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00621   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00622   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00623 
00624   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00625   _NS.Register(anEchoRef,
00626                "/Containers/theHostName/theContainerName/theComponentName");
00627 
00628   obj = _NS.ResolveComponent("anUnknownHostName",
00629                              "theContainerName",
00630                              "theComponentName");
00631   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00632 }
00633 
00634 // ============================================================================
00642 // ============================================================================
00643 
00644 void
00645 NamingServiceTest::testResolveComponentEmptyContainerName()
00646 {
00647   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00648   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00649   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00650   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00651 
00652   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00653   _NS.Register(anEchoRef,
00654                "/Containers/theHostName/theContainerName/theComponentName");
00655 
00656   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00657   _NS.Register(anEchoRef2,
00658                "/Containers/theHostName/aContainerName/aComponentName");
00659 
00660   NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
00661   _NS.Register(anEchoRef3,
00662                "/Containers/theHostName/otherContainerName/theComponentName");
00663 
00664   obj = _NS.ResolveComponent("anUnknownHostName",
00665                              "",
00666                              "theComponentName");
00667   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00668 
00669   obj = _NS.ResolveComponent("theHostName",
00670                              "",
00671                              "theComponentName");
00672   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00673   NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
00674   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
00675   CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
00676 }
00677 
00678 // ============================================================================
00682 // ============================================================================
00683 
00684 void
00685 NamingServiceTest::testResolveComponentUnknownContainerName()
00686 {
00687   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00688   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00689   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00690   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00691 
00692   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00693   _NS.Register(anEchoRef,
00694                "/Containers/theHostName/theContainerName/theComponentName");
00695 
00696   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00697   _NS.Register(anEchoRef2,
00698                "/Containers/theHostName/aContainerName/aComponentName");
00699 
00700   NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
00701   _NS.Register(anEchoRef3,
00702                "/Containers/theHostName/otherContainerName/theComponentName");
00703 
00704   obj = _NS.ResolveComponent("theHostName",
00705                              "anUnknownContainerName",
00706                              "theComponentName");
00707   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00708 }
00709 
00710 // ============================================================================
00714 // ============================================================================
00715 
00716 void
00717 NamingServiceTest::testResolveComponentEmptyComponentName()
00718 {
00719   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00720   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00721   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00722   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00723 
00724   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00725   _NS.Register(anEchoRef,
00726                "/Containers/theHostName/theContainerName/theComponentName");
00727 
00728   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00729   _NS.Register(anEchoRef2,
00730                "/Containers/theHostName/EmptyContainerName/");
00731 
00732   obj = _NS.ResolveComponent("theHostName",
00733                              "EmptyContainerName",
00734                              "");
00735   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00736 }
00737 
00738 // ============================================================================
00742 // ============================================================================
00743 
00744 void
00745 NamingServiceTest::testResolveComponentUnknownComponentName()
00746 {
00747   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00748   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00749   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00750   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00751 
00752   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00753   _NS.Register(anEchoRef,
00754                "/Containers/theHostName/theContainerName/theComponentName");
00755 
00756   obj = _NS.ResolveComponent("theHostName",
00757                              "theContainerName",
00758                              "anUnknownComponentName");
00759   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00760 }
00761 
00762 // ============================================================================
00768 // ============================================================================
00769 
00770 void
00771 NamingServiceTest::testResolveComponentFalseNbproc()
00772 {
00773   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00774   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00775   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00776   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00777 
00778   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00779   _NS.Register(anEchoRef,
00780                "/Containers/theHostName/theContainerName/theComponentName");
00781 
00782   obj = _NS.ResolveComponent("theHostName",
00783                              "theContainerName",
00784                              "theComponentName",
00785                              25);
00786   CPPUNIT_ASSERT(CORBA::is_nil(obj));
00787 
00788   obj = _NS.ResolveComponent("theHostName",
00789                              "theContainerName",
00790                              "theComponentName",
00791                              -25);
00792   CPPUNIT_ASSERT(! CORBA::is_nil(obj));
00793 }
00794 
00795 // ============================================================================
00799 // ============================================================================
00800 
00801 void
00802 NamingServiceTest::testContainerName()
00803 {
00804   std::string ref0 = "FactoryServer";
00805   std::string ret = _NS.ContainerName("");
00806   CPPUNIT_ASSERT(ret == ref0);
00807 
00808   ref0 = "MyContainerName";
00809   ret = _NS.ContainerName(ref0.c_str());
00810   CPPUNIT_ASSERT(ret == ref0);
00811 }
00812 
00813 // ============================================================================
00817 // ============================================================================
00818 
00819 void
00820 NamingServiceTest::testContainerNameParams()
00821 {
00822   Engines::MachineParameters params;
00823   params.container_name = "";
00824   params.hostname = "";
00825   params.OS = "";
00826   params.mem_mb = 0;
00827   params.cpu_clock = 0;
00828   params.nb_proc_per_node = 0;
00829   params.nb_node = 0;
00830   params.isMPI = false;
00831 
00832   std::string ref0 = "FactoryServer";
00833   std::string ret = _NS.ContainerName(params);
00834   CPPUNIT_ASSERT(ret == ref0);
00835 
00836   ref0 = "MyContainerName";
00837   params.container_name = ref0.c_str();
00838   ret = _NS.ContainerName(params);
00839   CPPUNIT_ASSERT(ret == ref0);
00840 }
00841 
00842 // ============================================================================
00846 // ============================================================================
00847 
00848 void
00849 NamingServiceTest::testBuildContainerNameForNS()
00850 {
00851   std::string ref0 = "/Containers/theHostName/theContainerName";
00852   std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
00853   CPPUNIT_ASSERT(ret == ref0);
00854 
00855   ref0 = "/Containers/theHostName/FactoryServer";
00856   ret = _NS.BuildContainerNameForNS("","theHostName");
00857   CPPUNIT_ASSERT(ret == ref0);
00858 }
00859 
00860 // ============================================================================
00864 // ============================================================================
00865 
00866 void
00867 NamingServiceTest::testBuildContainerNameForNSParams()
00868 {
00869   Engines::MachineParameters params;
00870   params.container_name = "";
00871   params.hostname = "";
00872   params.OS = "";
00873   params.mem_mb = 0;
00874   params.cpu_clock = 0;
00875   params.nb_proc_per_node = 0;
00876   params.nb_node = 0;
00877   params.isMPI = false;
00878 
00879   params.container_name = "theContainerName";
00880   std::string ref0 = "/Containers/theHostName/theContainerName";
00881   std::string ret = _NS.BuildContainerNameForNS(params,"theHostName");
00882   CPPUNIT_ASSERT(ret == ref0);
00883 
00884   params.container_name = "";
00885   ref0 = "/Containers/theHostName/FactoryServer";
00886   ret = _NS.BuildContainerNameForNS(params,"theHostName");
00887   CPPUNIT_ASSERT(ret == ref0);
00888 }
00889 
00890 // ============================================================================
00894 // ============================================================================
00895 
00896 void
00897 NamingServiceTest::testFind()
00898 {
00899   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00900   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00901   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00902   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00903 
00904   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00905   _NS.Register(anEchoRef,
00906                "/Containers/theHostName/theContainerName/theComponentName");
00907 
00908   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00909   _NS.Register(anEchoRef2,
00910                "/Containers/theHostName/aContainerName/aComponentName");
00911 
00912   NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
00913   _NS.Register(anEchoRef3,
00914                "/Containers/theHostName/otherContainerName/theComponentName");
00915 
00916   NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
00917   _NS.Register(anEchoRef4,
00918                "/Containers/anHostName/oneContainerName/theComponentName");
00919 
00920   _NS.Change_Directory("/Containers");
00921   int occ= _NS.Find("theComponentName");
00922   CPPUNIT_ASSERT(occ >= 3); // see previous tests
00923 
00924   _NS.Change_Directory("/Containers");
00925   occ= _NS.Find("aComponentName");
00926   CPPUNIT_ASSERT(occ == 1);
00927 
00928   _NS.Change_Directory("/Containers");
00929   occ= _NS.Find("UnknownCompnentName");
00930   CPPUNIT_ASSERT(occ == 0);
00931 }
00932 
00933 // ============================================================================
00937 // ============================================================================
00938 
00939 void
00940 NamingServiceTest::testCreateDirectory()
00941 {
00942   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00943   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00944   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00945   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00946 
00947   bool ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
00948   CPPUNIT_ASSERT(ret);
00949 
00950   _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
00951   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00952   int val = anEchoRef->getId();
00953   std::string name = "echo_";
00954   char anum[10];
00955   sprintf(anum,"%d",val);
00956   name += anum;
00957   _NS.Register(anEchoRef,name.c_str());
00958 
00959   std::string dirname = "/aaa/bbb/ccc/ddd/eee/";
00960   dirname += name;
00961   obj = _NS.Resolve(dirname.c_str());
00962   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00963   NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
00964   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
00965   CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
00966 
00967   ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
00968   CPPUNIT_ASSERT(ret);
00969 
00970   _NS.Change_Directory("/aaa/bbb");
00971   ret = _NS.Create_Directory("cccccc/dddddd/eeeeee");
00972   _NS.Register(anEchoRef,"echo_abcde");
00973 
00974   CPPUNIT_ASSERT(ret);
00975   _NS.Change_Directory("/aaa/bbb/cccccc/dddddd/eeeeee");
00976   obj = _NS.Resolve("echo_abcde");
00977   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00978 }
00979 
00980 // ============================================================================
00984 // ============================================================================
00985 
00986 void
00987 NamingServiceTest::testChangeDirectory()
00988 {
00989   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
00990   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00991   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
00992   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
00993 
00994   NSTEST::echo_var anEchoRef = myFactory->createInstance();
00995   _NS.Register(anEchoRef,
00996                "/Containers/theHostName/theContainerName/theComponentName");
00997 
00998   NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
00999   _NS.Register(anEchoRef2,
01000                "/Containers/theHostName/aContainerName/aComponentName");
01001 
01002   NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
01003   _NS.Register(anEchoRef3,
01004                "/Containers/theHostName/otherContainerName/theComponentName");
01005 
01006   NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
01007   _NS.Register(anEchoRef4,
01008                "/Containers/anHostName/oneContainerName/theComponentName");
01009   
01010   _NS.Change_Directory("/Containers/theHostName/otherContainerName");
01011   obj = _NS.Resolve("theComponentName");
01012   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
01013   
01014   NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
01015   CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
01016   CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId());
01017 }
01018 
01019 // ============================================================================
01023 // ============================================================================
01024 
01025 void
01026 NamingServiceTest::testCurrentDirectory()
01027 {
01028   std::string path = "/aaa/bbb/ccc/ddd/eee";
01029   bool ret = _NS.Create_Directory(path.c_str());
01030   CPPUNIT_ASSERT(ret);
01031 
01032   _NS.Change_Directory(path.c_str());
01033   char* acurdir = _NS.Current_Directory();
01034   std::string curdir = acurdir;
01035   free(acurdir);
01036   CPPUNIT_ASSERT(curdir == path);
01037 }
01038 
01039 // ============================================================================
01043 // ============================================================================
01044 
01045 void
01046 NamingServiceTest::testList()
01047 {
01048   _NS.Change_Directory("/Containers/theHostName/theContainerName");
01049   _NS.list();
01050   _NS.Change_Directory("/Containers");
01051   _NS.list();
01052 }
01053 
01054 // ============================================================================
01058 // ============================================================================
01059 
01060 void
01061 NamingServiceTest::testListDirectory()
01062 {
01063   _NS.Change_Directory("/Containers/theHostName/theContainerName");
01064   _NS.list_directory();
01065   _NS.Change_Directory("/Containers");
01066   _NS.list_directory();
01067 }
01068 
01069 // ============================================================================
01073 // ============================================================================
01074 
01075 void
01076 NamingServiceTest::testListDirectoryRecurs()
01077 {
01078   _NS.Change_Directory("/Containers/theHostName/theContainerName");
01079   _NS.list_directory_recurs();
01080   _NS.Change_Directory("/Containers");
01081   _NS.list_directory_recurs();
01082   _NS.Change_Directory("/");
01083   _NS.list_directory_recurs();
01084 }
01085 
01086 
01087 // ============================================================================
01091 // ============================================================================
01092 
01093 void
01094 NamingServiceTest::testListSubdirs()
01095 {
01096   _NS.Change_Directory("/Containers/theHostName/theContainerName");
01097   _NS.list_subdirs();
01098   _NS.Change_Directory("/Containers");
01099   _NS.list_subdirs();
01100   _NS.Change_Directory("/");
01101   _NS.list_subdirs();
01102 }
01103 // ============================================================================
01107 // ============================================================================
01108 
01109 void
01110 NamingServiceTest::testDestroyName()
01111 {
01112   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
01113   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
01114   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
01115   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
01116 
01117   std::string path = "/Containers/theHostName/theContainerName/theComponentName";
01118 
01119   NSTEST::echo_var anEchoRef = myFactory->createInstance();
01120   _NS.Register(anEchoRef, path.c_str());
01121 
01122   obj=_NS.Resolve(path.c_str());
01123   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
01124 
01125   _NS.Destroy_Name(path.c_str());
01126   obj=_NS.Resolve(path.c_str());
01127   CPPUNIT_ASSERT(CORBA::is_nil(obj));
01128 }
01129 
01130 // ============================================================================
01134 // ============================================================================
01135 
01136 void
01137 NamingServiceTest::testDestroyDirectory()
01138 {
01139   CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
01140   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
01141   NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
01142   CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
01143 
01144   std::string path = "/Containers/theHostName/theContainerName/theComponentName";
01145 
01146   NSTEST::echo_var anEchoRef = myFactory->createInstance();
01147   _NS.Register(anEchoRef, path.c_str());
01148 
01149   _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
01150   obj=_NS.Resolve(path.c_str());
01151   CPPUNIT_ASSERT(!CORBA::is_nil(obj)); // directory not empty: not destroyed
01152 
01153   _NS.Destroy_Name(path.c_str());
01154   _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
01155   _NS.Change_Directory("/Containers/theHostName");
01156   _NS.list_subdirs();
01157 }
01158 
01159 // ============================================================================
01164 // ============================================================================
01165 
01166 void NamingServiceTest::_destroyDirectoryRecurs(std::string path)
01167 {
01168   std::string current = path;
01169   SCRUTE(path);
01170   if (_NS.Change_Directory(path.c_str()))
01171     {
01172       std::vector<std::string> subdirs = _NS.list_subdirs();
01173       for (int i=0; i<subdirs.size(); i++)
01174         {
01175           std::string subpath=path + "/" +subdirs[i];
01176           _destroyDirectoryRecurs(subpath);
01177         }
01178       if (_NS.Change_Directory(path.c_str()))
01179         {
01180           _NS.Destroy_FullDirectory(path.c_str());
01181         }
01182     }
01183 }
01184 
01185 void
01186 NamingServiceTest::testDestroyFullDirectory()
01187 {
01188   _NS.Destroy_FullDirectory("/Containers");
01189   CPPUNIT_ASSERT(_NS.Change_Directory("/Containers"));
01190   std::vector<std::string> subdirs = _NS.list_subdirs();
01191   CPPUNIT_ASSERT(subdirs.size() >0);
01192   _NS.list_directory_recurs();
01193   std::string path = "/Containers";
01194   _destroyDirectoryRecurs(path);
01195   CPPUNIT_ASSERT( ! _NS.Change_Directory("/Containers"));
01196   _NS.Change_Directory("/");
01197   _NS.list_subdirs();
01198   _NS.list_directory_recurs();
01199 }
01200 
01201 // ============================================================================
01205 // ============================================================================
01206 
01207 void
01208 NamingServiceTest::testGetIorAddr()
01209 {
01210   CORBA::String_var root = _NS.getIORaddr();
01211   CORBA::Object_var obj = _orb->string_to_object(root);
01212   CPPUNIT_ASSERT(!CORBA::is_nil(obj)); 
01213 }
01214 
01215 // ============================================================================
01219 // ============================================================================
01220 
01221 // void
01222 // NamingServiceTest::()
01223 // {
01224 //   CPPUNIT_ASSERT(0);
01225 // }
01226