1 // Copyright (C) 2007-2014 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 "SALOME_LifeCycleCORBA.hxx"
28 #include "utilities.h"
37 // --- uncomment to have some traces on standard error
38 // (useful only when adding new tests...)
42 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
43 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
50 #define setenv Kernel_Utils::setenv
53 #define TRACEFILE "/tmp/traceUnitTest.log"
55 // ============================================================================
57 * a basic CORBA object implementation for use with namingService tests
59 // ============================================================================
61 NSTEST_echo_i::NSTEST_echo_i()
66 NSTEST_echo_i::NSTEST_echo_i(CORBA::Long num)
71 NSTEST_echo_i::~NSTEST_echo_i()
75 CORBA::Long NSTEST_echo_i::getId()
80 // ============================================================================
82 * a factory of CORBA objects for use with namingService tests
84 // ============================================================================
86 NSTEST_aFactory_i::NSTEST_aFactory_i()
91 NSTEST_aFactory_i::~NSTEST_aFactory_i()
95 NSTEST::echo_ptr NSTEST_aFactory_i::createInstance()
97 NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
99 NSTEST::echo_var anEchoRef = anEcho->_this();
100 anEcho->_remove_ref();
101 return anEchoRef._retn();
104 // ============================================================================
107 * - delete preexisting trace classes if any
108 * - set trace on file
109 * Get or initialize the orb
110 * Create a SALOME_NamingService instance
112 // ============================================================================
115 NamingServiceTest::setUp()
117 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
119 bp1->deleteInstance(bp1);
122 const char *theFileName = TRACEFILE;
124 std::string s = "file:";
128 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
130 std::ofstream traceFile;
131 // traceFile.open(theFileName, ios::out | ios::trunc);
132 traceFile.open(theFileName, std::ios::out | std::ios::app);
133 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
136 bp1 = LocalTraceBufferPool::instance();
139 // --- Get or initialize the orb
142 char* _argv[] = {(char*)""};
143 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
144 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
145 _orb = init(_argc , _argv ) ;
147 // --- Create a SALOME_NamingService instance
151 // --- Create an NSTEST::factory
153 CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
154 ASSERT(!CORBA::is_nil(obj));
155 _root_poa = PortableServer::POA::_narrow(obj);
156 _pman = _root_poa->the_POAManager();
157 _myFactory = new NSTEST_aFactory_i();
158 _myFactoryId = _root_poa->activate_object(_myFactory);
159 _factoryRef = _myFactory->_this();
161 _myFactory->_remove_ref();
165 // ============================================================================
167 * - delete trace classes
169 // ============================================================================
172 NamingServiceTest::tearDown()
175 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
177 bp1->deleteInstance(bp1);
180 // ============================================================================
182 * Test default constructor: must be followed by a call to init_orb(ORB)
184 // ============================================================================
187 NamingServiceTest::testConstructorDefault()
189 SALOME_NamingService NS;
190 //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
193 CORBA::String_var root = NS.getIORaddr();
194 CORBA::Object_var obj = _orb->string_to_object(root);
195 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
197 CosNaming::NamingContext_var rootContext =
198 CosNaming::NamingContext::_narrow(obj);
199 CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
202 // ============================================================================
204 * Test constructor with ORB parameter
206 // ============================================================================
209 NamingServiceTest::testConstructorOrb()
211 SALOME_NamingService NS(_orb);
212 CORBA::String_var root = NS.getIORaddr();
213 CORBA::Object_var obj = _orb->string_to_object(root);
214 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
216 CosNaming::NamingContext_var rootContext =
217 CosNaming::NamingContext::_narrow(obj);
218 CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
221 // ============================================================================
223 * Test Register and resolve of a single CORBA object with absolute pathname,
224 * without subdirectories
226 // ============================================================================
229 NamingServiceTest::testRegisterResolveAbsNoPath()
231 _NS.Register(_factoryRef,"/nstest_factory");
232 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
233 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
234 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
235 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
238 // ============================================================================
240 * Test Register and resolve of a single CORBA object with relative pathname,
241 * without subdirectories
243 // ============================================================================
246 NamingServiceTest::testRegisterResolveRelativeNoPath()
248 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
249 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
250 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
251 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
253 _NS.Create_Directory("/myContext");
254 _NS.Change_Directory("/myContext");
256 NSTEST::echo_var anEchoRef = myFactory->createInstance();
257 _NS.Register(anEchoRef,"echo_0");
259 obj = _NS.Resolve("echo_0");
260 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
261 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
262 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
263 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
265 obj = _NS.Resolve("/myContext/echo_0");
266 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
267 NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
268 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
269 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
272 // ============================================================================
274 * Test Register and resolve of a single CORBA object with absolute pathname,
277 // ============================================================================
280 NamingServiceTest::testRegisterResolveAbsWithPath()
282 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
283 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
284 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
285 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
287 NSTEST::echo_var anEchoRef = myFactory->createInstance();
288 _NS.Register(anEchoRef,"/nstest/echo_0");
290 obj = _NS.Resolve("/nstest/echo_0");
291 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
292 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
293 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
294 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRefa->getId());
296 NSTEST::echo_var anEchoRef1 = myFactory->createInstance();
297 _NS.Register(anEchoRef1,"/nstest2/rep2/rep3/echo_1");
298 CPPUNIT_ASSERT(anEchoRef->getId() != anEchoRef1->getId());
300 obj = _NS.Resolve("/nstest2/rep2/rep3/echo_1");
301 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
302 NSTEST::echo_var anEchoRef1a = NSTEST::echo::_narrow(obj);
303 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef1a));
304 CPPUNIT_ASSERT(anEchoRef1->getId() == anEchoRef1a->getId());
306 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
307 _NS.Register(anEchoRef2,"/nstest2/1/2/3/4/echo_1");
309 obj = _NS.Resolve("/nstest2/1/2/3/4/echo_1");
310 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
311 NSTEST::echo_var anEchoRef2a = NSTEST::echo::_narrow(obj);
312 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2a));
313 CPPUNIT_ASSERT(anEchoRef2->getId() == anEchoRef2a->getId());
316 // ============================================================================
318 * Test Register and resolve of a single CORBA object with relative pathname,
320 * Relative Path is changed to the created subdirectory when Register()
322 // ============================================================================
325 NamingServiceTest::testRegisterResolveRelativeWithPath()
327 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
328 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
329 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
330 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
331 _NS.Create_Directory("/myContext");
332 _NS.Change_Directory("/myContext");
334 NSTEST::echo_var anEchoRef = myFactory->createInstance();
335 _NS.Register(anEchoRef,"subdir/echo_0");
337 obj = _NS.Resolve("echo_0");
338 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
339 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
340 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
342 obj = _NS.Resolve("/myContext/subdir/echo_0");
343 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
344 NSTEST::echo_var anEchoRef3 = NSTEST::echo::_narrow(obj);
345 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef3));
346 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef3->getId());
348 _NS.Change_Directory("/myContext");
349 obj = _NS.Resolve("subdir/echo_0");
350 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
351 NSTEST::echo_var anEchoRef4 = NSTEST::echo::_narrow(obj);
352 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef4));
353 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef4->getId());
356 // ============================================================================
358 * Test resolve with a name not known
360 // ============================================================================
363 NamingServiceTest::testResolveBadName()
365 CORBA::Object_var obj = _NS.Resolve("/notRegisteredName");
366 CPPUNIT_ASSERT(CORBA::is_nil(obj));
368 obj = _NS.Resolve("/nstest/notRegisteredName");
369 CPPUNIT_ASSERT(CORBA::is_nil(obj));
371 obj = _NS.Resolve("/unknownPath/notRegisteredName");
372 CPPUNIT_ASSERT(CORBA::is_nil(obj));
374 obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName");
375 CPPUNIT_ASSERT(CORBA::is_nil(obj));
378 // ============================================================================
380 * Test resolve with a name not known, with a relative path
382 // ============================================================================
385 NamingServiceTest::testResolveBadNameRelative()
387 _NS.Create_Directory("/myContext");
388 _NS.Change_Directory("/myContext");
390 CORBA::Object_var obj = _NS.Resolve("notRegisteredName");
391 CPPUNIT_ASSERT(CORBA::is_nil(obj));
393 obj = _NS.Resolve("unknownPath/notRegisteredName");
394 CPPUNIT_ASSERT(CORBA::is_nil(obj));
396 obj = _NS.Resolve("anUnknown/ComplicatedPath/notRegisteredName");
397 CPPUNIT_ASSERT(CORBA::is_nil(obj));
400 // ============================================================================
402 * Test register and resolve multiple objects, test resolveFirst.
403 * Register a few objects in /nstestfirst/echo_n where n is the object id.
404 * Resolve all the objects.
405 * ResolveFirst /nstestfirst/echo must give /nstestfirst/echo_i, corresponding
406 * to the first object.
408 // ============================================================================
413 NamingServiceTest::testResolveFirst()
415 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
416 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
417 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
418 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
422 for (int i=0; i<NB_OBJS; i++)
424 NSTEST::echo_var anEchoRef = myFactory->createInstance();
425 ref[i] = anEchoRef->getId();
426 std::string name = "/nstestfirst/echo_";
428 sprintf(anum,"%d",ref[i]);
430 _NS.Register(anEchoRef,name.c_str());
433 for (int i=0; i<NB_OBJS; i++)
435 std::string name = "/nstestfirst/echo_";
437 sprintf(anum,"%d",ref[i]);
439 obj = _NS.Resolve(name.c_str());
440 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
441 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
442 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
443 CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
446 std::string name = "/nstestfirst/echo";
447 obj = _NS.ResolveFirst(name.c_str());
448 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
449 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
450 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
451 CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
454 // ============================================================================
456 * Test register and resolve multiple objects, test resolveFirst, relative path
457 * Register a few objects in /nstestfirstrel/echo_n where n is the object id.
458 * Resolve all the objects.
459 * ResolveFirst echo with a relative path /nstestfirstrel must give
460 * /nstestfirst/echo_i, corresponding to the first object.
462 // ============================================================================
465 NamingServiceTest::testResolveFirstRelative()
467 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
468 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
469 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
470 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
474 for (int i=0; i<NB_OBJS; i++)
476 NSTEST::echo_var anEchoRef = myFactory->createInstance();
477 ref[i] = anEchoRef->getId();
478 std::string name = "/nstestfirstrel/echo_";
480 sprintf(anum,"%d",ref[i]);
482 _NS.Register(anEchoRef,name.c_str());
485 for (int i=0; i<NB_OBJS; i++)
487 _NS.Change_Directory("/nstestfirstrel");
488 std::string name = "echo_";
490 sprintf(anum,"%d",ref[i]);
492 obj = _NS.Resolve(name.c_str());
493 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
494 NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
495 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
496 CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
499 _NS.Change_Directory("/nstestfirstrel");
500 std::string name = "echo";
501 obj = _NS.ResolveFirst(name.c_str());
502 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
505 // ============================================================================
507 * Test resolveFirst with unknown name
509 // ============================================================================
512 NamingServiceTest::testResolveFirstUnknown()
514 std::string name = "/notYeyRegistered";
515 CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
516 CPPUNIT_ASSERT(CORBA::is_nil(obj));
518 name = "/nstestfirst/notYeyRegistered";
519 obj = _NS.ResolveFirst(name.c_str());
520 CPPUNIT_ASSERT(CORBA::is_nil(obj));
522 name = "/rrr/sss/ttt/notYeyRegistered";
523 obj = _NS.ResolveFirst(name.c_str());
524 CPPUNIT_ASSERT(CORBA::is_nil(obj));
527 // ============================================================================
529 * Test resolveFirst with unknown name, relative Path
531 // ============================================================================
534 NamingServiceTest::testResolveFirstUnknownRelative()
536 _NS.Create_Directory("/myContext");
537 _NS.Change_Directory("/myContext");
539 std::string name = "RelnotYeyRegistered";
540 CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
541 CPPUNIT_ASSERT(CORBA::is_nil(obj));
543 name = "Relnstestfirst/notYeyRegistered";
544 obj = _NS.ResolveFirst(name.c_str());
545 CPPUNIT_ASSERT(CORBA::is_nil(obj));
547 name = "Relrrr/sss/ttt/notYeyRegistered";
548 obj = _NS.ResolveFirst(name.c_str());
549 CPPUNIT_ASSERT(CORBA::is_nil(obj));
552 // ============================================================================
554 * Test ResolveComponent works as specified
556 // ============================================================================
559 NamingServiceTest::testResolveComponentOK()
561 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
562 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
563 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
564 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
566 NSTEST::echo_var anEchoRef = myFactory->createInstance();
567 _NS.Register(anEchoRef,
568 "/Containers/theHostName/theContainerName/theComponentName");
570 obj = _NS.ResolveComponent("theHostName",
573 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
574 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
575 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
576 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
579 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
580 _NS.Register(anEchoRef2,
581 "/Containers/theHostName/theContainerName_2/theComponentName");
583 obj = _NS.ResolveComponent("theHostName",
587 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
588 NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
589 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
590 CPPUNIT_ASSERT(anEchoRefb->getId() == anEchoRef2->getId());
593 // ============================================================================
595 * Test ResolveComponent gives nil pointer if hostname is not given (empty)
597 // ============================================================================
600 NamingServiceTest::testResolveComponentEmptyHostname()
602 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
603 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
604 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
605 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
607 NSTEST::echo_var anEchoRef = myFactory->createInstance();
608 _NS.Register(anEchoRef,
609 "/Containers/theHostName/theContainerName/theComponentName");
611 obj = _NS.ResolveComponent("",
614 CPPUNIT_ASSERT(CORBA::is_nil(obj));
617 // ============================================================================
619 * Test ResolveComponent gives nil pointer if hostname is unknown
621 // ============================================================================
624 NamingServiceTest::testResolveComponentUnknownHostname()
626 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
627 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
628 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
629 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
631 NSTEST::echo_var anEchoRef = myFactory->createInstance();
632 _NS.Register(anEchoRef,
633 "/Containers/theHostName/theContainerName/theComponentName");
635 obj = _NS.ResolveComponent("anUnknownHostName",
638 CPPUNIT_ASSERT(CORBA::is_nil(obj));
641 // ============================================================================
643 * Test ResolveComponent when containerName is empty.
644 * check bad hostname gives nil pointer.
645 * If componentName registered on a container from hostname, a component
646 * reference is found (the first one).
647 * Else give nil pointer.
649 // ============================================================================
652 NamingServiceTest::testResolveComponentEmptyContainerName()
654 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
655 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
656 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
657 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
659 NSTEST::echo_var anEchoRef = myFactory->createInstance();
660 _NS.Register(anEchoRef,
661 "/Containers/theHostName/theContainerName/theComponentName");
663 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
664 _NS.Register(anEchoRef2,
665 "/Containers/theHostName/aContainerName/aComponentName");
667 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
668 _NS.Register(anEchoRef3,
669 "/Containers/theHostName/otherContainerName/theComponentName");
671 obj = _NS.ResolveComponent("anUnknownHostName",
674 CPPUNIT_ASSERT(CORBA::is_nil(obj));
676 obj = _NS.ResolveComponent("theHostName",
679 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
680 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
681 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
682 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef->getId());
685 // ============================================================================
689 // ============================================================================
692 NamingServiceTest::testResolveComponentUnknownContainerName()
694 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
695 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
696 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
697 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
699 NSTEST::echo_var anEchoRef = myFactory->createInstance();
700 _NS.Register(anEchoRef,
701 "/Containers/theHostName/theContainerName/theComponentName");
703 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
704 _NS.Register(anEchoRef2,
705 "/Containers/theHostName/aContainerName/aComponentName");
707 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
708 _NS.Register(anEchoRef3,
709 "/Containers/theHostName/otherContainerName/theComponentName");
711 obj = _NS.ResolveComponent("theHostName",
712 "anUnknownContainerName",
714 CPPUNIT_ASSERT(CORBA::is_nil(obj));
717 // ============================================================================
721 // ============================================================================
724 NamingServiceTest::testResolveComponentEmptyComponentName()
726 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
727 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
728 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
729 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
731 NSTEST::echo_var anEchoRef = myFactory->createInstance();
732 _NS.Register(anEchoRef,
733 "/Containers/theHostName/theContainerName/theComponentName");
735 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
736 _NS.Register(anEchoRef2,
737 "/Containers/theHostName/EmptyContainerName/");
739 obj = _NS.ResolveComponent("theHostName",
740 "EmptyContainerName",
742 CPPUNIT_ASSERT(CORBA::is_nil(obj));
745 // ============================================================================
749 // ============================================================================
752 NamingServiceTest::testResolveComponentUnknownComponentName()
754 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
755 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
756 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
757 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
759 NSTEST::echo_var anEchoRef = myFactory->createInstance();
760 _NS.Register(anEchoRef,
761 "/Containers/theHostName/theContainerName/theComponentName");
763 obj = _NS.ResolveComponent("theHostName",
765 "anUnknownComponentName");
766 CPPUNIT_ASSERT(CORBA::is_nil(obj));
769 // ============================================================================
771 * Test with a false number nbproc.
772 * A positive number not corresponding to a registered component gives nil ref.
773 * A negative number is not taken into account and may give a non nil ref.
775 // ============================================================================
778 NamingServiceTest::testResolveComponentFalseNbproc()
780 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
781 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
782 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
783 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
785 NSTEST::echo_var anEchoRef = myFactory->createInstance();
786 _NS.Register(anEchoRef,
787 "/Containers/theHostName/theContainerName/theComponentName");
789 obj = _NS.ResolveComponent("theHostName",
793 CPPUNIT_ASSERT(CORBA::is_nil(obj));
795 obj = _NS.ResolveComponent("theHostName",
799 CPPUNIT_ASSERT(! CORBA::is_nil(obj));
802 // ============================================================================
806 // ============================================================================
809 NamingServiceTest::testContainerName()
811 std::string ref0 = "FactoryServer";
812 std::string ret = _NS.ContainerName("");
813 CPPUNIT_ASSERT(ret == ref0);
815 ref0 = "MyContainerName";
816 ret = _NS.ContainerName(ref0.c_str());
817 CPPUNIT_ASSERT(ret == ref0);
820 // ============================================================================
824 // ============================================================================
827 NamingServiceTest::testContainerNameParams()
829 Engines::ContainerParameters params;
830 SALOME_LifeCycleCORBA::preSet(params);
832 std::string ref0 = "FactoryServer";
833 std::string ret = _NS.ContainerName(params);
834 CPPUNIT_ASSERT(ret == ref0);
836 ref0 = "MyContainerName";
837 params.container_name = ref0.c_str();
838 ret = _NS.ContainerName(params);
839 CPPUNIT_ASSERT(ret == ref0);
842 // ============================================================================
846 // ============================================================================
849 NamingServiceTest::testBuildContainerNameForNS()
851 std::string ref0 = "/Containers/theHostName/theContainerName";
852 std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
853 CPPUNIT_ASSERT(ret == ref0);
855 ref0 = "/Containers/theHostName/FactoryServer";
856 ret = _NS.BuildContainerNameForNS("","theHostName");
857 CPPUNIT_ASSERT(ret == ref0);
860 // ============================================================================
864 // ============================================================================
867 NamingServiceTest::testBuildContainerNameForNSParams()
869 Engines::ContainerParameters params;
870 SALOME_LifeCycleCORBA::preSet(params);
872 params.container_name = "theContainerName";
873 std::string ref0 = "/Containers/theHostName/theContainerName";
874 std::string ret = _NS.BuildContainerNameForNS(params,"theHostName");
875 CPPUNIT_ASSERT(ret == ref0);
877 params.container_name = "";
878 ref0 = "/Containers/theHostName/FactoryServer";
879 ret = _NS.BuildContainerNameForNS(params,"theHostName");
880 CPPUNIT_ASSERT(ret == ref0);
883 // ============================================================================
887 // ============================================================================
890 NamingServiceTest::testFind()
892 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
893 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
894 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
895 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
897 NSTEST::echo_var anEchoRef = myFactory->createInstance();
898 _NS.Register(anEchoRef,
899 "/Containers/theHostName/theContainerName/theComponentName");
901 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
902 _NS.Register(anEchoRef2,
903 "/Containers/theHostName/aContainerName/aComponentName");
905 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
906 _NS.Register(anEchoRef3,
907 "/Containers/theHostName/otherContainerName/theComponentName");
909 NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
910 _NS.Register(anEchoRef4,
911 "/Containers/anHostName/oneContainerName/theComponentName");
913 _NS.Change_Directory("/Containers");
914 int occ= _NS.Find("theComponentName");
915 CPPUNIT_ASSERT(occ >= 3); // see previous tests
917 _NS.Change_Directory("/Containers");
918 occ= _NS.Find("aComponentName");
919 CPPUNIT_ASSERT(occ == 1);
921 _NS.Change_Directory("/Containers");
922 occ= _NS.Find("UnknownCompnentName");
923 CPPUNIT_ASSERT(occ == 0);
926 // ============================================================================
930 // ============================================================================
933 NamingServiceTest::testCreateDirectory()
935 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
936 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
937 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
938 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
940 bool ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
943 _NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
944 NSTEST::echo_var anEchoRef = myFactory->createInstance();
945 int val = anEchoRef->getId();
946 std::string name = "echo_";
948 sprintf(anum,"%d",val);
950 _NS.Register(anEchoRef,name.c_str());
952 std::string dirname = "/aaa/bbb/ccc/ddd/eee/";
954 obj = _NS.Resolve(dirname.c_str());
955 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
956 NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
957 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
958 CPPUNIT_ASSERT(anEchoRef->getId() == anEchoRef2->getId());
960 ret = _NS.Create_Directory("/aaa/bbb/ccc/ddd/eee");
963 _NS.Change_Directory("/aaa/bbb");
964 ret = _NS.Create_Directory("cccccc/dddddd/eeeeee");
965 _NS.Register(anEchoRef,"echo_abcde");
968 _NS.Change_Directory("/aaa/bbb/cccccc/dddddd/eeeeee");
969 obj = _NS.Resolve("echo_abcde");
970 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
973 // ============================================================================
977 // ============================================================================
980 NamingServiceTest::testChangeDirectory()
982 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
983 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
984 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
985 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
987 NSTEST::echo_var anEchoRef = myFactory->createInstance();
988 _NS.Register(anEchoRef,
989 "/Containers/theHostName/theContainerName/theComponentName");
991 NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
992 _NS.Register(anEchoRef2,
993 "/Containers/theHostName/aContainerName/aComponentName");
995 NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
996 _NS.Register(anEchoRef3,
997 "/Containers/theHostName/otherContainerName/theComponentName");
999 NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
1000 _NS.Register(anEchoRef4,
1001 "/Containers/anHostName/oneContainerName/theComponentName");
1003 _NS.Change_Directory("/Containers/theHostName/otherContainerName");
1004 obj = _NS.Resolve("theComponentName");
1005 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1007 NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
1008 CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
1009 CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId());
1012 // ============================================================================
1016 // ============================================================================
1019 NamingServiceTest::testCurrentDirectory()
1021 std::string path = "/aaa/bbb/ccc/ddd/eee";
1022 bool ret = _NS.Create_Directory(path.c_str());
1023 CPPUNIT_ASSERT(ret);
1025 _NS.Change_Directory(path.c_str());
1026 char* acurdir = _NS.Current_Directory();
1027 std::string curdir = acurdir;
1029 CPPUNIT_ASSERT(curdir == path);
1032 // ============================================================================
1036 // ============================================================================
1039 NamingServiceTest::testList()
1041 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1043 _NS.Change_Directory("/Containers");
1047 // ============================================================================
1051 // ============================================================================
1054 NamingServiceTest::testListDirectory()
1056 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1057 _NS.list_directory();
1058 _NS.Change_Directory("/Containers");
1059 _NS.list_directory();
1062 // ============================================================================
1066 // ============================================================================
1069 NamingServiceTest::testListDirectoryRecurs()
1071 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1072 _NS.list_directory_recurs();
1073 _NS.Change_Directory("/Containers");
1074 _NS.list_directory_recurs();
1075 _NS.Change_Directory("/");
1076 _NS.list_directory_recurs();
1080 // ============================================================================
1084 // ============================================================================
1087 NamingServiceTest::testListSubdirs()
1089 _NS.Change_Directory("/Containers/theHostName/theContainerName");
1091 _NS.Change_Directory("/Containers");
1093 _NS.Change_Directory("/");
1096 // ============================================================================
1100 // ============================================================================
1103 NamingServiceTest::testDestroyName()
1105 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
1106 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1107 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
1108 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
1110 std::string path = "/Containers/theHostName/theContainerName/theComponentName";
1112 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1113 _NS.Register(anEchoRef, path.c_str());
1115 obj=_NS.Resolve(path.c_str());
1116 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1118 _NS.Destroy_Name(path.c_str());
1119 obj=_NS.Resolve(path.c_str());
1120 CPPUNIT_ASSERT(CORBA::is_nil(obj));
1123 // ============================================================================
1127 // ============================================================================
1130 NamingServiceTest::testDestroyDirectory()
1132 CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
1133 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1134 NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
1135 CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
1137 std::string path = "/Containers/theHostName/theContainerName/theComponentName";
1139 NSTEST::echo_var anEchoRef = myFactory->createInstance();
1140 _NS.Register(anEchoRef, path.c_str());
1142 _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
1143 obj=_NS.Resolve(path.c_str());
1144 CPPUNIT_ASSERT(!CORBA::is_nil(obj)); // directory not empty: not destroyed
1146 _NS.Destroy_Name(path.c_str());
1147 _NS.Destroy_Directory("/Containers/theHostName/theContainerName");
1148 _NS.Change_Directory("/Containers/theHostName");
1152 // ============================================================================
1154 * DestroyFullDirectory is not recursive
1155 * Need Housekeeping of /Containers for further tests !
1157 // ============================================================================
1159 void NamingServiceTest::_destroyDirectoryRecurs(std::string path)
1161 std::string current = path;
1163 if (_NS.Change_Directory(path.c_str()))
1165 std::vector<std::string> subdirs = _NS.list_subdirs();
1166 for (int i=0; i<subdirs.size(); i++)
1168 std::string subpath=path + "/" +subdirs[i];
1169 _destroyDirectoryRecurs(subpath);
1171 if (_NS.Change_Directory(path.c_str()))
1173 _NS.Destroy_FullDirectory(path.c_str());
1179 NamingServiceTest::testDestroyFullDirectory()
1181 _NS.Destroy_FullDirectory("/Containers");
1182 CPPUNIT_ASSERT(_NS.Change_Directory("/Containers"));
1183 std::vector<std::string> subdirs = _NS.list_subdirs();
1184 CPPUNIT_ASSERT(subdirs.size() >0);
1185 _NS.list_directory_recurs();
1186 std::string path = "/Containers";
1187 _destroyDirectoryRecurs(path);
1188 CPPUNIT_ASSERT( ! _NS.Change_Directory("/Containers"));
1189 _NS.Change_Directory("/");
1191 _NS.list_directory_recurs();
1194 // ============================================================================
1198 // ============================================================================
1201 NamingServiceTest::testGetIorAddr()
1203 CORBA::String_var root = _NS.getIORaddr();
1204 CORBA::Object_var obj = _orb->string_to_object(root);
1205 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
1208 // ============================================================================
1212 // ============================================================================
1215 // NamingServiceTest::()
1217 // CPPUNIT_ASSERT(0);