1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "NamingServiceTest.hxx"
24 #include "Utils_ORB_INIT.hxx"
25 #include "Utils_SINGLETON.hxx"
26 #include "Basics_Utils.hxx"
35 // --- uncomment to have some traces on standard error
36 // (useful only when adding new tests...)
40 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
41 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
48 #define setenv Kernel_Utils::setenv
51 #define TRACEFILE "/tmp/traceUnitTest.log"
53 // ============================================================================
55 * a basic CORBA object implementation for use with namingService tests
57 // ============================================================================
59 NSTEST_echo_i::NSTEST_echo_i()
64 NSTEST_echo_i::NSTEST_echo_i(CORBA::Long num)
69 NSTEST_echo_i::~NSTEST_echo_i()
73 CORBA::Long NSTEST_echo_i::getId()
78 // ============================================================================
80 * a factory of CORBA objects for use with namingService tests
82 // ============================================================================
84 NSTEST_aFactory_i::NSTEST_aFactory_i()
89 NSTEST_aFactory_i::~NSTEST_aFactory_i()
93 NSTEST::echo_ptr NSTEST_aFactory_i::createInstance()
95 NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
97 NSTEST::echo_var anEchoRef = anEcho->_this();
98 anEcho->_remove_ref();
99 return anEchoRef._retn();
102 // ============================================================================
105 * - delete preexisting trace classes if any
106 * - set trace on file
107 * Get or initialize the orb
108 * Create a SALOME_NamingService instance
110 // ============================================================================
113 NamingServiceTest::setUp()
115 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
117 bp1->deleteInstance(bp1);
120 const char *theFileName = TRACEFILE;
122 std::string s = "file:";
126 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
128 std::ofstream traceFile;
129 // traceFile.open(theFileName, ios::out | ios::trunc);
130 traceFile.open(theFileName, std::ios::out | std::ios::app);
131 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
134 bp1 = LocalTraceBufferPool::instance();
137 // --- Get or initialize the orb
140 char* _argv[] = {(char*)""};
141 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
142 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
143 _orb = init(_argc , _argv ) ;
145 // --- Create a SALOME_NamingService instance
149 // --- Create an NSTEST::factory
151 CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
152 ASSERT(!CORBA::is_nil(obj));
153 _root_poa = PortableServer::POA::_narrow(obj);
154 _pman = _root_poa->the_POAManager();
155 _myFactory = new NSTEST_aFactory_i();
156 _myFactoryId = _root_poa->activate_object(_myFactory);
157 _factoryRef = _myFactory->_this();
159 _myFactory->_remove_ref();
163 // ============================================================================
165 * - delete trace classes
167 // ============================================================================
170 NamingServiceTest::tearDown()
173 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
175 bp1->deleteInstance(bp1);
178 // ============================================================================
180 * Test default constructor: must be followed by a call to init_orb(ORB)
182 // ============================================================================
185 NamingServiceTest::testConstructorDefault()
187 SALOME_NamingService NS;
188 //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
191 CORBA::String_var root = NS.getIORaddr();
192 CORBA::Object_var obj = _orb->string_to_object(root);
193 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
195 CosNaming::NamingContext_var rootContext =
196 CosNaming::NamingContext::_narrow(obj);
197 CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
200 // ============================================================================
202 * Test constructor with ORB parameter
204 // ============================================================================
207 NamingServiceTest::testConstructorOrb()
209 SALOME_NamingService NS(_orb);
210 CORBA::String_var root = NS.getIORaddr();
211 CORBA::Object_var obj = _orb->string_to_object(root);
212 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
214 CosNaming::NamingContext_var rootContext =
215 CosNaming::NamingContext::_narrow(obj);
216 CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
219 // ============================================================================
221 * Test Register and resolve of a single CORBA object with absolute pathname,
222 * without subdirectories
224 // ============================================================================
227 NamingServiceTest::testRegisterResolveAbsNoPath()
229 _NS.Register(_factoryRef,"/nstest_factory");
230 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
231 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
232 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
233 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
236 // ============================================================================
238 * Test Register and resolve of a single CORBA object with relative pathname,
239 * without subdirectories
241 // ============================================================================
244 NamingServiceTest::testRegisterResolveRelativeNoPath()
246 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
247 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
248 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
249 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
251 _NS.Create_Directory("/myContext");
252 _NS.Change_Directory("/myContext");
254 NSTEST::echo_var anEchoRef = myFactory->createInstance();
255 _NS.Register(anEchoRef,"echo_0");
257 obj = _NS.Resolve("echo_0");
258 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
259 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
260 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
261 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
263 obj = _NS.Resolve("/myContext/echo_0");
264 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
265 NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
266 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
267 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
270 // ============================================================================
272 * Test Register and resolve of a single CORBA object with absolute pathname,
275 // ============================================================================
278 NamingServiceTest::testRegisterResolveAbsWithPath()
280 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
281 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
282 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
283 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
285 NSTEST::echo_var anEchoRef = myFactory->createInstance();
286 _NS.Register(anEchoRef,"/nstest/echo_0");
288 obj = _NS.Resolve("/nstest/echo_0");
289 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
290 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
291 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
292 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRefa->getId());
294 NSTEST::echo_var anEchoRef1 = myFactory->createInstance();
295 _NS.Register(anEchoRef1,"/nstest2/rep2/rep3/echo_1");
296 CPPUNIT_ASSERT(anEchoRef->getId() != anEchoRef1->getId());
298 obj = _NS.Resolve("/nstest2/rep2/rep3/echo_1");
299 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
300 NSTEST::echo_var anEchoRef1a = NSTEST::echo::_narrow(obj);
301 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef1a));
302 CPPUNIT_ASSERT(anEchoRef1->getId() == anEchoRef1a->getId());
304 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
305 _NS.Register(anEchoRef2,"/nstest2/1/2/3/4/echo_1");
307 obj = _NS.Resolve("/nstest2/1/2/3/4/echo_1");
308 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
309 NSTEST::echo_var anEchoRef2a = NSTEST::echo::_narrow(obj);
310 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2a));
311 CPPUNIT_ASSERT(anEchoRef2->getId() == anEchoRef2a->getId());
314 // ============================================================================
316 * Test Register and resolve of a single CORBA object with relative pathname,
318 * Relative Path is changed to the created subdirectory when Register()
320 // ============================================================================
323 NamingServiceTest::testRegisterResolveRelativeWithPath()
325 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
326 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
327 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
328 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
329 _NS.Create_Directory("/myContext");
330 _NS.Change_Directory("/myContext");
332 NSTEST::echo_var anEchoRef = myFactory->createInstance();
333 _NS.Register(anEchoRef,"subdir/echo_0");
335 obj = _NS.Resolve("echo_0");
336 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
337 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
338 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
340 obj = _NS.Resolve("/myContext/subdir/echo_0");
341 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
342 NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
343 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
344 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
346 _NS.Change_Directory("/myContext");
347 obj = _NS.Resolve("subdir/echo_0");
348 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
349 NSTEST::echo_var anEchoRef4 = NSTEST::echo::_narrow(obj);
350 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef4));
351 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef4->getId());
354 // ============================================================================
356 * Test resolve with a name not known
358 // ============================================================================
361 NamingServiceTest::testResolveBadName()
363 CORBA::Object_var obj = _NS.Resolve("/notRegisteredName");
364 CPPUNIT_ASSERT(CORBA::is_nil(obj));
366 obj = _NS.Resolve("/nstest/notRegisteredName");
367 CPPUNIT_ASSERT(CORBA::is_nil(obj));
369 obj = _NS.Resolve("/unknownPath/notRegisteredName");
370 CPPUNIT_ASSERT(CORBA::is_nil(obj));
372 obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName");
373 CPPUNIT_ASSERT(CORBA::is_nil(obj));
376 // ============================================================================
378 * Test resolve with a name not known, with a relative path
380 // ============================================================================
383 NamingServiceTest::testResolveBadNameRelative()
385 _NS.Create_Directory("/myContext");
386 _NS.Change_Directory("/myContext");
388 CORBA::Object_var obj = _NS.Resolve("notRegisteredName");
389 CPPUNIT_ASSERT(CORBA::is_nil(obj));
391 obj = _NS.Resolve("unknownPath/notRegisteredName");
392 CPPUNIT_ASSERT(CORBA::is_nil(obj));
394 obj = _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName");
395 CPPUNIT_ASSERT(CORBA::is_nil(obj));
398 // ============================================================================
400 * Test register and resolve multiple objects, test resolveFirst.
401 * Register a few objects in /nstestfirst/echo_n where n is the object id.
402 * Resolve all the objects.
403 * ResolveFirst /nstestfirst/echo must give /nstestfirst/echo_i, corresponding
404 * to the first object.
406 // ============================================================================
411 NamingServiceTest::testResolveFirst()
413 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
414 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
415 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
416 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
420 for (int i=0; i<NB_OBJS; i++)
422 NSTEST::echo_var anEchoRef = myFactory->createInstance();
423 ref[i] = anEchoRef->getId();
424 std::string name = "/nstestfirst/echo_";
426 sprintf(anum,"%d",ref[i]);
428 _NS.Register(anEchoRef,name.c_str());
431 for (int i=0; i<NB_OBJS; i++)
433 std::string name = "/nstestfirst/echo_";
435 sprintf(anum,"%d",ref[i]);
437 obj = _NS.Resolve(name.c_str());
438 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
439 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
440 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
441 CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
444 std::string name = "/nstestfirst/echo";
445 obj = _NS.ResolveFirst(name.c_str());
446 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
447 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
448 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
449 CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
452 // ============================================================================
454 * Test register and resolve multiple objects, test resolveFirst, relative path
455 * Register a few objects in /nstestfirstrel/echo_n where n is the object id.
456 * Resolve all the objects.
457 * ResolveFirst echo with a relative path /nstestfirstrel must give
458 * /nstestfirst/echo_i, corresponding to the first object.
460 // ============================================================================
463 NamingServiceTest::testResolveFirstRelative()
465 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
466 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
467 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
468 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
472 for (int i=0; i<NB_OBJS; i++)
474 NSTEST::echo_var anEchoRef = myFactory->createInstance();
475 ref[i] = anEchoRef->getId();
476 std::string name = "/nstestfirstrel/echo_";
478 sprintf(anum,"%d",ref[i]);
480 _NS.Register(anEchoRef,name.c_str());
483 for (int i=0; i<NB_OBJS; i++)
485 _NS.Change_Directory("/nstestfirstrel");
486 std::string name = "echo_";
488 sprintf(anum,"%d",ref[i]);
490 obj = _NS.Resolve(name.c_str());
491 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
492 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
493 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
494 CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
497 _NS.Change_Directory("/nstestfirstrel");
498 std::string name = "echo";
499 obj = _NS.ResolveFirst(name.c_str());
500 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
503 // ============================================================================
505 * Test resolveFirst with unknown name
507 // ============================================================================
510 NamingServiceTest::testResolveFirstUnknown()
512 std::string name = "/notYeyRegistered";
513 CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
514 CPPUNIT_ASSERT(CORBA::is_nil(obj));
516 name = "/nstestfirst/notYeyRegistered";
517 obj = _NS.ResolveFirst(name.c_str());
518 CPPUNIT_ASSERT(CORBA::is_nil(obj));
520 name = "/rrr/sss/ttt/notYeyRegistered";
521 obj = _NS.ResolveFirst(name.c_str());
522 CPPUNIT_ASSERT(CORBA::is_nil(obj));
525 // ============================================================================
527 * Test resolveFirst with unknown name, relative Path
529 // ============================================================================
532 NamingServiceTest::testResolveFirstUnknownRelative()
534 _NS.Create_Directory("/myContext");
535 _NS.Change_Directory("/myContext");
537 std::string name = "RelnotYeyRegistered";
538 CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
539 CPPUNIT_ASSERT(CORBA::is_nil(obj));
541 name = "Relnstestfirst/notYeyRegistered";
542 obj = _NS.ResolveFirst(name.c_str());
543 CPPUNIT_ASSERT(CORBA::is_nil(obj));
545 name = "Relrrr/sss/ttt/notYeyRegistered";
546 obj = _NS.ResolveFirst(name.c_str());
547 CPPUNIT_ASSERT(CORBA::is_nil(obj));
550 // ============================================================================
552 * Test ResolveComponent works as specified
554 // ============================================================================
557 NamingServiceTest::testResolveComponentOK()
559 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
560 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
561 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
562 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
564 NSTEST::echo_var anEchoRef = myFactory->createInstance();
565 _NS.Register(anEchoRef,
566 "/Containers/theHostName/theContainerName/theComponentName");
568 obj = _NS.ResolveComponent("theHostName",
571 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
572 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
573 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
574 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
577 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
578 _NS.Register(anEchoRef2,
579 "/Containers/theHostName/theContainerName_2/theComponentName");
581 obj = _NS.ResolveComponent("theHostName",
585 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
586 NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
587 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
588 CPPUNIT_ASSERT(anEchoRefb->getId() == anEchoRef2->getId());
591 // ============================================================================
593 * Test ResolveComponent gives nil pointer if hostname is not given (empty)
595 // ============================================================================
598 NamingServiceTest::testResolveComponentEmptyHostname()
600 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
601 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
602 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
603 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
605 NSTEST::echo_var anEchoRef = myFactory->createInstance();
606 _NS.Register(anEchoRef,
607 "/Containers/theHostName/theContainerName/theComponentName");
609 obj = _NS.ResolveComponent("",
612 CPPUNIT_ASSERT(CORBA::is_nil(obj));
615 // ============================================================================
617 * Test ResolveComponent gives nil pointer if hostname is unknown
619 // ============================================================================
622 NamingServiceTest::testResolveComponentUnknownHostname()
624 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
625 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
626 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
627 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
629 NSTEST::echo_var anEchoRef = myFactory->createInstance();
630 _NS.Register(anEchoRef,
631 "/Containers/theHostName/theContainerName/theComponentName");
633 obj = _NS.ResolveComponent("anUnknownHostName",
636 CPPUNIT_ASSERT(CORBA::is_nil(obj));
639 // ============================================================================
641 * Test ResolveComponent when containerName is empty.
642 * check bad hostname gives nil pointer.
643 * If componentName registered on a container from hostname, a component
644 * reference is found (the first one).
645 * Else give nil pointer.
647 // ============================================================================
650 NamingServiceTest::testResolveComponentEmptyContainerName()
652 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
653 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
654 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
655 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
657 NSTEST::echo_var anEchoRef = myFactory->createInstance();
658 _NS.Register(anEchoRef,
659 "/Containers/theHostName/theContainerName/theComponentName");
661 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
662 _NS.Register(anEchoRef2,
663 "/Containers/theHostName/aContainerName/aComponentName");
665 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
666 _NS.Register(anEchoRef3,
667 "/Containers/theHostName/otherContainerName/theComponentName");
669 obj = _NS.ResolveComponent("anUnknownHostName",
672 CPPUNIT_ASSERT(CORBA::is_nil(obj));
674 obj = _NS.ResolveComponent("theHostName",
677 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
678 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
679 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
680 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
683 // ============================================================================
687 // ============================================================================
690 NamingServiceTest::testResolveComponentUnknownContainerName()
692 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
693 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
694 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
695 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
697 NSTEST::echo_var anEchoRef = myFactory->createInstance();
698 _NS.Register(anEchoRef,
699 "/Containers/theHostName/theContainerName/theComponentName");
701 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
702 _NS.Register(anEchoRef2,
703 "/Containers/theHostName/aContainerName/aComponentName");
705 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
706 _NS.Register(anEchoRef3,
707 "/Containers/theHostName/otherContainerName/theComponentName");
709 obj = _NS.ResolveComponent("theHostName",
710 "anUnknownContainerName",
712 CPPUNIT_ASSERT(CORBA::is_nil(obj));
715 // ============================================================================
719 // ============================================================================
722 NamingServiceTest::testResolveComponentEmptyComponentName()
724 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
725 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
726 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
727 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
729 NSTEST::echo_var anEchoRef = myFactory->createInstance();
730 _NS.Register(anEchoRef,
731 "/Containers/theHostName/theContainerName/theComponentName");
733 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
734 _NS.Register(anEchoRef2,
735 "/Containers/theHostName/EmptyContainerName/");
737 obj = _NS.ResolveComponent("theHostName",
738 "EmptyContainerName",
740 CPPUNIT_ASSERT(CORBA::is_nil(obj));
743 // ============================================================================
747 // ============================================================================
750 NamingServiceTest::testResolveComponentUnknownComponentName()
752 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
753 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
754 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
755 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
757 NSTEST::echo_var anEchoRef = myFactory->createInstance();
758 _NS.Register(anEchoRef,
759 "/Containers/theHostName/theContainerName/theComponentName");
761 obj = _NS.ResolveComponent("theHostName",
763 "anUnknownComponentName");
764 CPPUNIT_ASSERT(CORBA::is_nil(obj));
767 // ============================================================================
769 * Test with a false number nbproc.
770 * A positive number not corresponding to a registered component gives nil ref.
771 * A negative number is not taken into account and may give a non nil ref.
773 // ============================================================================
776 NamingServiceTest::testResolveComponentFalseNbproc()
778 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
779 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
780 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
781 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
783 NSTEST::echo_var anEchoRef = myFactory->createInstance();
784 _NS.Register(anEchoRef,
785 "/Containers/theHostName/theContainerName/theComponentName");
787 obj = _NS.ResolveComponent("theHostName",
791 CPPUNIT_ASSERT(CORBA::is_nil(obj));
793 obj = _NS.ResolveComponent("theHostName",
797 CPPUNIT_ASSERT(! CORBA::is_nil(obj));
800 // ============================================================================
804 // ============================================================================
807 NamingServiceTest::testContainerName()
809 std::string ref0 = "FactoryServer";
810 std::string ret = _NS.ContainerName("");
811 CPPUNIT_ASSERT(ret == ref0);
813 ref0 = "MyContainerName";
814 ret = _NS.ContainerName(ref0.c_str());
815 CPPUNIT_ASSERT(ret == ref0);
818 // ============================================================================
822 // ============================================================================
825 NamingServiceTest::testContainerNameParams()
827 Engines::MachineParameters params;
828 params.container_name = "";
829 params.hostname = "";
832 params.cpu_clock = 0;
833 params.nb_proc_per_node = 0;
835 params.isMPI = false;
837 std::string ref0 = "FactoryServer";
838 std::string ret = _NS.ContainerName(params);
839 CPPUNIT_ASSERT(ret == ref0);
841 ref0 = "MyContainerName";
842 params.container_name = ref0.c_str();
843 ret = _NS.ContainerName(params);
844 CPPUNIT_ASSERT(ret == ref0);
847 // ============================================================================
851 // ============================================================================
854 NamingServiceTest::testBuildContainerNameForNS()
856 std::string ref0 = "/Containers/theHostName/theContainerName";
857 std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
858 CPPUNIT_ASSERT(ret == ref0);
860 ref0 = "/Containers/theHostName/FactoryServer";
861 ret = _NS.BuildContainerNameForNS("","theHostName");
862 CPPUNIT_ASSERT(ret == ref0);
865 // ============================================================================
869 // ============================================================================
872 NamingServiceTest::testBuildContainerNameForNSParams()
874 Engines::MachineParameters params;
875 params.container_name = "";
876 params.hostname = "";
879 params.cpu_clock = 0;
880 params.nb_proc_per_node = 0;
882 params.isMPI = false;
884 params.container_name = "theContainerName";
885 std::string ref0 = "/Containers/theHostName/theContainerName";
886 std::string ret = _NS.BuildContainerNameForNS(params,"theHostName");
887 CPPUNIT_ASSERT(ret == ref0);
889 params.container_name = "";
890 ref0 = "/Containers/theHostName/FactoryServer";
891 ret = _NS.BuildContainerNameForNS(params,"theHostName");
892 CPPUNIT_ASSERT(ret == ref0);
895 // ============================================================================
899 // ============================================================================
902 NamingServiceTest::testFind()
904 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
905 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
906 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
907 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
909 NSTEST::echo_var anEchoRef = myFactory->createInstance();
910 _NS.Register(anEchoRef,
911 "/Containers/theHostName/theContainerName/theComponentName");
913 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
914 _NS.Register(anEchoRef2,
915 "/Containers/theHostName/aContainerName/aComponentName");
917 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
918 _NS.Register(anEchoRef3,
919 "/Containers/theHostName/otherContainerName/theComponentName");
921 NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
922 _NS.Register(anEchoRef4,
923 "/Containers/anHostName/oneContainerName/theComponentName");
925 _NS.Change_Directory("/Containers");
926 int occ= _NS.Find("theComponentName");
927 CPPUNIT_ASSERT(occ >= 3); // see previous tests
929 _NS.Change_Directory("/Containers");
930 occ= _NS.Find("aComponentName");
931 CPPUNIT_ASSERT(occ == 1);
933 _NS.Change_Directory("/Containers");
934 occ= _NS.Find("UnknownCompnentName");
935 CPPUNIT_ASSERT(occ == 0);
938 // ============================================================================
942 // ============================================================================
945 NamingServiceTest::testCreateDirectory()
947 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
948 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
949 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
950 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
952 bool ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
955 _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
956 NSTEST::echo_var anEchoRef = myFactory->createInstance();
957 int val = anEchoRef->getId();
958 std::string name = "echo_";
960 sprintf(anum,"%d",val);
962 _NS.Register(anEchoRef,name.c_str());
964 std::string dirname = "/aaa/bbb/ccc/ddd/eee/";
966 obj = _NS.Resolve(dirname.c_str());
967 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
968 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
969 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
970 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
972 ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
975 _NS.Change_Directory("/aaa/bbb");
976 ret = _NS.Create_Directory("cccccc/dddddd/eeeeee");
977 _NS.Register(anEchoRef,"echo_abcde");
980 _NS.Change_Directory("/aaa/bbb/cccccc/dddddd/eeeeee");
981 obj = _NS.Resolve("echo_abcde");
982 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
985 // ============================================================================
989 // ============================================================================
992 NamingServiceTest::testChangeDirectory()
994 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
995 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
996 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
997 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
999 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1000 _NS.Register(anEchoRef,
1001 "/Containers/theHostName/theContainerName/theComponentName");
1003 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
1004 _NS.Register(anEchoRef2,
1005 "/Containers/theHostName/aContainerName/aComponentName");
1007 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
1008 _NS.Register(anEchoRef3,
1009 "/Containers/theHostName/otherContainerName/theComponentName");
1011 NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
1012 _NS.Register(anEchoRef4,
1013 "/Containers/anHostName/oneContainerName/theComponentName");
1015 _NS.Change_Directory("/Containers/theHostName/otherContainerName");
1016 obj = _NS.Resolve("theComponentName");
1017 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1019 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
1020 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
1021 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId());
1024 // ============================================================================
1028 // ============================================================================
1031 NamingServiceTest::testCurrentDirectory()
1033 std::string path = "/aaa/bbb/ccc/ddd/eee";
1034 bool ret = _NS.Create_Directory(path.c_str());
1035 CPPUNIT_ASSERT(ret);
1037 _NS.Change_Directory(path.c_str());
1038 char* acurdir = _NS.Current_Directory();
1039 std::string curdir = acurdir;
1041 CPPUNIT_ASSERT(curdir == path);
1044 // ============================================================================
1048 // ============================================================================
1051 NamingServiceTest::testList()
1053 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1055 _NS.Change_Directory("/Containers");
1059 // ============================================================================
1063 // ============================================================================
1066 NamingServiceTest::testListDirectory()
1068 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1069 _NS.list_directory();
1070 _NS.Change_Directory("/Containers");
1071 _NS.list_directory();
1074 // ============================================================================
1078 // ============================================================================
1081 NamingServiceTest::testListDirectoryRecurs()
1083 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1084 _NS.list_directory_recurs();
1085 _NS.Change_Directory("/Containers");
1086 _NS.list_directory_recurs();
1087 _NS.Change_Directory("/");
1088 _NS.list_directory_recurs();
1092 // ============================================================================
1096 // ============================================================================
1099 NamingServiceTest::testListSubdirs()
1101 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1103 _NS.Change_Directory("/Containers");
1105 _NS.Change_Directory("/");
1108 // ============================================================================
1112 // ============================================================================
1115 NamingServiceTest::testDestroyName()
1117 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
1118 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1119 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
1120 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
1122 std::string path = "/Containers/theHostName/theContainerName/theComponentName";
1124 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1125 _NS.Register(anEchoRef, path.c_str());
1127 obj=_NS.Resolve(path.c_str());
1128 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1130 _NS.Destroy_Name(path.c_str());
1131 obj=_NS.Resolve(path.c_str());
1132 CPPUNIT_ASSERT(CORBA::is_nil(obj));
1135 // ============================================================================
1139 // ============================================================================
1142 NamingServiceTest::testDestroyDirectory()
1144 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
1145 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1146 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
1147 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
1149 std::string path = "/Containers/theHostName/theContainerName/theComponentName";
1151 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1152 _NS.Register(anEchoRef, path.c_str());
1154 _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
1155 obj=_NS.Resolve(path.c_str());
1156 CPPUNIT_ASSERT(!CORBA::is_nil(obj)); // directory not empty: not destroyed
1158 _NS.Destroy_Name(path.c_str());
1159 _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
1160 _NS.Change_Directory("/Containers/theHostName");
1164 // ============================================================================
1166 * DestroyFullDirectory is not recursive
1167 * Need Housekeeping of /Containers for further tests !
1169 // ============================================================================
1171 void NamingServiceTest::_destroyDirectoryRecurs(std::string path)
1173 std::string current = path;
1175 if (_NS.Change_Directory(path.c_str()))
1177 std::vector<std::string> subdirs = _NS.list_subdirs();
1178 for (int i=0; i<subdirs.size(); i++)
1180 std::string subpath=path + "/" +subdirs[i];
1181 _destroyDirectoryRecurs(subpath);
1183 if (_NS.Change_Directory(path.c_str()))
1185 _NS.Destroy_FullDirectory(path.c_str());
1191 NamingServiceTest::testDestroyFullDirectory()
1193 _NS.Destroy_FullDirectory("/Containers");
1194 CPPUNIT_ASSERT(_NS.Change_Directory("/Containers"));
1195 std::vector<std::string> subdirs = _NS.list_subdirs();
1196 CPPUNIT_ASSERT(subdirs.size() >0);
1197 _NS.list_directory_recurs();
1198 std::string path = "/Containers";
1199 _destroyDirectoryRecurs(path);
1200 CPPUNIT_ASSERT( ! _NS.Change_Directory("/Containers"));
1201 _NS.Change_Directory("/");
1203 _NS.list_directory_recurs();
1206 // ============================================================================
1210 // ============================================================================
1213 NamingServiceTest::testGetIorAddr()
1215 CORBA::String_var root = _NS.getIORaddr();
1216 CORBA::Object_var obj = _orb->string_to_object(root);
1217 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1220 // ============================================================================
1224 // ============================================================================
1227 // NamingServiceTest::()
1229 // CPPUNIT_ASSERT(0);