19 #ifndef CorbaNaming_cpp 20 #define CorbaNaming_cpp 22 #include <cppunit/ui/text/TestRunner.h> 23 #include <cppunit/TextOutputter.h> 24 #include <cppunit/extensions/TestFactoryRegistry.h> 25 #include <cppunit/extensions/HelperMacros.h> 26 #include <cppunit/TestAssert.h> 42 void activate(::PortableServer::ServantBase* servant)
46 m_poa->activate_object(servant);
48 catch(const ::PortableServer::POA::ServantAlreadyActive &)
54 ::PortableServer::POA_ptr
m_poa;
65 :
public CppUnit::TestFixture
68 CPPUNIT_TEST(test_resolveStr);
69 CPPUNIT_TEST(test_bindOrResolve);
70 CPPUNIT_TEST(test_bindOrResolveContext);
71 CPPUNIT_TEST(test_bind);
72 CPPUNIT_TEST(test_bindByString);
73 CPPUNIT_TEST(test_bindRecursive);
74 CPPUNIT_TEST(test_bind_already_bound);
75 CPPUNIT_TEST(test_rebind);
76 CPPUNIT_TEST(test_rebindByString);
77 CPPUNIT_TEST(tset_rebindRecursive);
78 CPPUNIT_TEST(test_bindContext);
79 CPPUNIT_TEST(test_bindContextRecursive);
80 CPPUNIT_TEST(test_rebindContext);
81 CPPUNIT_TEST(test_rebindContextRecursive);
82 CPPUNIT_TEST(test_unbind);
83 CPPUNIT_TEST(test_bindNewContext);
84 CPPUNIT_TEST(test_destroyRecursive);
85 CPPUNIT_TEST_SUITE_END();
91 CORBA::Object_ptr context
92 = CosNaming::NamingContext::_duplicate(m_pNaming->getRootContext());
94 CosNaming::Name name = m_pNaming->toName(fullName);
96 CORBA::ULong len(name.length());
97 for (CORBA::ULong i = 0; i < len; ++i)
99 if (m_pNaming->isNamingContext(context))
101 CosNaming::NamingContext_var nc
102 = CosNaming::NamingContext::_narrow(context);
103 CPPUNIT_ASSERT(! CORBA::is_nil(nc));
105 CosNaming::Name subName = m_pNaming->subName(name, i, i);
107 CORBA::Object_ptr resolvedObj = nc->resolve(subName);
109 context = resolvedObj;
118 CosNaming::NamingContext_var nc
119 = CosNaming::NamingContext::_narrow(context);
121 throw CosNaming::NamingContext::CannotProceed(
122 nc, m_pNaming->subName(name, i));
129 CORBA::ULong len(name.length());
130 for (CORBA::ULong i = 0; i < len; i++)
132 std::cout << name[i].id <<
"." << name[i].kind;
138 std::cout << std::endl;
169 m_pORB = CORBA::ORB_init(argc, argv);
170 m_pPOA = PortableServer::POA::_narrow(
171 m_pORB->resolve_initial_references(
"RootPOA"));
172 m_pPOA->the_POAManager()->activate();
175 m_pNaming->
init(
"localhost:2809");
184 if (m_pNaming != NULL)
delete m_pNaming;
194 std::string set_name(
"corbaloc::localhost:2809/NameService");
195 m_pNaming->
init(
"localhost:2809");
199 CPPUNIT_ASSERT_EQUAL(set_name, get_name);
201 CosNaming::Name name;
204 name[0].kind =
"kind";
206 std::string str(m_pNaming->
toString(name));
207 CPPUNIT_ASSERT(
"id.kind" == str);
214 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
218 CORBA::Object_ptr obj = m_pNaming->
resolveStr(
"id.kind");
219 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
236 CPPUNIT_ASSERT(! CORBA::is_nil(rto0->
getObjRef()));
238 const char* fullName0 =
"id0-lv0.kind0-lv0/id0-lv1.kind0-lv1";
240 CORBA::Object_ptr
obj0 = resolveRecursive(
"id0-lv0.kind0-lv0");
241 CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0);
242 CPPUNIT_ASSERT(! CORBA::is_nil(nc0));
247 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
250 const char* fullName =
"lv1-id.lv1-kind";
251 CORBA::Object_ptr obj1 = m_pNaming->
bindOrResolve(nc0._retn(),
253 CORBA::Object_ptr obj = resolveRecursive(
"id0-lv0.kind0-lv0/lv1-id.lv1-kind");
254 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
272 CPPUNIT_ASSERT(! CORBA::is_nil(rto0->
getObjRef()));
274 const char* fullName0 =
"id0-lv0.kind0-lv0/id0-lv1.kind0-lv1";
276 CORBA::Object_ptr
obj0 = resolveRecursive(
"id0-lv0.kind0-lv0");
277 CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0);
278 CPPUNIT_ASSERT(! CORBA::is_nil(nc0));
283 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
286 const char* fullName =
"lv1-id.lv1-kind";
288 m_pNaming->
toName(fullName) );
289 CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
293 CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
311 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
314 const char* fullName =
"lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
316 CORBA::Object_ptr obj = resolveRecursive(fullName);
317 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
334 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
337 const char* fullName =
"lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
339 CORBA::Object_ptr obj = resolveRecursive(fullName);
340 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
356 CPPUNIT_ASSERT(! CORBA::is_nil(rto0->
getObjRef()));
358 const char* fullName0 =
"id0-lv0.kind0-lv0/id0-lv1.kind0-lv1";
361 CORBA::Object_ptr
obj0 = resolveRecursive(
"id0-lv0.kind0-lv0");
362 CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0);
363 CPPUNIT_ASSERT(! CORBA::is_nil(nc0));
368 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
371 const char* fullName =
"lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
373 CORBA::Object_ptr obj = resolveRecursive(
"id0-lv0.kind0-lv0/lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind");
374 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
391 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
394 const char* fullName =
"lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
396 CORBA::Object_ptr obj = resolveRecursive(fullName);
397 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
403 CPPUNIT_FAIL(
"Expected exception not thrown.");
405 catch (CosNaming::NamingContext::AlreadyBound expected) {}
421 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->
getObjRef()));
424 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
427 const char* fullName =
"lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
429 CORBA::Object_ptr obj1 = resolveRecursive(fullName);
430 CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this()));
434 CORBA::Object_ptr obj2 = resolveRecursive(fullName);
435 CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this()));
452 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->
getObjRef()));
455 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
458 const char* fullName =
"lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
460 CORBA::Object_ptr obj1 = resolveRecursive(fullName);
461 CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this()));
465 CORBA::Object_ptr obj2 = resolveRecursive(fullName);
466 CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this()));
481 CosNaming::NamingContext_ptr ncParent = m_pNaming->
newContext();
482 CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
484 m_pNaming->
bindContext(
"id-parent.kind-parent", ncParent);
485 CORBA::Object_ptr objParent = resolveRecursive(
"id-parent.kind-parent");
486 CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent));
491 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
495 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
499 ncParent, m_pNaming->
toName(
"id-rto.kind-rto"), rto1->getObjRef());
500 CORBA::Object_ptr objRto1 = resolveRecursive(
501 "id-parent.kind-parent/id-rto.kind-rto");
502 CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef()));
507 CORBA::Object_ptr objRto2 = resolveRecursive(
508 "id-parent.kind-parent/id-rto.kind-rto");
509 CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->
getObjRef()));
526 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
529 CosNaming::NamingContext_ptr nc = m_pNaming->
newContext();
530 CPPUNIT_ASSERT(! CORBA::is_nil(nc));
535 m_pNaming->
bindContext(
"id-lv0.kind-lv0/id-lv1.kind-lv1", nc);
537 CORBA::Object_ptr objNc = resolveRecursive(
"id-lv0.kind-lv0/id-lv1.kind-lv1");
538 CPPUNIT_ASSERT(objNc->_is_equivalent(nc));
540 CORBA::Object_ptr objRto = resolveRecursive(
"id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind");
541 CPPUNIT_ASSERT(objRto->_is_equivalent(rto->
getObjRef()));
555 CosNaming::NamingContext_ptr ncParent = m_pNaming->
newContext();
556 CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
558 m_pNaming->
bindContext(
"id-parent.kind-parent", ncParent);
559 CORBA::Object_ptr objParent = resolveRecursive(
"id-parent.kind-parent");
560 CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent));
565 CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
567 CosNaming::NamingContext_ptr nc = m_pNaming->
newContext();
568 CPPUNIT_ASSERT(! CORBA::is_nil(nc));
569 nc->bind(m_pNaming->
toName(
"id.kind"), rto->getObjRef());
573 ncParent, m_pNaming->
toName(
"id-lv0.kind-lv0/id-lv1.kind-lv1"), nc);
575 CORBA::Object_ptr objNc = resolveRecursive(
576 "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1");
577 CPPUNIT_ASSERT(objNc->_is_equivalent(nc));
579 CORBA::Object_ptr objRto = resolveRecursive(
580 "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind");
581 CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef()));
598 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->
getObjRef()));
602 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
604 CosNaming::NamingContext_ptr nc1 = m_pNaming->
newContext();
605 CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
608 CosNaming::NamingContext_ptr nc2 = m_pNaming->
newContext();
609 CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
614 CORBA::Object_ptr objRto1 = resolveRecursive(
"id-nc.kind-nc/id-rto.kind-rto");
615 CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->
getObjRef()));
619 CORBA::Object_ptr objRto2 = resolveRecursive(
"id-nc.kind-nc/id-rto.kind-rto");
620 CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->
getObjRef()));
635 CosNaming::NamingContext_ptr ncParent = m_pNaming->
newContext();
636 CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
638 m_pNaming->
bindContext(
"id-parent.kind-parent", ncParent);
639 CORBA::Object_ptr objParent = resolveRecursive(
"id-parent.kind-parent");
640 CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent));
645 CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
649 CPPUNIT_ASSERT(! CORBA::is_nil(rto2->
getObjRef()));
651 CosNaming::NamingContext_ptr nc1 = m_pNaming->
newContext();
652 CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
653 nc1->bind(m_pNaming->
toName(
"id-rto.kind-rto"), rto1->getObjRef());
655 CosNaming::NamingContext_ptr nc2 = m_pNaming->
newContext();
656 CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
661 ncParent, m_pNaming->
toName(
"id-nc.kind-nc"), nc1);
662 CORBA::Object_ptr objRto1 = resolveRecursive(
663 "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto");
664 CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef()));
668 ncParent, m_pNaming->
toName(
"id-nc.kind-nc"), nc2);
669 CORBA::Object_ptr objRto2 = resolveRecursive(
670 "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto");
671 CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->
getObjRef()));
694 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
698 CORBA::Object_ptr obj = m_pNaming->
resolve(
"id.kind");
699 CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
702 m_pNaming->
unbind(
"id.kind");
708 CPPUNIT_FAIL(
"Expected exception not thrown.");
710 catch (CosNaming::NamingContext::NotFound expected)
716 CPPUNIT_FAIL(
"Unexpected exception catched.");
734 CPPUNIT_ASSERT(! CORBA::is_nil(rto->
getObjRef()));
737 CosNaming::NamingContext_ptr nc
739 CPPUNIT_ASSERT(! CORBA::is_nil(nc));
743 CORBA::Object_ptr obj = resolveRecursive(
"id-lv0.kind-lv0/id.kind");
744 CPPUNIT_ASSERT(! CORBA::is_nil(obj));
760 CosNaming::NamingContext_ptr ncParent = m_pNaming->
newContext();
761 CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
763 m_pNaming->
bindContext(
"id-parent.kind-parent", ncParent);
764 CORBA::Object_ptr objNcParent = resolveRecursive(
"id-parent.kind-parent");
765 CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent));
768 CosNaming::NamingContext_ptr nc1 = m_pNaming->
newContext();
769 CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
772 CORBA::Object_ptr objNc1 = resolveRecursive(
"id-parent.kind-parent/id1.kind1");
773 CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1));
776 CosNaming::NamingContext_ptr nc2 = m_pNaming->
newContext();
777 CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
780 CORBA::Object_ptr objNc2 = resolveRecursive(
"id-parent.kind-parent/id2.kind2");
781 CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2));
864 int main(
int argc,
char* argv[])
877 std::string arg(argv[i]);
878 std::string next_arg;
879 if (i + 1 < argc) next_arg = argv[i + 1];
882 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
895 ofs.open(fname.c_str());
897 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
898 if ( arg ==
"--cerr" ) { target = 1;
break; }
899 if ( arg ==
"--xsl" )
901 if (next_arg ==
"") xsl =
"default.xsl";
904 if ( arg ==
"--namespace" )
908 std::cerr <<
"no namespace specified" << std::endl;
918 CppUnit::TextUi::TestRunner runner;
920 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
922 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
923 CppUnit::Outputter* outputter = 0;
924 std::ostream* stream = target ? &std::cerr : &std::cout;
928 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
931 std::cout <<
"XML_OUT" << std::endl;
932 outputter =
new CppUnit::XmlOutputter(&runner.result(),
934 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
937 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
940 runner.setOutputter(outputter);
945 #endif // CorbaNaming_cpp int main(int argc, char **argv)
void test_bindByString()
bindByString()メソッドのテスト
void destroyRecursive(CosNaming::NamingContext_ptr context)
Destroy the naming context recursively.
CORBA::Object_ptr resolveStr(const char *string_name)
Resolve from name of string representation and get object.
void test_rebind()
rebind()メソッドのテスト
void rebindRecursive(CosNaming::NamingContext_ptr context, const CosNaming::Name &name, CORBA::Object_ptr obj)
Bind intermediate context recursively and rebind object.
void test_rebindContext()
rebindContext()メソッドのテスト
CosNaming::NamingContext_ptr bindNewContext(const CosNaming::Name &name, bool force=true)
Bind new NamingContext.
void test_rebindContextRecursive()
rebindContextRecursive()メソッドのテスト
const char * getNameServer()
Get the name of name server.
void rebind(const CosNaming::Name &name, CORBA::Object_ptr obj, const bool force=1)
Rebind object.
obj0
Manager::create_component(in string module_name);.
void test_bind_already_bound()
bind()メソッドのテスト
CosNaming::NamingContext_ptr getRootContext()
Get the root context.
CORBA::Object_ptr resolve(const CosNaming::Name &name)
Return object bound on the specified NameComponent.
CorbaNamingTests()
Constructor.
void bindContextRecursive(CosNaming::NamingContext_ptr context, const CosNaming::Name &name, CosNaming::NamingContext_ptr name_cxt)
Bind intermediate context recursively and bind NamingContext.
void bindByString(const char *string_name, CORBA::Object_ptr obj, const bool force=1)
Bind object on specified string name position.
void test_destroyRecursive()
void test_bind()
bind()メソッドのテスト
CORBA::Object_ptr resolveRecursive(const char *fullName)
::PortableServer::POA_ptr m_poa
CORBA Naming Service helper class.
void unbind(const CosNaming::Name &name)
Unbind a binding specified by NameComponent.
void tset_rebindRecursive()
rebindRecursive()メソッドのテスト
RTC::CorbaNaming * m_pNaming
CORBA naming service helper class.
void rebindContextRecursive(CosNaming::NamingContext_ptr context, const CosNaming::Name &name, CosNaming::NamingContext_ptr name_cxt)
Rebind intermediate context recursively and rebind NamingContext.
void init(const char *name_server)
Initialize the Naming Service.
void bindContext(const CosNaming::Name &name, CosNaming::NamingContext_ptr name_cxt, const bool force=1)
Bind NamingContext.
CosNaming::NamingContext_ptr newContext()
Create new NamingContext.
void bind(const CosNaming::Name &name, CORBA::Object_ptr obj, const bool force=1)
Bind object on specified name component position.
CosNaming::Name toName(const char *string_name)
Resolve given string representation to NameComponent.
void test_bindContext()
bindContext()メソッドのテスト
void test_resolveStr()
getNameServer(), toString(), toUrl(), resolveStr()メソッドのテスト
void test_bindOrResolveContext()
bindOrResolveContext()メソッドのテスト
CosNaming::NamingContext_ptr bindOrResolveContext(CosNaming::NamingContext_ptr context, const CosNaming::Name &name, CosNaming::NamingContext_ptr new_context)
Bind or resolve the given name component.
PortableServer::POA_ptr m_pPOA
void test_bindOrResolve()
bindOrResolve()メソッドのテスト
void bindRecursive(CosNaming::NamingContext_ptr context, const CosNaming::Name &name, CORBA::Object_ptr obj)
Bind intermediate context recursively and bind object.
virtual void tearDown()
Test finalization.
void test_bindNewContext()
bindNewContext()メソッドのテスト
void test_bindRecursive()
bindRecursive()メソッドのテスト
CORBA::Object_ptr bindOrResolve(CosNaming::NamingContext_ptr context, const CosNaming::Name &name, CORBA::Object_ptr obj)
Bind or resolve the given name component.
void test_unbind()
unbind()メソッドのテスト
void test_rebindByString()
rebindByString()メソッドのテスト
CorbaObjectManager(::CORBA::ORB_ptr orb,::PortableServer::POA_ptr poa)
char * toString(const CosNaming::Name &name)
Get string representation of given NameComponent.
void test_bindContextRecursive()
bindContextRecursive()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests)
void printName(CosNaming::Name name)
void activate(::PortableServer::ServantBase *servant)
void rebindContext(const CosNaming::Name &name, CosNaming::NamingContext_ptr name_cxt, const bool force=1)
Rebind NamingContext.
virtual ~CorbaNamingTests()
Destructor.
void clearAll()
Destroy all bindings.
virtual void setUp()
Test initialization.
RTObject_ptr getObjRef() const
[local interface] Get the object reference
void rebindByString(const char *string_name, CORBA::Object_ptr obj, const bool force=1)
Rebind Object.