CorbaNamingTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
11 /*
12  * $Log: CorbaNamingTests.cpp,v $
13  * Revision 1.1 2008/04/29 09:54:28 arafune
14  * The first commitment.
15  *
16  *
17  */
18 
19 #ifndef CorbaNaming_cpp
20 #define CorbaNaming_cpp
21 
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>
27 
28 #include <rtm/RTC.h>
29 #include <rtm/RTObject.h>
30 #include <rtm/CorbaNaming.h>
31 
32 namespace RTC
33 {
35  {
36  public:
37  CorbaObjectManager(::CORBA::ORB_ptr orb, ::PortableServer::POA_ptr poa)
38  : m_orb(orb), m_poa(poa)
39  {
40  }
41 
42  void activate(::PortableServer::ServantBase* servant)
43  {
44  try
45  {
46  m_poa->activate_object(servant);
47  }
48  catch(const ::PortableServer::POA::ServantAlreadyActive &)
49  {
50  }
51  }
52  protected:
53  ::CORBA::ORB_ptr m_orb;
54  ::PortableServer::POA_ptr m_poa;
55  };
56 };
57 
62 namespace CorbaNaming
63 {
65  : public CppUnit::TestFixture
66  {
67  CPPUNIT_TEST_SUITE(CorbaNamingTests);
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();
86 
87  private:
88  // helper
89  CORBA::Object_ptr resolveRecursive(const char* fullName)
90  {
91  CORBA::Object_ptr context
92  = CosNaming::NamingContext::_duplicate(m_pNaming->getRootContext());
93 
94  CosNaming::Name name = m_pNaming->toName(fullName);
95 
96  CORBA::ULong len(name.length());
97  for (CORBA::ULong i = 0; i < len; ++i)
98  {
99  if (m_pNaming->isNamingContext(context))
100  {
101  CosNaming::NamingContext_var nc
102  = CosNaming::NamingContext::_narrow(context);
103  CPPUNIT_ASSERT(! CORBA::is_nil(nc));
104 
105  CosNaming::Name subName = m_pNaming->subName(name, i, i);
106 
107  CORBA::Object_ptr resolvedObj = nc->resolve(subName);
108 
109  context = resolvedObj;
110 
111  if (i == len - 1)
112  {
113  return context;
114  }
115  }
116  else
117  {
118  CosNaming::NamingContext_var nc
119  = CosNaming::NamingContext::_narrow(context);
120 
121  throw CosNaming::NamingContext::CannotProceed(
122  nc, m_pNaming->subName(name, i));
123  }
124  }
125  }
126 
127  void printName(CosNaming::Name name)
128  {
129  CORBA::ULong len(name.length());
130  for (CORBA::ULong i = 0; i < len; i++)
131  {
132  std::cout << name[i].id << "." << name[i].kind;
133  if (i < len - 1)
134  {
135  std::cout << "/";
136  }
137  }
138  std::cout << std::endl;
139  }
140 
141  private:
142  CORBA::ORB_ptr m_pORB;
143  PortableServer::POA_ptr m_pPOA;
145 
146  public:
151  {
152  }
153 
158  {
159  }
160 
164  virtual void setUp()
165  {
166  int argc(0);
167  char** argv(NULL);
168 
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();
173  m_pNaming = new RTC::CorbaNaming(m_pORB);
174 
175  m_pNaming->init("localhost:2809");
176  m_pNaming->clearAll();
177  }
178 
182  virtual void tearDown()
183  {
184  if (m_pNaming != NULL) delete m_pNaming;
185  }
186 
193  {
194  std::string set_name("corbaloc::localhost:2809/NameService");
195  m_pNaming->init("localhost:2809");
196 
197  // ネームサーバの名前を正しく取得できるか
198  std::string get_name(m_pNaming->getNameServer());
199  CPPUNIT_ASSERT_EQUAL(set_name, get_name);
200 
201  CosNaming::Name name;
202  name.length(1);
203  name[0].id = "id";
204  name[0].kind = "kind";
205  // 与えられた NameComponent の文字列表現を正しく返すか
206  std::string str(m_pNaming->toString(name));
207  CPPUNIT_ASSERT("id.kind" == str);
208 
209 // std::string url(m_pNaming->toUrl("", "" ));
210 
211  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
212  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
213  objMgr.activate(rto);
214  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
215  m_pNaming->bindByString("id.kind", rto->getObjRef());
216 
217  // 与えられた文字列表現を resolve しオブジェクトを返すか
218  CORBA::Object_ptr obj = m_pNaming->resolveStr("id.kind");
219  CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
220 
221  rto->_remove_ref();
222  }
223 
230  {
231  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
232 
233  // バインド先となるコンテキストを登録しておく
234  RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA);
235  objMgr.activate(rto0);
236  CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef()));
237 
238  const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1";
239  m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef());
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));
243 
244  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind"; CORBA::Object_ptr obj1 = m_pNaming->bindOrResolve(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bindOrResolveContext()メソッドのテスト * * - 名前をバインドまたは解決できるか */ void test_bindOrResolveContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto0); CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef())); const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1"; m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef()); CORBA::Object_ptr obj0 = resolveRecursive("id0-lv0.kind0-lv0"); CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0); CPPUNIT_ASSERT(! CORBA::is_nil(nc0)); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind"; CosNaming::NamingContext_var nc1 = m_pNaming->bindOrResolveContext(nc0._retn(), m_pNaming->toName(fullName) ); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); CosNaming::NamingContext_var nc2 = m_pNaming->bindOrResolveContext(nc1._retn(), m_pNaming->toName(fullName), m_pNaming->newContext() ); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindByString()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindByString(fullName, rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindRecursive()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto0); CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef())); const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1"; m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef()); CORBA::Object_ptr obj0 = resolveRecursive("id0-lv0.kind0-lv0"); CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0); CPPUNIT_ASSERT(! CORBA::is_nil(nc0)); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindRecursive(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? */ void test_bind_already_bound() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? try { m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::AlreadyBound expected) {} rto->_remove_ref(); } /*! * @brief rebind()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
245  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
246  objMgr.activate(rto);
247  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
248 
249  // オブジェクトをバインドし、それが正しく設定されるか?
250  const char* fullName = "lv1-id.lv1-kind";
251  CORBA::Object_ptr obj1 = m_pNaming->bindOrResolve(nc0._retn(),
252  m_pNaming->toName(fullName), rto->getObjRef());
253  CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind");
254  CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
255 
256  rto->_remove_ref();
257  rto0->_remove_ref();
258  }
259 
266  {
267  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
268 
269  // バインド先となるコンテキストを登録しておく
270  RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA);
271  objMgr.activate(rto0);
272  CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef()));
273 
274  const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1";
275  m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef());
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));
279 
280  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind"; CosNaming::NamingContext_var nc1 = m_pNaming->bindOrResolveContext(nc0._retn(), m_pNaming->toName(fullName) ); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); CosNaming::NamingContext_var nc2 = m_pNaming->bindOrResolveContext(nc1._retn(), m_pNaming->toName(fullName), m_pNaming->newContext() ); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindByString()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindByString(fullName, rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindRecursive()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto0); CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef())); const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1"; m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef()); CORBA::Object_ptr obj0 = resolveRecursive("id0-lv0.kind0-lv0"); CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0); CPPUNIT_ASSERT(! CORBA::is_nil(nc0)); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindRecursive(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? */ void test_bind_already_bound() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? try { m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::AlreadyBound expected) {} rto->_remove_ref(); } /*! * @brief rebind()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
281  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
282  objMgr.activate(rto);
283  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
284 
285  // オブジェクトをバインドし、それが正しく設定されるか?
286  const char* fullName = "lv1-id.lv1-kind";
287  CosNaming::NamingContext_var nc1 = m_pNaming->bindOrResolveContext(nc0._retn(),
288  m_pNaming->toName(fullName) );
289  CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
290 
291  CosNaming::NamingContext_var nc2 = m_pNaming->bindOrResolveContext(nc1._retn(),
292  m_pNaming->toName(fullName), m_pNaming->newContext() );
293  CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
294 
295  rto->_remove_ref();
296  rto0->_remove_ref();
297  }
298 
304  void test_bind()
305  {
306  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
307 
308  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindByString()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindByString(fullName, rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindRecursive()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto0); CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef())); const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1"; m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef()); CORBA::Object_ptr obj0 = resolveRecursive("id0-lv0.kind0-lv0"); CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0); CPPUNIT_ASSERT(! CORBA::is_nil(nc0)); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindRecursive(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? */ void test_bind_already_bound() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? try { m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::AlreadyBound expected) {} rto->_remove_ref(); } /*! * @brief rebind()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
309  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
310  objMgr.activate(rto);
311  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
312 
313  // オブジェクトをバインドし、それが正しく設定されるか?
314  const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
315  m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef());
316  CORBA::Object_ptr obj = resolveRecursive(fullName);
317  CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
318  rto->_remove_ref();
319  }
320 
327  {
328 
329  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
330 
331  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindByString(fullName, rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); } /*! * @brief bindRecursive()メソッドのテスト * * - オブジェクトをバインドし、それが正しく設定されるか? */ void test_bindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto0); CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef())); const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1"; m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef()); CORBA::Object_ptr obj0 = resolveRecursive("id0-lv0.kind0-lv0"); CosNaming::NamingContext_var nc0 = CosNaming::NamingContextExt::_narrow(obj0); CPPUNIT_ASSERT(! CORBA::is_nil(nc0)); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindRecursive(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? */ void test_bind_already_bound() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? try { m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::AlreadyBound expected) {} rto->_remove_ref(); } /*! * @brief rebind()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
332  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
333  objMgr.activate(rto);
334  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
335 
336  // オブジェクトをバインドし、それが正しく設定されるか?
337  const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
338  m_pNaming->bindByString(fullName, rto->getObjRef());
339  CORBA::Object_ptr obj = resolveRecursive(fullName);
340  CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
341  rto->_remove_ref();
342  }
343 
350  {
351  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
352 
353  // バインド先となるコンテキストを登録しておく
354  RTC::RTObject_impl* rto0 = new RTC::RTObject_impl(m_pORB, m_pPOA);
355  objMgr.activate(rto0);
356  CPPUNIT_ASSERT(! CORBA::is_nil(rto0->getObjRef()));
357 
358  const char* fullName0 = "id0-lv0.kind0-lv0/id0-lv1.kind0-lv1";
359  m_pNaming->bind(m_pNaming->toName(fullName0), rto0->getObjRef());
360 
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));
364 
365  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bindRecursive(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id0-lv0.kind0-lv0/lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); rto->_remove_ref(); rto0->_remove_ref(); } /*! * @brief bind()メソッドのテスト * * - すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? */ void test_bind_already_bound() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? try { m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::AlreadyBound expected) {} rto->_remove_ref(); } /*! * @brief rebind()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
366  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
367  objMgr.activate(rto);
368  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
369 
370  // オブジェクトをバインドし、それが正しく設定されるか?
371  const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
372  m_pNaming->bindRecursive(nc0._retn(), m_pNaming->toName(fullName), rto->getObjRef());
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()));
375  rto->_remove_ref();
376  rto0->_remove_ref();
377  }
378 
385  {
386  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
387 
388  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive(fullName); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか? try { m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef()); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::AlreadyBound expected) {} rto->_remove_ref(); } /*! * @brief rebind()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
389  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
390  objMgr.activate(rto);
391  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
392 
393  // オブジェクトをバインドし、それが正しく設定されるか?
394  const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
395  m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef());
396  CORBA::Object_ptr obj = resolveRecursive(fullName);
397  CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
398 
399  // すでにバインド済みの名称を指定してバインドを試みた場合、意図どおりの例外がスローされるか?
400  try
401  {
402  m_pNaming->bind(m_pNaming->toName(fullName), rto->getObjRef());
403  CPPUNIT_FAIL("Expected exception not thrown.");
404  }
405  catch (CosNaming::NamingContext::AlreadyBound expected) {}
406  rto->_remove_ref();
407  }
408 
414  void test_rebind()
415  {
416  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
417 
418  // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindByString()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? */ void test_rebindByString() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
419  RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA);
420  objMgr.activate(rto1);
421  CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
422  RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA);
423  objMgr.activate(rto2);
424  CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef()));
425 
426  // オブジェクトをバインドし、それが正しく設定されるか?
427  const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
428  m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef());
429  CORBA::Object_ptr obj1 = resolveRecursive(fullName);
430  CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this()));
431 
432  // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか?
433  m_pNaming->rebind(m_pNaming->toName(fullName), rto2->getObjRef());
434  CORBA::Object_ptr obj2 = resolveRecursive(fullName);
435  CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this()));
436  rto2->_remove_ref();
437  rto1->_remove_ref();
438  }
439 
446  {
447  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
448 
449  // アクティブ化する RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // オブジェクトをバインドし、それが正しく設定されるか? const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind"; m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef()); CORBA::Object_ptr obj1 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this())); // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか? m_pNaming->rebindByString(fullName, rto2->getObjRef()); CORBA::Object_ptr obj2 = resolveRecursive(fullName); CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindRecursive()メソッドのテスト * * - すでにバインド済みの名称を指定してリバインドを試みた場合、正しく新しいバインディングに置き換わるか? */ void tset_rebindRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テスト用にバインドするオブジェクトを作成しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
450  RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA);
451  objMgr.activate(rto1);
452  CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
453  RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA);
454  objMgr.activate(rto2);
455  CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef()));
456 
457  // オブジェクトをバインドし、それが正しく設定されるか?
458  const char* fullName = "lv1-id.lv1-kind/lv2-id.lv2-kind/lv3-id.lv3-kind";
459  m_pNaming->bind(m_pNaming->toName(fullName), rto1->getObjRef());
460  CORBA::Object_ptr obj1 = resolveRecursive(fullName);
461  CPPUNIT_ASSERT(obj1->_is_equivalent(rto1->_this()));
462 
463  // すでにバインド済みの名称を指定してリバインドを試みた場合、新しいバインディングに置き換わるか?
464  m_pNaming->rebindByString(fullName, rto2->getObjRef());
465  CORBA::Object_ptr obj2 = resolveRecursive(fullName);
466  CPPUNIT_ASSERT(obj2->_is_equivalent(rto2->_this()));
467  rto2->_remove_ref();
468  rto1->_remove_ref();
469  }
470 
477  {
478  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
479 
480  // バインド先となるコンテキストを作成し、バインドしておく
481  CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext();
482  CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
483 
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));
487 
488  // テスト用にバインドするオブジェクトを作成しておく
489  RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA);
490  objMgr.activate(rto1);
491  CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
492 
493  RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA);
494  objMgr.activate(rto2);
495  CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef()));
496 
497  // 1つ目のオブジェクトをバインドする m_pNaming->bindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか? m_pNaming->rebindRecursive( ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief bindContext()メソッドのテスト * * - NamingContextを正しくバインドできるか? */ void test_bindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを登録しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // テストに用いるコンテキストを準備しておく CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
498  m_pNaming->bindRecursive(
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()));
503 
504  // 2つ目のオブジェクトを、1つ目と同じ位置に正しくリバインドできるか?
505  m_pNaming->rebindRecursive(
506  ncParent, m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef());
507  CORBA::Object_ptr objRto2 = resolveRecursive(
508  "id-parent.kind-parent/id-rto.kind-rto");
509  CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef()));
510  rto2->_remove_ref();
511  rto1->_remove_ref();
512  }
513 
520  {
521  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
522 
523  // バインド先となるコンテキストを登録しておく
524  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
525  objMgr.activate(rto);
526  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
527 
528  // テストに用いるコンテキストを準備しておく
529  CosNaming::NamingContext_ptr nc = m_pNaming->newContext();
530  CPPUNIT_ASSERT(! CORBA::is_nil(nc));
531 
532  nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef());
533 
534  // コンテキストをバインドし、正しくバインドできたことを確認する m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc); CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief bindContextRecursive()メソッドのテスト * * - バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? */ void test_bindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、あらかじめバインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // バインドするコンテキストを作成しておく RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); CosNaming::NamingContext_ptr nc = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか? m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc); CORBA::Object_ptr objNc = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1"); CPPUNIT_ASSERT(objNc->_is_equivalent(nc)); CORBA::Object_ptr objRto = resolveRecursive( "id-parent.kind-parent/id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind"); CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef())); rto->_remove_ref(); } /*! * @brief rebindContext()メソッドのテスト * * - すでにバインド済みのコンテキストを同じ位置に別のコンテキストのバインドし、正しくリバインドできることを確認する */ void test_rebindContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
535  m_pNaming->bindContext("id-lv0.kind-lv0/id-lv1.kind-lv1", nc);
536 
537  CORBA::Object_ptr objNc = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1");
538  CPPUNIT_ASSERT(objNc->_is_equivalent(nc));
539 
540  CORBA::Object_ptr objRto = resolveRecursive("id-lv0.kind-lv0/id-lv1.kind-lv1/id.kind");
541  CPPUNIT_ASSERT(objRto->_is_equivalent(rto->getObjRef()));
542  rto->_remove_ref();
543  }
544 
551  {
552  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
553 
554  // バインド先となるコンテキストを作成し、あらかじめバインドしておく
555  CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext();
556  CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
557 
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));
561 
562  // バインドするコンテキストを作成しておく
563  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
564  objMgr.activate(rto);
565  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
566 
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());
570 
571  // バインド先となるコンテキストを指定して、バインド対象となるコンテキストをバインドできるか?
572  m_pNaming->bindContextRecursive(
573  ncParent, m_pNaming->toName("id-lv0.kind-lv0/id-lv1.kind-lv1"), nc);
574 
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));
578 
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()));
582  rto->_remove_ref();
583  }
584 
591  {
592 
593  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
594 
595  // テストに用いるコンテキストを準備しておく
596  RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA);
597  objMgr.activate(rto1);
598  CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
599 
600  RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA);
601  objMgr.activate(rto2);
602  CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef()));
603 
604  CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext();
605  CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
606  nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef());
607 
608  CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext();
609  CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
610  nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef());
611 
612  // 1つ目のコンテキストをバインドする m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
613  m_pNaming->bindContext(m_pNaming->toName("id-nc.kind-nc"), nc1);
614  CORBA::Object_ptr objRto1 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto");
615  CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef()));
616 
617  // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } /*! * @brief rebindContextRecursive()メソッドのテスト * * - すでにバインド済みのコンテキストと同じ位置に、異なるコンテキストを正しくリバインドできるか? */ void test_rebindContextRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // バインド先となるコンテキストを作成し、バインドしておく CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objParent->_is_equivalent(ncParent)); // テストに用いるコンテキストを準備しておく RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto1); CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef())); RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto2); CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef())); CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); nc1->bind(m_pNaming->toName("id-rto.kind-rto"), rto1->getObjRef()); CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef()); // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
618  m_pNaming->rebindContext(m_pNaming->toName("id-nc.kind-nc"), nc2);
619  CORBA::Object_ptr objRto2 = resolveRecursive("id-nc.kind-nc/id-rto.kind-rto");
620  CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef()));
621  rto2->_remove_ref();
622  rto1->_remove_ref();
623  }
624 
631  {
632  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
633 
634  // バインド先となるコンテキストを作成し、バインドしておく
635  CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext();
636  CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
637 
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));
641 
642  // テストに用いるコンテキストを準備しておく
643  RTC::RTObject_impl* rto1 = new RTC::RTObject_impl(m_pORB, m_pPOA);
644  objMgr.activate(rto1);
645  CPPUNIT_ASSERT(! CORBA::is_nil(rto1->getObjRef()));
646 
647  RTC::RTObject_impl* rto2 = new RTC::RTObject_impl(m_pORB, m_pPOA);
648  objMgr.activate(rto2);
649  CPPUNIT_ASSERT(! CORBA::is_nil(rto2->getObjRef()));
650 
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());
654 
655  CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext();
656  CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
657  nc2->bind(m_pNaming->toName("id-rto.kind-rto"), rto2->getObjRef());
658 
659  // 1つ目のコンテキストをバインドする m_pNaming->bindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc1); CORBA::Object_ptr objRto1 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto1->_is_equivalent(rto1->getObjRef())); // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
660  m_pNaming->bindContextRecursive(
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()));
665 
666  // 2つ目のコンテキストを同じ位置にバインドし、正しくリバインドできることを確認する m_pNaming->rebindContextRecursive( ncParent, m_pNaming->toName("id-nc.kind-nc"), nc2); CORBA::Object_ptr objRto2 = resolveRecursive( "id-parent.kind-parent/id-nc.kind-nc/id-rto.kind-rto"); CPPUNIT_ASSERT(objRto2->_is_equivalent(rto2->getObjRef())); rto2->_remove_ref(); rto1->_remove_ref(); } void test_resolve() { // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
667  m_pNaming->rebindContextRecursive(
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()));
672  rto2->_remove_ref();
673  rto1->_remove_ref();
674  }
675 
677  {
678  // 他テスト群にて兼ねる } /*! * @brief unbind()メソッドのテスト * * - バインド済みのオブジェクトを正常にアンバインドできるか? * - アンバインド済みのオブジェクトの解決を試みて、意図どおりの例外がスローされるか? */ void test_unbind() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
679  }
680 
687  void test_unbind()
688  {
689  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
690 
691  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
692  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
693  objMgr.activate(rto);
694  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
695 
696  // オブジェクトをバインドする m_pNaming->bindByString("id.kind", rto->getObjRef()); CORBA::Object_ptr obj = m_pNaming->resolve("id.kind"); CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this())); // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
697  m_pNaming->bindByString("id.kind", rto->getObjRef());
698  CORBA::Object_ptr obj = m_pNaming->resolve("id.kind");
699  CPPUNIT_ASSERT(obj->_is_equivalent(rto->_this()));
700 
701  // オブジェクトをアンバインドする m_pNaming->unbind("id.kind"); // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか? try { m_pNaming->resolve("id.kind"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (CosNaming::NamingContext::NotFound expected) { // do nothing } catch (...) { CPPUNIT_FAIL("Unexpected exception catched."); } rto->_remove_ref(); } /*! * @brief bindNewContext()メソッドのテスト * * - 新しいコンテキストをバインドできるか? * - バインドしたコンテキストを利用してオブジェクト参照を正しくバインドできるか? */ void test_bindNewContext() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
702  m_pNaming->unbind("id.kind");
703 
704  // アンバインドしたオブジェクトの解決を試みて、意図どおりの例外がスローされるか?
705  try
706  {
707  m_pNaming->resolve("id.kind");
708  CPPUNIT_FAIL("Expected exception not thrown.");
709  }
710  catch (CosNaming::NamingContext::NotFound expected)
711  {
712  // do nothing
713  }
714  catch (...)
715  {
716  CPPUNIT_FAIL("Unexpected exception catched.");
717  }
718  rto->_remove_ref();
719  }
720 
728  {
729  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
730 
731  // アクティブ化する RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA); objMgr.activate(rto); CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef())); // 新しいコンテキストをバインドできるか? CosNaming::NamingContext_ptr nc = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0")); CPPUNIT_ASSERT(! CORBA::is_nil(nc)); // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか? nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef()); CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind"); CPPUNIT_ASSERT(! CORBA::is_nil(obj)); rto->_remove_ref(); } void test_destroy() { // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略 } void test_destroyRecursive() { RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA); // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
732  RTC::RTObject_impl* rto = new RTC::RTObject_impl(m_pORB, m_pPOA);
733  objMgr.activate(rto);
734  CPPUNIT_ASSERT(! CORBA::is_nil(rto->getObjRef()));
735 
736  // 新しいコンテキストをバインドできるか?
737  CosNaming::NamingContext_ptr nc
738  = m_pNaming->bindNewContext(m_pNaming->toName("id-lv0.kind-lv0"));
739  CPPUNIT_ASSERT(! CORBA::is_nil(nc));
740 
741  // バインドしたコンテキストを利用してオブジェクト参照をバインドできるか?
742  nc->bind(m_pNaming->toName("id.kind"), rto->getObjRef());
743  CORBA::Object_ptr obj = resolveRecursive("id-lv0.kind-lv0/id.kind");
744  CPPUNIT_ASSERT(! CORBA::is_nil(obj));
745 
746  rto->_remove_ref();
747  }
748 
750  {
751  // CosNaming::NamingContext::destroy()への単純な委譲なので、テスト省略
752  }
753 
755  {
756  RTC::CorbaObjectManager objMgr(m_pORB, m_pPOA);
757 
758  // destroy対象となるコンテキストのツリーを構築する(親1:子2) // (親) CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(ncParent)); m_pNaming->bindContext("id-parent.kind-parent", ncParent); CORBA::Object_ptr objNcParent = resolveRecursive("id-parent.kind-parent"); CPPUNIT_ASSERT(objNcParent->_is_equivalent(ncParent)); // (子1) CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc1)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1); CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1"); CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1)); // (子2) CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext(); CPPUNIT_ASSERT(! CORBA::is_nil(nc2)); m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2); CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2"); CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2)); // destroyRecursive()を呼び出す m_pNaming->destroyRecursive(m_pNaming->getRootContext()); // 各コンテキストがdestroyされているか? // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
759  // (親)
760  CosNaming::NamingContext_ptr ncParent = m_pNaming->newContext();
761  CPPUNIT_ASSERT(! CORBA::is_nil(ncParent));
762 
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));
766 
767  // (子1)
768  CosNaming::NamingContext_ptr nc1 = m_pNaming->newContext();
769  CPPUNIT_ASSERT(! CORBA::is_nil(nc1));
770 
771  m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id1.kind1"), nc1);
772  CORBA::Object_ptr objNc1 = resolveRecursive("id-parent.kind-parent/id1.kind1");
773  CPPUNIT_ASSERT(objNc1->_is_equivalent(nc1));
774 
775  // (子2)
776  CosNaming::NamingContext_ptr nc2 = m_pNaming->newContext();
777  CPPUNIT_ASSERT(! CORBA::is_nil(nc2));
778 
779  m_pNaming->bindContextRecursive(ncParent, m_pNaming->toName("id2.kind2"), nc2);
780  CORBA::Object_ptr objNc2 = resolveRecursive("id-parent.kind-parent/id2.kind2");
781  CPPUNIT_ASSERT(objNc2->_is_equivalent(nc2));
782 
783  // destroyRecursive()を呼び出す
784  m_pNaming->destroyRecursive(m_pNaming->getRootContext());
785 
786  // 各コンテキストがdestroyされているか?
787  // (各コンテキストへのメソッド呼出しを行い、意図どおり例外がスローされるか?) // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない? // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。 //new_context doesn't throw out the exception. //Therefore, the following tests are omitted. /* { bool thrown = false; try { ncParent->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc1->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } { bool thrown = false; try { nc2->new_context(); } catch (CORBA::OBJECT_NOT_EXIST expected) { // expected thrown = true; } catch (...) { // expected thrown = true; } if (! thrown) CPPUNIT_FAIL("Exception not thrown."); } */ } }; }; // namespace CorbaNaming /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaNaming::CorbaNamingTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // CorbaNaming_cpp
788  // ※CORBA実装によってはCORBA::OBJECT_NOT_EXIST例外ではないかも知れない?
789  // そこで、CORBA::OBJECT_NOT_EXISTでない場合も考慮してチェックしている。
790 
791  //new_context doesn't throw out the exception.
792  //Therefore, the following tests are omitted.
793 /*
794  {
795 
796  bool thrown = false;
797  try
798  {
799  ncParent->new_context();
800  }
801  catch (CORBA::OBJECT_NOT_EXIST expected)
802  {
803  // expected
804  thrown = true;
805  }
806  catch (...)
807  {
808  // expected
809  thrown = true;
810  }
811  if (! thrown) CPPUNIT_FAIL("Exception not thrown.");
812 
813  }
814 
815  {
816  bool thrown = false;
817  try
818  {
819  nc1->new_context();
820  }
821  catch (CORBA::OBJECT_NOT_EXIST expected)
822  {
823  // expected
824  thrown = true;
825  }
826  catch (...)
827  {
828  // expected
829  thrown = true;
830  }
831  if (! thrown) CPPUNIT_FAIL("Exception not thrown.");
832  }
833 
834  {
835  bool thrown = false;
836  try
837  {
838  nc2->new_context();
839  }
840  catch (CORBA::OBJECT_NOT_EXIST expected)
841  {
842  // expected
843  thrown = true;
844  }
845  catch (...)
846  {
847  // expected
848  thrown = true;
849  }
850  if (! thrown) CPPUNIT_FAIL("Exception not thrown.");
851  }
852 */
853  }
854 
855  };
856 }; // namespace CorbaNaming
857 
858 /*
859  * Register test suite
860  */
862 
863 #ifdef LOCAL_MAIN
864 int main(int argc, char* argv[])
865 {
866 
867  FORMAT format = TEXT_OUT;
868  int target = 0;
869  std::string xsl;
870  std::string ns;
871  std::string fname;
872  std::ofstream ofs;
873 
874  int i(1);
875  while (i < argc)
876  {
877  std::string arg(argv[i]);
878  std::string next_arg;
879  if (i + 1 < argc) next_arg = argv[i + 1];
880  else next_arg = "";
881 
882  if (arg == "--text") { format = TEXT_OUT; break; }
883  if (arg == "--xml")
884  {
885  if (next_arg == "")
886  {
887  fname = argv[0];
888  fname += ".xml";
889  }
890  else
891  {
892  fname = next_arg;
893  }
894  format = XML_OUT;
895  ofs.open(fname.c_str());
896  }
897  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
898  if ( arg == "--cerr" ) { target = 1; break; }
899  if ( arg == "--xsl" )
900  {
901  if (next_arg == "") xsl = "default.xsl";
902  else xsl = next_arg;
903  }
904  if ( arg == "--namespace" )
905  {
906  if (next_arg == "")
907  {
908  std::cerr << "no namespace specified" << std::endl;
909  exit(1);
910  }
911  else
912  {
913  xsl = next_arg;
914  }
915  }
916  ++i;
917  }
918  CppUnit::TextUi::TestRunner runner;
919  if ( ns.empty() )
920  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
921  else
922  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
923  CppUnit::Outputter* outputter = 0;
924  std::ostream* stream = target ? &std::cerr : &std::cout;
925  switch ( format )
926  {
927  case TEXT_OUT :
928  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
929  break;
930  case XML_OUT :
931  std::cout << "XML_OUT" << std::endl;
932  outputter = new CppUnit::XmlOutputter(&runner.result(),
933  ofs, "shift_jis");
934  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
935  break;
936  case COMPILER_OUT :
937  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
938  break;
939  }
940  runner.setOutputter(outputter);
941  runner.run();
942  return 0; // runner.run() ? 0 : 1;
943 }
944 #endif // MAIN
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.
RT-Component.
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.
RT-Component class.
Definition: RTObject.h:89
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.
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_bind()
bind()メソッドのテスト
CORBA::Object_ptr resolveRecursive(const char *fullName)
::PortableServer::POA_ptr m_poa
CORBA Naming Service helper class.
Definition: CorbaNaming.h:89
void unbind(const CosNaming::Name &name)
Unbind a binding specified by NameComponent.
void tset_rebindRecursive()
rebindRecursive()メソッドのテスト
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.
Definition: CorbaNaming.cpp:77
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()メソッドのテスト
RTComponent header.
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
Definition: RTObject.cpp:1483
void rebindByString(const char *string_name, CORBA::Object_ptr obj, const bool force=1)
Rebind Object.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:51