1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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"
27 #include "Basics_DirUtils.hxx"
28 #include "SALOME_LifeCycleCORBA.hxx"
29 #include "utilities.h"
38 // --- uncomment to have some traces on standard error
39 // (useful only when adding new tests...)
43 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
44 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
51 #define setenv Kernel_Utils::setenv
54 // ============================================================================
56 * a basic CORBA object implementation for use with namingService tests
58 // ============================================================================
60 NSTEST_echo_i::NSTEST_echo_i()
65 NSTEST_echo_i::NSTEST_echo_i(CORBA::Long num)
70 NSTEST_echo_i::~NSTEST_echo_i()
74 CORBA::Long NSTEST_echo_i::getId()
79 // ============================================================================
81 * a factory of CORBA objects for use with namingService tests
83 // ============================================================================
85 NSTEST_aFactory_i::NSTEST_aFactory_i()
90 NSTEST_aFactory_i::~NSTEST_aFactory_i()
94 NSTEST::echo_ptr NSTEST_aFactory_i::createInstance()
96 NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
98 NSTEST::echo_var anEchoRef = anEcho->_this();
99 anEcho->_remove_ref();
100 return anEchoRef._retn();
103 // ============================================================================
105 * Set Trace mechanism
106 * - delete preexisting trace classes if any
107 * - set trace on file
108 * Get or initialize the orb
109 * Create a SALOME_NamingService instance
111 // ============================================================================
114 NamingServiceTest::_getTraceFileName()
116 std::string dir = Kernel_Utils::GetTmpDir();
117 return dir + "traceUnitTest-NamingServiceTest.log";
121 NamingServiceTest::setUp()
123 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
125 bp1->deleteInstance(bp1);
128 std::string theFileName = _getTraceFileName();
130 std::string s = "file:";
134 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
136 std::ofstream traceFile;
137 // traceFile.open(theFileName, ios::out | ios::trunc);
138 traceFile.open(theFileName.c_str(), std::ios::out | std::ios::app);
139 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
142 bp1 = LocalTraceBufferPool::instance();
145 // --- Get or initialize the orb
148 char* _argv[] = {(char*)""};
149 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
150 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
151 _orb = init(_argc , _argv ) ;
153 // --- Create a SALOME_NamingService instance
157 // --- Create an NSTEST::factory
159 CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
160 ASSERT(!CORBA::is_nil(obj));
161 _root_poa = PortableServer::POA::_narrow(obj);
162 _pman = _root_poa->the_POAManager();
163 _myFactory = new NSTEST_aFactory_i();
164 _myFactoryId = _root_poa->activate_object(_myFactory);
165 _factoryRef = _myFactory->_this();
167 _myFactory->_remove_ref();
171 // ============================================================================
173 * - delete trace classes
175 // ============================================================================
178 NamingServiceTest::tearDown()
181 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
183 bp1->deleteInstance(bp1);
186 // ============================================================================
188 * Test default constructor: must be followed by a call to init_orb(ORB)
190 // ============================================================================
193 NamingServiceTest::testConstructorDefault()
195 SALOME_NamingService NS;
196 //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
199 CORBA::String_var root = NS.getIORaddr();
200 CORBA::Object_var obj = _orb->string_to_object(root);
201 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
203 CosNaming::NamingContext_var rootContext =
204 CosNaming::NamingContext::_narrow(obj);
205 CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
208 // ============================================================================
210 * Test constructor with ORB parameter
212 // ============================================================================
215 NamingServiceTest::testConstructorOrb()
217 SALOME_NamingService NS(_orb);
218 CORBA::String_var root = NS.getIORaddr();
219 CORBA::Object_var obj = _orb->string_to_object(root);
220 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
222 CosNaming::NamingContext_var rootContext =
223 CosNaming::NamingContext::_narrow(obj);
224 CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
227 // ============================================================================
229 * Test Register and resolve of a single CORBA object with absolute pathname,
230 * without subdirectories
232 // ============================================================================
235 NamingServiceTest::testRegisterResolveAbsNoPath()
237 _NS.Register(_factoryRef,"/nstest_factory");
238 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
239 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
240 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
241 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
244 // ============================================================================
246 * Test Register and resolve of a single CORBA object with relative pathname,
247 * without subdirectories
249 // ============================================================================
252 NamingServiceTest::testRegisterResolveRelativeNoPath()
254 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
255 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
256 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
257 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
259 _NS.Create_Directory("/myContext");
260 _NS.Change_Directory("/myContext");
262 NSTEST::echo_var anEchoRef = myFactory->createInstance();
263 _NS.Register(anEchoRef,"echo_0");
265 obj = _NS.Resolve("echo_0");
266 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
267 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
268 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
269 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
271 obj = _NS.Resolve("/myContext/echo_0");
272 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
273 NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
274 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
275 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
278 // ============================================================================
280 * Test Register and resolve of a single CORBA object with absolute pathname,
283 // ============================================================================
286 NamingServiceTest::testRegisterResolveAbsWithPath()
288 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
289 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
290 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
291 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
293 NSTEST::echo_var anEchoRef = myFactory->createInstance();
294 _NS.Register(anEchoRef,"/nstest/echo_0");
296 obj = _NS.Resolve("/nstest/echo_0");
297 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
298 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
299 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
300 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRefa->getId());
302 NSTEST::echo_var anEchoRef1 = myFactory->createInstance();
303 _NS.Register(anEchoRef1,"/nstest2/rep2/rep3/echo_1");
304 CPPUNIT_ASSERT(anEchoRef->getId() != anEchoRef1->getId());
306 obj = _NS.Resolve("/nstest2/rep2/rep3/echo_1");
307 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
308 NSTEST::echo_var anEchoRef1a = NSTEST::echo::_narrow(obj);
309 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef1a));
310 CPPUNIT_ASSERT(anEchoRef1->getId() == anEchoRef1a->getId());
312 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
313 _NS.Register(anEchoRef2,"/nstest2/1/2/3/4/echo_1");
315 obj = _NS.Resolve("/nstest2/1/2/3/4/echo_1");
316 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
317 NSTEST::echo_var anEchoRef2a = NSTEST::echo::_narrow(obj);
318 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2a));
319 CPPUNIT_ASSERT(anEchoRef2->getId() == anEchoRef2a->getId());
322 // ============================================================================
324 * Test Register and resolve of a single CORBA object with relative pathname,
326 * Relative Path is changed to the created subdirectory when Register()
328 // ============================================================================
331 NamingServiceTest::testRegisterResolveRelativeWithPath()
333 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
334 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
335 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
336 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
337 _NS.Create_Directory("/myContext");
338 _NS.Change_Directory("/myContext");
340 NSTEST::echo_var anEchoRef = myFactory->createInstance();
341 _NS.Register(anEchoRef,"subdir/echo_0");
343 obj = _NS.Resolve("echo_0");
344 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
345 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
346 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
348 obj = _NS.Resolve("/myContext/subdir/echo_0");
349 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
350 NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
351 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
352 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
354 _NS.Change_Directory("/myContext");
355 obj = _NS.Resolve("subdir/echo_0");
356 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
357 NSTEST::echo_var anEchoRef4 = NSTEST::echo::_narrow(obj);
358 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef4));
359 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef4->getId());
362 // ============================================================================
364 * Test resolve with a name not known
366 // ============================================================================
369 NamingServiceTest::testResolveBadName()
371 CORBA::Object_var obj = _NS.Resolve("/notRegisteredName");
372 CPPUNIT_ASSERT(CORBA::is_nil(obj));
374 obj = _NS.Resolve("/nstest/notRegisteredName");
375 CPPUNIT_ASSERT(CORBA::is_nil(obj));
377 obj = _NS.Resolve("/unknownPath/notRegisteredName");
378 CPPUNIT_ASSERT(CORBA::is_nil(obj));
380 obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName");
381 CPPUNIT_ASSERT(CORBA::is_nil(obj));
384 // ============================================================================
386 * Test resolve with a name not known, with a relative path
388 // ============================================================================
391 NamingServiceTest::testResolveBadNameRelative()
393 _NS.Create_Directory("/myContext");
394 _NS.Change_Directory("/myContext");
396 CORBA::Object_var obj = _NS.Resolve("notRegisteredName");
397 CPPUNIT_ASSERT(CORBA::is_nil(obj));
399 obj = _NS.Resolve("unknownPath/notRegisteredName");
400 CPPUNIT_ASSERT(CORBA::is_nil(obj));
402 obj = _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName");
403 CPPUNIT_ASSERT(CORBA::is_nil(obj));
406 // ============================================================================
408 * Test register and resolve multiple objects, test resolveFirst.
409 * Register a few objects in /nstestfirst/echo_n where n is the object id.
410 * Resolve all the objects.
411 * ResolveFirst /nstestfirst/echo must give /nstestfirst/echo_i, corresponding
412 * to the first object.
414 // ============================================================================
419 NamingServiceTest::testResolveFirst()
421 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
422 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
423 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
424 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
428 for (int i=0; i<NB_OBJS; i++)
430 NSTEST::echo_var anEchoRef = myFactory->createInstance();
431 ref[i] = anEchoRef->getId();
432 std::string name = "/nstestfirst/echo_";
434 sprintf(anum,"%d",ref[i]);
436 _NS.Register(anEchoRef,name.c_str());
439 for (int i=0; i<NB_OBJS; i++)
441 std::string name = "/nstestfirst/echo_";
443 sprintf(anum,"%d",ref[i]);
445 obj = _NS.Resolve(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[i]);
452 std::string name = "/nstestfirst/echo";
453 obj = _NS.ResolveFirst(name.c_str());
454 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
455 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
456 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
457 CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
460 // ============================================================================
462 * Test register and resolve multiple objects, test resolveFirst, relative path
463 * Register a few objects in /nstestfirstrel/echo_n where n is the object id.
464 * Resolve all the objects.
465 * ResolveFirst echo with a relative path /nstestfirstrel must give
466 * /nstestfirst/echo_i, corresponding to the first object.
468 // ============================================================================
471 NamingServiceTest::testResolveFirstRelative()
473 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
474 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
475 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
476 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
480 for (int i=0; i<NB_OBJS; i++)
482 NSTEST::echo_var anEchoRef = myFactory->createInstance();
483 ref[i] = anEchoRef->getId();
484 std::string name = "/nstestfirstrel/echo_";
486 sprintf(anum,"%d",ref[i]);
488 _NS.Register(anEchoRef,name.c_str());
491 for (int i=0; i<NB_OBJS; i++)
493 _NS.Change_Directory("/nstestfirstrel");
494 std::string name = "echo_";
496 sprintf(anum,"%d",ref[i]);
498 obj = _NS.Resolve(name.c_str());
499 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
500 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
501 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
502 CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
505 _NS.Change_Directory("/nstestfirstrel");
506 std::string name = "echo";
507 obj = _NS.ResolveFirst(name.c_str());
508 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
511 // ============================================================================
513 * Test resolveFirst with unknown name
515 // ============================================================================
518 NamingServiceTest::testResolveFirstUnknown()
520 std::string name = "/notYeyRegistered";
521 CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
522 CPPUNIT_ASSERT(CORBA::is_nil(obj));
524 name = "/nstestfirst/notYeyRegistered";
525 obj = _NS.ResolveFirst(name.c_str());
526 CPPUNIT_ASSERT(CORBA::is_nil(obj));
528 name = "/rrr/sss/ttt/notYeyRegistered";
529 obj = _NS.ResolveFirst(name.c_str());
530 CPPUNIT_ASSERT(CORBA::is_nil(obj));
533 // ============================================================================
535 * Test resolveFirst with unknown name, relative Path
537 // ============================================================================
540 NamingServiceTest::testResolveFirstUnknownRelative()
542 _NS.Create_Directory("/myContext");
543 _NS.Change_Directory("/myContext");
545 std::string name = "RelnotYeyRegistered";
546 CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
547 CPPUNIT_ASSERT(CORBA::is_nil(obj));
549 name = "Relnstestfirst/notYeyRegistered";
550 obj = _NS.ResolveFirst(name.c_str());
551 CPPUNIT_ASSERT(CORBA::is_nil(obj));
553 name = "Relrrr/sss/ttt/notYeyRegistered";
554 obj = _NS.ResolveFirst(name.c_str());
555 CPPUNIT_ASSERT(CORBA::is_nil(obj));
558 // ============================================================================
560 * Test ResolveComponent works as specified
562 // ============================================================================
565 NamingServiceTest::testResolveComponentOK()
567 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
568 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
569 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
570 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
572 NSTEST::echo_var anEchoRef = myFactory->createInstance();
573 _NS.Register(anEchoRef,
574 "/Containers/theHostName/theContainerName/theComponentName");
576 obj = _NS.ResolveComponent("theHostName",
579 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
580 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
581 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
582 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
585 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
586 _NS.Register(anEchoRef2,
587 "/Containers/theHostName/theContainerName_2/theComponentName");
589 obj = _NS.ResolveComponent("theHostName",
593 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
594 NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
595 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
596 CPPUNIT_ASSERT(anEchoRefb->getId() == anEchoRef2->getId());
599 // ============================================================================
601 * Test ResolveComponent gives nil pointer if hostname is not given (empty)
603 // ============================================================================
606 NamingServiceTest::testResolveComponentEmptyHostname()
608 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
609 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
610 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
611 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
613 NSTEST::echo_var anEchoRef = myFactory->createInstance();
614 _NS.Register(anEchoRef,
615 "/Containers/theHostName/theContainerName/theComponentName");
617 obj = _NS.ResolveComponent("",
620 CPPUNIT_ASSERT(CORBA::is_nil(obj));
623 // ============================================================================
625 * Test ResolveComponent gives nil pointer if hostname is unknown
627 // ============================================================================
630 NamingServiceTest::testResolveComponentUnknownHostname()
632 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
633 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
634 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
635 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
637 NSTEST::echo_var anEchoRef = myFactory->createInstance();
638 _NS.Register(anEchoRef,
639 "/Containers/theHostName/theContainerName/theComponentName");
641 obj = _NS.ResolveComponent("anUnknownHostName",
644 CPPUNIT_ASSERT(CORBA::is_nil(obj));
647 // ============================================================================
649 * Test ResolveComponent when containerName is empty.
650 * check bad hostname gives nil pointer.
651 * If componentName registered on a container from hostname, a component
652 * reference is found (the first one).
653 * Else give nil pointer.
655 // ============================================================================
658 NamingServiceTest::testResolveComponentEmptyContainerName()
660 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
661 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
662 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
663 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
665 NSTEST::echo_var anEchoRef = myFactory->createInstance();
666 _NS.Register(anEchoRef,
667 "/Containers/theHostName/theContainerName/theComponentName");
669 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
670 _NS.Register(anEchoRef2,
671 "/Containers/theHostName/aContainerName/aComponentName");
673 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
674 _NS.Register(anEchoRef3,
675 "/Containers/theHostName/otherContainerName/theComponentName");
677 obj = _NS.ResolveComponent("anUnknownHostName",
680 CPPUNIT_ASSERT(CORBA::is_nil(obj));
682 obj = _NS.ResolveComponent("theHostName",
685 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
686 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
687 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
688 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
691 // ============================================================================
695 // ============================================================================
698 NamingServiceTest::testResolveComponentUnknownContainerName()
700 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
701 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
702 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
703 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
705 NSTEST::echo_var anEchoRef = myFactory->createInstance();
706 _NS.Register(anEchoRef,
707 "/Containers/theHostName/theContainerName/theComponentName");
709 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
710 _NS.Register(anEchoRef2,
711 "/Containers/theHostName/aContainerName/aComponentName");
713 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
714 _NS.Register(anEchoRef3,
715 "/Containers/theHostName/otherContainerName/theComponentName");
717 obj = _NS.ResolveComponent("theHostName",
718 "anUnknownContainerName",
720 CPPUNIT_ASSERT(CORBA::is_nil(obj));
723 // ============================================================================
727 // ============================================================================
730 NamingServiceTest::testResolveComponentEmptyComponentName()
732 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
733 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
734 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
735 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
737 NSTEST::echo_var anEchoRef = myFactory->createInstance();
738 _NS.Register(anEchoRef,
739 "/Containers/theHostName/theContainerName/theComponentName");
741 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
742 _NS.Register(anEchoRef2,
743 "/Containers/theHostName/EmptyContainerName/");
745 obj = _NS.ResolveComponent("theHostName",
746 "EmptyContainerName",
748 CPPUNIT_ASSERT(CORBA::is_nil(obj));
751 // ============================================================================
755 // ============================================================================
758 NamingServiceTest::testResolveComponentUnknownComponentName()
760 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
761 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
762 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
763 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
765 NSTEST::echo_var anEchoRef = myFactory->createInstance();
766 _NS.Register(anEchoRef,
767 "/Containers/theHostName/theContainerName/theComponentName");
769 obj = _NS.ResolveComponent("theHostName",
771 "anUnknownComponentName");
772 CPPUNIT_ASSERT(CORBA::is_nil(obj));
775 // ============================================================================
777 * Test with a false number nbproc.
778 * A positive number not corresponding to a registered component gives nil ref.
779 * A negative number is not taken into account and may give a non nil ref.
781 // ============================================================================
784 NamingServiceTest::testResolveComponentFalseNbproc()
786 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
787 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
788 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
789 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
791 NSTEST::echo_var anEchoRef = myFactory->createInstance();
792 _NS.Register(anEchoRef,
793 "/Containers/theHostName/theContainerName/theComponentName");
795 obj = _NS.ResolveComponent("theHostName",
799 CPPUNIT_ASSERT(CORBA::is_nil(obj));
801 obj = _NS.ResolveComponent("theHostName",
805 CPPUNIT_ASSERT(! CORBA::is_nil(obj));
808 // ============================================================================
812 // ============================================================================
815 NamingServiceTest::testContainerName()
817 std::string ref0 = "FactoryServer";
818 std::string ret = SALOME_NamingService_Abstract::ContainerName("");
819 CPPUNIT_ASSERT(ret == ref0);
821 ref0 = "MyContainerName";
822 ret = SALOME_NamingService_Abstract::ContainerName(ref0.c_str());
823 CPPUNIT_ASSERT(ret == ref0);
826 // ============================================================================
830 // ============================================================================
833 NamingServiceTest::testContainerNameParams()
835 Engines::ContainerParameters params;
836 SALOME_LifeCycleCORBA::preSet(params);
838 std::string ref0 = "FactoryServer";
839 std::string ret = _NS.ContainerName(params);
840 CPPUNIT_ASSERT(ret == ref0);
842 ref0 = "MyContainerName";
843 params.container_name = ref0.c_str();
844 ret = _NS.ContainerName(params);
845 CPPUNIT_ASSERT(ret == ref0);
848 // ============================================================================
852 // ============================================================================
855 NamingServiceTest::testBuildContainerNameForNS()
857 std::string ref0 = "/Containers/theHostName/theContainerName";
858 std::string ret = SALOME_NamingService_Abstract::BuildContainerNameForNS("theContainerName","theHostName");
859 CPPUNIT_ASSERT(ret == ref0);
861 ref0 = "/Containers/theHostName/FactoryServer";
862 ret = SALOME_NamingService_Abstract::BuildContainerNameForNS("","theHostName");
863 CPPUNIT_ASSERT(ret == ref0);
866 // ============================================================================
870 // ============================================================================
873 NamingServiceTest::testBuildContainerNameForNSParams()
875 Engines::ContainerParameters params;
876 SALOME_LifeCycleCORBA::preSet(params);
878 params.container_name = "theContainerName";
879 std::string ref0 = "/Containers/theHostName/theContainerName";
880 std::string ret = _NS.BuildContainerNameForNS(params,"theHostName");
881 CPPUNIT_ASSERT(ret == ref0);
883 params.container_name = "";
884 ref0 = "/Containers/theHostName/FactoryServer";
885 ret = _NS.BuildContainerNameForNS(params,"theHostName");
886 CPPUNIT_ASSERT(ret == ref0);
889 // ============================================================================
893 // ============================================================================
896 NamingServiceTest::testFind()
898 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
899 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
900 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
901 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
903 NSTEST::echo_var anEchoRef = myFactory->createInstance();
904 _NS.Register(anEchoRef,
905 "/Containers/theHostName/theContainerName/theComponentName");
907 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
908 _NS.Register(anEchoRef2,
909 "/Containers/theHostName/aContainerName/aComponentName");
911 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
912 _NS.Register(anEchoRef3,
913 "/Containers/theHostName/otherContainerName/theComponentName");
915 NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
916 _NS.Register(anEchoRef4,
917 "/Containers/anHostName/oneContainerName/theComponentName");
919 _NS.Change_Directory("/Containers");
920 int occ= _NS.Find("theComponentName");
921 CPPUNIT_ASSERT(occ >= 3); // see previous tests
923 _NS.Change_Directory("/Containers");
924 occ= _NS.Find("aComponentName");
925 CPPUNIT_ASSERT(occ == 1);
927 _NS.Change_Directory("/Containers");
928 occ= _NS.Find("UnknownCompnentName");
929 CPPUNIT_ASSERT(occ == 0);
932 // ============================================================================
936 // ============================================================================
939 NamingServiceTest::testCreateDirectory()
941 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
942 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
943 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
944 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
946 bool ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
949 _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
950 NSTEST::echo_var anEchoRef = myFactory->createInstance();
951 int val = anEchoRef->getId();
952 std::string name = "echo_";
954 sprintf(anum,"%d",val);
956 _NS.Register(anEchoRef,name.c_str());
958 std::string dirname = "/aaa/bbb/ccc/ddd/eee/";
960 obj = _NS.Resolve(dirname.c_str());
961 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
962 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
963 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
964 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
966 ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
969 _NS.Change_Directory("/aaa/bbb");
970 ret = _NS.Create_Directory("cccccc/dddddd/eeeeee");
971 _NS.Register(anEchoRef,"echo_abcde");
974 _NS.Change_Directory("/aaa/bbb/cccccc/dddddd/eeeeee");
975 obj = _NS.Resolve("echo_abcde");
976 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
979 // ============================================================================
983 // ============================================================================
986 NamingServiceTest::testChangeDirectory()
988 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
989 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
990 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
991 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
993 NSTEST::echo_var anEchoRef = myFactory->createInstance();
994 _NS.Register(anEchoRef,
995 "/Containers/theHostName/theContainerName/theComponentName");
997 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
998 _NS.Register(anEchoRef2,
999 "/Containers/theHostName/aContainerName/aComponentName");
1001 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
1002 _NS.Register(anEchoRef3,
1003 "/Containers/theHostName/otherContainerName/theComponentName");
1005 NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
1006 _NS.Register(anEchoRef4,
1007 "/Containers/anHostName/oneContainerName/theComponentName");
1009 _NS.Change_Directory("/Containers/theHostName/otherContainerName");
1010 obj = _NS.Resolve("theComponentName");
1011 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1013 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
1014 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
1015 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId());
1018 // ============================================================================
1022 // ============================================================================
1025 NamingServiceTest::testCurrentDirectory()
1027 std::string path = "/aaa/bbb/ccc/ddd/eee";
1028 bool ret = _NS.Create_Directory(path.c_str());
1029 CPPUNIT_ASSERT(ret);
1031 _NS.Change_Directory(path.c_str());
1032 char* acurdir = _NS.Current_Directory();
1033 std::string curdir = acurdir;
1035 CPPUNIT_ASSERT(curdir == path);
1038 // ============================================================================
1042 // ============================================================================
1045 NamingServiceTest::testList()
1047 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1049 _NS.Change_Directory("/Containers");
1053 // ============================================================================
1057 // ============================================================================
1060 NamingServiceTest::testListDirectory()
1062 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1063 _NS.list_directory();
1064 _NS.Change_Directory("/Containers");
1065 _NS.list_directory();
1068 // ============================================================================
1072 // ============================================================================
1075 NamingServiceTest::testListDirectoryRecurs()
1077 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1078 _NS.list_directory_recurs();
1079 _NS.Change_Directory("/Containers");
1080 _NS.list_directory_recurs();
1081 _NS.Change_Directory("/");
1082 _NS.list_directory_recurs();
1086 // ============================================================================
1090 // ============================================================================
1093 NamingServiceTest::testListSubdirs()
1095 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1097 _NS.Change_Directory("/Containers");
1099 _NS.Change_Directory("/");
1102 // ============================================================================
1106 // ============================================================================
1109 NamingServiceTest::testDestroyName()
1111 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
1112 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1113 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
1114 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
1116 std::string path = "/Containers/theHostName/theContainerName/theComponentName";
1118 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1119 _NS.Register(anEchoRef, path.c_str());
1121 obj=_NS.Resolve(path.c_str());
1122 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1124 _NS.Destroy_Name(path.c_str());
1125 obj=_NS.Resolve(path.c_str());
1126 CPPUNIT_ASSERT(CORBA::is_nil(obj));
1129 // ============================================================================
1133 // ============================================================================
1136 NamingServiceTest::testDestroyDirectory()
1138 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
1139 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1140 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
1141 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
1143 std::string path = "/Containers/theHostName/theContainerName/theComponentName";
1145 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1146 _NS.Register(anEchoRef, path.c_str());
1148 _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
1149 obj=_NS.Resolve(path.c_str());
1150 CPPUNIT_ASSERT(!CORBA::is_nil(obj)); // directory not empty: not destroyed
1152 _NS.Destroy_Name(path.c_str());
1153 _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
1154 _NS.Change_Directory("/Containers/theHostName");
1158 // ============================================================================
1160 * DestroyFullDirectory is not recursive
1161 * Need Housekeeping of /Containers for further tests !
1163 // ============================================================================
1165 void NamingServiceTest::_destroyDirectoryRecurs(std::string path)
1167 std::string current = path;
1169 if (_NS.Change_Directory(path.c_str()))
1171 std::vector<std::string> subdirs = _NS.list_subdirs();
1172 for (size_t i=0; i<subdirs.size(); i++)
1174 std::string subpath=path + "/" +subdirs[i];
1175 _destroyDirectoryRecurs(subpath);
1177 if (_NS.Change_Directory(path.c_str()))
1179 _NS.Destroy_FullDirectory(path.c_str());
1185 NamingServiceTest::testDestroyFullDirectory()
1187 _NS.Destroy_FullDirectory("/Containers");
1188 CPPUNIT_ASSERT(_NS.Change_Directory("/Containers"));
1189 std::vector<std::string> subdirs = _NS.list_subdirs();
1190 CPPUNIT_ASSERT(subdirs.size() >0);
1191 _NS.list_directory_recurs();
1192 std::string path = "/Containers";
1193 _destroyDirectoryRecurs(path);
1194 CPPUNIT_ASSERT( ! _NS.Change_Directory("/Containers"));
1195 _NS.Change_Directory("/");
1197 _NS.list_directory_recurs();
1200 // ============================================================================
1204 // ============================================================================
1207 NamingServiceTest::testGetIorAddr()
1209 CORBA::String_var root = _NS.getIORaddr();
1210 CORBA::Object_var obj = _orb->string_to_object(root);
1211 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1214 // ============================================================================
1218 // ============================================================================
1221 // NamingServiceTest::()
1223 // CPPUNIT_ASSERT(0);