CorbaPortTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: CorbaPortTests.cpp,v $
14  * Revision 1.2 2008/04/04 12:06:09 arafune
15  * Refactored some tests. No new tests were added.
16  *
17  * Revision 1.1 2007/12/20 07:50:18 arafune
18  * *** empty log message ***
19  *
20  * Revision 1.1 2007/01/04 00:50:38 n-ando
21  * *** empty log message ***
22  *
23  *
24  */
25 
26 #ifndef CorbaPort_cpp
27 #define CorbaPort_cpp
28 
29 #include <cppunit/ui/text/TestRunner.h>
30 #include <cppunit/TextOutputter.h>
31 #include <cppunit/extensions/TestFactoryRegistry.h>
32 #include <cppunit/extensions/HelperMacros.h>
33 #include <cppunit/TestAssert.h>
34 
35 #include <rtm/CorbaPort.h>
36 #include <rtm/CorbaConsumer.h>
37 
38 #include "MyServiceSkel.h"
39 
41  : public virtual POA_MyService,
42  public virtual PortableServer::RefCountServantBase
43 {
44 public:
46  {
47  };
48 
49  virtual ~MyService_impl()
50  {
51  };
52 
53  void setName(const char* name)
54  {
55  m_name = name;
56  }
57 
58  char* name()
59  {
60  return "MyService";
61  }
62 
63  void hello_world()
64  {
65  m_hello_world_called = true;
66  }
67 
68  void print_msg(const char* msg)
69  {
70  std::cout << m_name << ": " << msg << std::endl;
71  }
72 
74  {
75  return m_hello_world_called;
76  }
77 
78 private:
79  std::string m_name;
81 };
82 
83 
89  : public RTC::CorbaPort
90 {
91  public:
95  CorbaPortMock(const char* name)
96  : RTC::CorbaPort(name)
97  {
98  }
102  virtual ~CorbaPortMock(void)
103  {
104  }
109  {
110  deactivateInterfaces();
111  }
116  {
117  activateInterfaces();
118  }
119 };
124 namespace CorbaPort
125 {
127  : public CppUnit::TestFixture
128  {
129  CPPUNIT_TEST_SUITE(CorbaPortTests);
130  CPPUNIT_TEST(test_get_port_profile);
131  CPPUNIT_TEST(test_connect);
132  CPPUNIT_TEST(test_disconnect);
133  CPPUNIT_TEST(test_registerProvider);
134  CPPUNIT_TEST(test_activateInterfaces_deactivateInterfaces);
135  CPPUNIT_TEST_SUITE_END();
136 
137  private:
138  CORBA::ORB_ptr m_pORB;
139  PortableServer::POA_ptr m_pPOA;
140 
141  public:
146  {
147  }
148 
153  {
154  }
155 
159  virtual void setUp()
160  {
161  int argc(0);
162  char** argv(NULL);
163 
164  m_pORB = CORBA::ORB_init(argc, argv);
165  m_pPOA = PortableServer::POA::_narrow(
166  m_pORB->resolve_initial_references("RootPOA"));
167  m_pPOA->the_POAManager()->activate();
168  }
169 
173  virtual void tearDown()
174  {
175  try
176  {
177  // m_pPOA->destroy(false, false);
178  // m_pPOA->the_POAManager()->deactivate(false, false);
179  // m_pORB->destroy();
180  }
181  catch (...)
182  {
183  // do nothing
184  }
185  }
186 
196  {
197  // テスト対象となるCorbaPortを構成する MyService_impl* pMyServiceImpl = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumer = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically RTC::CorbaPort* port = new RTC::CorbaPort("name of port"); coil::Properties dummy; port->init(dummy); port->registerProvider("MyService (provided)", "Generic (provided)", *pMyServiceImpl); port->registerConsumer("MyService (required)", "Generic (required)", *pMyServiceConsumer); RTC::PortService_var portRef = port->getPortRef(); RTC::PortProfile* profile = portRef->get_port_profile(); // ポート名称を正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("unknown.name of port"), std::string(profile->name)); // インタフェースプロファイルを取得し、あらかじめ設定しておいた内容と一致することを確認する RTC::PortInterfaceProfileList& profiles = profile->interfaces; for (CORBA::ULong i = 0; i < profile->interfaces.length(); ++i) { if (std::string(profiles[i].instance_name) == std::string("MyService (provided)")) { // type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("Generic (provided)"), std::string(profiles[i].type_name)); // polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::PROVIDED, profiles[i].polarity); } else if (std::string(profiles[i].instance_name) == std::string("MyService (required)")) { // type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("Generic (required)"), std::string(profiles[i].type_name)); // polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, profiles[i].polarity); } else { // 予期しないinstance_nameが取得された場合 std::string msg("Unexpected instance_name:"); msg += std::string(profiles[i].instance_name); CPPUNIT_FAIL(msg); } } delete port; delete pMyServiceConsumer; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImpl)); delete pMyServiceImpl; } /*! * connect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? * - ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? */ void test_connect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
198  MyService_impl* pMyServiceImpl
199  = new MyService_impl(); // will be deleted automatically
200  RTC::CorbaConsumer<MyService>* pMyServiceConsumer
201  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
202 
203  RTC::CorbaPort* port = new RTC::CorbaPort("name of port");
204  coil::Properties dummy;
205  port->init(dummy);
206  port->registerProvider("MyService (provided)", "Generic (provided)", *pMyServiceImpl);
207  port->registerConsumer("MyService (required)", "Generic (required)", *pMyServiceConsumer);
208 
209  RTC::PortService_var portRef = port->getPortRef();
210  RTC::PortProfile* profile = portRef->get_port_profile();
211 
212  // ポート名称を正しく取得できるか?
213  CPPUNIT_ASSERT_EQUAL(std::string("unknown.name of port"), std::string(profile->name));
214 
215  // インタフェースプロファイルを取得し、あらかじめ設定しておいた内容と一致することを確認する RTC::PortInterfaceProfileList& profiles = profile->interfaces; for (CORBA::ULong i = 0; i < profile->interfaces.length(); ++i) { if (std::string(profiles[i].instance_name) == std::string("MyService (provided)")) { // type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("Generic (provided)"), std::string(profiles[i].type_name)); // polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::PROVIDED, profiles[i].polarity); } else if (std::string(profiles[i].instance_name) == std::string("MyService (required)")) { // type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("Generic (required)"), std::string(profiles[i].type_name)); // polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, profiles[i].polarity); } else { // 予期しないinstance_nameが取得された場合 std::string msg("Unexpected instance_name:"); msg += std::string(profiles[i].instance_name); CPPUNIT_FAIL(msg); } } delete port; delete pMyServiceConsumer; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImpl)); delete pMyServiceImpl; } /*! * connect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? * - ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? */ void test_connect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
216  RTC::PortInterfaceProfileList& profiles = profile->interfaces;
217  for (CORBA::ULong i = 0; i < profile->interfaces.length(); ++i)
218  {
219  if (std::string(profiles[i].instance_name)
220  == std::string("MyService (provided)"))
221  {
222  // type_nameを正しく取得できるか?
223  CPPUNIT_ASSERT_EQUAL(std::string("Generic (provided)"),
224  std::string(profiles[i].type_name));
225 
226  // polarityを正しく取得できるか?
227  CPPUNIT_ASSERT_EQUAL(RTC::PROVIDED, profiles[i].polarity);
228  }
229  else if (std::string(profiles[i].instance_name)
230  == std::string("MyService (required)"))
231  {
232  // type_nameを正しく取得できるか?
233  CPPUNIT_ASSERT_EQUAL(std::string("Generic (required)"),
234  std::string(profiles[i].type_name));
235 
236  // polarityを正しく取得できるか?
237  CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, profiles[i].polarity);
238  }
239  else
240  {
241  // 予期しないinstance_nameが取得された場合 std::string msg("Unexpected instance_name:"); msg += std::string(profiles[i].instance_name); CPPUNIT_FAIL(msg); } } delete port; delete pMyServiceConsumer; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImpl)); delete pMyServiceImpl; } /*! * connect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? * - ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? */ void test_connect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
242  std::string msg("Unexpected instance_name:");
243  msg += std::string(profiles[i].instance_name);
244  CPPUNIT_FAIL(msg);
245  }
246  }
247 
248  delete port;
249  delete pMyServiceConsumer;
250  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImpl));
251  delete pMyServiceImpl;
252  }
253 
261  {
262  // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
263  MyService_impl* pMyServiceImplA
264  = new MyService_impl(); // will be deleted automatically
265  RTC::CorbaConsumer<MyService>* pMyServiceConsumerB
266  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
267 
268  CorbaPortMock* port0 = new CorbaPortMock("name of port0");
269  port0->registerProvider("MyServiceA", "Generic", *pMyServiceImplA);
270  port0->registerConsumer("MyServiceB", "Generic", *pMyServiceConsumerB);
271 
272  // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
273  MyService_impl* pMyServiceImplB
274  = new MyService_impl(); // will be deleted automatically
275  RTC::CorbaConsumer<MyService>* pMyServiceConsumerA
276  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
277 
278  CorbaPortMock* port1 = new CorbaPortMock("name of port1");
279  port1->registerProvider("MyServiceB", "Generic", *pMyServiceImplB);
280  port1->registerConsumer("MyServiceA", "Generic", *pMyServiceConsumerA);
281 
282  // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
283  RTC::ConnectorProfile connProfile;
284  connProfile.connector_id = "";
285  connProfile.name = CORBA::string_dup("name of connector profile");
286  connProfile.ports.length(2);
287  connProfile.ports[0] = port0->getPortRef();
288  connProfile.ports[1] = port1->getPortRef();
289 
290  // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called()); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト * * - 接続が成功した後に切断を行い、リモートメソッドの呼出しが意図どおり失敗することを確認する */ void test_disconnect() { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
291  port0->getPortRef()->connect(connProfile);
292 
293  port0->activateInterfaces_public();
294  port1->activateInterfaces_public();
295 
296  // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか?
297  CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called());
298  (*pMyServiceConsumerA)->hello_world();
299  CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called());
300 
301  // ポート0のコンシューマ側からメソッドを呼び出すと、ポート1のプロバイダ側が意図どおり呼び出されるか?
302  CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called());
303  (*pMyServiceConsumerB)->hello_world();
304  CPPUNIT_ASSERT(pMyServiceImplB->is_hello_world_called());
305 
306 // delete port1;
307  delete port0;
308  delete pMyServiceConsumerA;
309  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB));
310  delete pMyServiceImplB;
311  delete pMyServiceConsumerB;
312  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA));
313  delete pMyServiceImplA;
314  }
315 
322  {
323  // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0-1"); port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
324  MyService_impl* pMyServiceImplA
325  = new MyService_impl(); // will be deleted automatically
326  RTC::CorbaConsumer<MyService>* pMyServiceConsumerB
327  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
328 
329  CorbaPortMock* port0 = new CorbaPortMock("name of port0-1");
330  port0->registerProvider("MyServiceA-1", "Generic", *pMyServiceImplA);
331  port0->registerConsumer("MyServiceB-1", "Generic", *pMyServiceConsumerB);
332 
333  // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1-1"); port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
334  MyService_impl* pMyServiceImplB
335  = new MyService_impl(); // will be deleted automatically
336  RTC::CorbaConsumer<MyService>* pMyServiceConsumerA
337  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
338 
339  CorbaPortMock* port1 = new CorbaPortMock("name of port1-1");
340  port1->registerProvider("MyServiceB-1", "Generic", *pMyServiceImplB);
341  port1->registerConsumer("MyServiceA-1", "Generic", *pMyServiceConsumerA);
342 
343  // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = "id1"; connProfile.name = CORBA::string_dup("name of connector profile-1"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
344  RTC::ConnectorProfile connProfile;
345  connProfile.connector_id = "id1";
346  connProfile.name = CORBA::string_dup("name of connector profile-1");
347  connProfile.ports.length(2);
348  connProfile.ports[0] = port0->getPortRef();
349  connProfile.ports[1] = port1->getPortRef();
350 
351  // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
352  port0->getPortRef()->connect(connProfile);
353 
354  port0->activateInterfaces_public();
355  port1->activateInterfaces_public();
356 
357  // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか?
358  CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called());
359  (*pMyServiceConsumerA)->hello_world();
360  CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called());
361 
362  // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか? try { CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called()); (*pMyServiceConsumerB)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { // Properly disconnected. } // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } /*! * @brief registerProvider()メソッドのテスト * */ void test_registerProvider(void) { MyService_impl* pImpl0 = new MyService_impl(); MyService_impl* pImpl1 = new MyService_impl(); CorbaPortMock* port0 = new CorbaPortMock("name of port"); bool ret; ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(false,ret); //既に登録してあるインスタンス名を登録した場合、falseを返す。 ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(false,ret); //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。 // falseを返すが登録される。 ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0); CPPUNIT_ASSERT_EQUAL(true,ret); //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。 ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1); CPPUNIT_ASSERT_EQUAL(true,ret); port0->deactivateInterfaces_public(); delete port0; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1)); delete pImpl1; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0)); delete pImpl0; } /*! * @brief registerProvider()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
363  port0->getPortRef()->disconnect(connProfile.connector_id);
364 
365  // ポート0のコンシューマ側からメソッドを呼び出しを試みると、意図どおりに失敗するか?
366  try
367  {
368  CPPUNIT_ASSERT(! pMyServiceImplB->is_hello_world_called());
369  (*pMyServiceConsumerB)->hello_world();
370 
371  CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed.");
372  }
373  catch(...)
374  {
375  // Properly disconnected.
376  }
377 
378 // delete port1;
379  delete port0;
380  delete pMyServiceConsumerA;
381  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB));
382  delete pMyServiceImplB;
383  delete pMyServiceConsumerB;
384  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA));
385  delete pMyServiceImplA;
386  }
392  {
393  MyService_impl* pImpl0
394  = new MyService_impl();
395 
396  MyService_impl* pImpl1
397  = new MyService_impl();
398 
399 
400  CorbaPortMock* port0 = new CorbaPortMock("name of port");
401  bool ret;
402  ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0);
403  CPPUNIT_ASSERT_EQUAL(true,ret);
404 
405  //既に登録してあるインスタンス名とオブジェクトを登録した場合、falseを返す。
406  ret = port0->registerProvider("registerProvider0", "Generic", *pImpl0);
407  CPPUNIT_ASSERT_EQUAL(false,ret);
408 
409  //既に登録してあるインスタンス名を登録した場合、falseを返す。
410  ret = port0->registerProvider("registerProvider0", "Generic", *pImpl1);
411  CPPUNIT_ASSERT_EQUAL(false,ret);
412 
413  //別なインスタンス名で既に登録してあるオブジェクトを登録した場合、trueを返す。
414  // falseを返すが登録される。
415  ret = port0->registerProvider("registerProvider1", "Generic", *pImpl0);
416  CPPUNIT_ASSERT_EQUAL(true,ret);
417 
418  //登録してないインスタンス名とオブジェクトを登録した場合、trueを返す。
419  ret = port0->registerProvider("registerProvider2", "Generic", *pImpl1);
420  CPPUNIT_ASSERT_EQUAL(true,ret);
421 
423 
424  delete port0;
425  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl1));
426  delete pImpl1;
427  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pImpl0));
428  delete pImpl0;
429  }
435  {
436  // ポート0を構成する MyService_impl* pMyServiceImplA = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerB = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port0 = new CorbaPortMock("name of port0"); port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA); port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB); // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
437  MyService_impl* pMyServiceImplA
438  = new MyService_impl(); // will be deleted automatically
439  RTC::CorbaConsumer<MyService>* pMyServiceConsumerB
440  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
441 
442  CorbaPortMock* port0 = new CorbaPortMock("name of port0");
443  port0->registerProvider("MyServiceAA", "Generic", *pMyServiceImplA);
444  port0->registerConsumer("MyServiceBB", "Generic", *pMyServiceConsumerB);
445 
446  // ポート1を構成する MyService_impl* pMyServiceImplB = new MyService_impl(); // will be deleted automatically RTC::CorbaConsumer<MyService>* pMyServiceConsumerA = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically CorbaPortMock* port1 = new CorbaPortMock("name of port1"); port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB); port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA); // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
447  MyService_impl* pMyServiceImplB
448  = new MyService_impl(); // will be deleted automatically
449  RTC::CorbaConsumer<MyService>* pMyServiceConsumerA
450  = new RTC::CorbaConsumer<MyService>(); // will be deleted automatically
451 
452  CorbaPortMock* port1 = new CorbaPortMock("name of port1");
453  port1->registerProvider("MyServiceBB", "Generic", *pMyServiceImplB);
454  port1->registerConsumer("MyServiceAA", "Generic", *pMyServiceConsumerA);
455 
456  // 接続プロファイルを構成する RTC::ConnectorProfile connProfile; connProfile.connector_id = ""; connProfile.name = CORBA::string_dup("name of connector profile"); connProfile.ports.length(2); connProfile.ports[0] = port0->getPortRef(); connProfile.ports[1] = port1->getPortRef(); // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
457  RTC::ConnectorProfile connProfile;
458  connProfile.connector_id = "";
459  connProfile.name = CORBA::string_dup("name of connector profile");
460  connProfile.ports.length(2);
461  connProfile.ports[0] = port0->getPortRef();
462  connProfile.ports[1] = port1->getPortRef();
463 
464  // 接続する port0->getPortRef()->connect(connProfile); port0->activateInterfaces_public(); port1->activateInterfaces_public(); // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか? CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called()); (*pMyServiceConsumerA)->hello_world(); CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called()); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
465  port0->getPortRef()->connect(connProfile);
466 
467  port0->activateInterfaces_public();
468  port1->activateInterfaces_public();
469 
470  // ポート1のコンシューマ側からメソッドを呼び出すと、ポート0のプロバイダ側が意図どおり呼び出されるか?
471  CPPUNIT_ASSERT(! pMyServiceImplA->is_hello_world_called());
472  (*pMyServiceConsumerA)->hello_world();
473  CPPUNIT_ASSERT(pMyServiceImplA->is_hello_world_called());
474 
475  // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
476  port0->getPortRef()->disconnect(connProfile.connector_id);
477 
478  //全てdeactivate obujectする port0->deactivateInterfaces_public(); port1->deactivateInterfaces_public(); port0->getPortRef()->connect(connProfile); //deactivate object が実行されてたため、エラーとなる。 try { (*pMyServiceConsumerA)->hello_world(); CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed."); } catch(...) { } // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
479  port0->deactivateInterfaces_public();
480  port1->deactivateInterfaces_public();
481 
482  port0->getPortRef()->connect(connProfile);
483 
484  //deactivate object が実行されてたため、エラーとなる。
485  try
486  {
487  (*pMyServiceConsumerA)->hello_world();
488  CPPUNIT_FAIL("Couldn't catch no exceptions. Disconnection failed.");
489  }
490  catch(...)
491  {
492  }
493 
494  // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); port0->activateInterfaces_public(); port1->activateInterfaces_public(); port0->getPortRef()->connect(connProfile); //activate object が実行されてたため、正常に動作する 。 (*pMyServiceConsumerA)->hello_world(); // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
495  port0->getPortRef()->disconnect(connProfile.connector_id);
496 
497  port0->activateInterfaces_public();
498  port1->activateInterfaces_public();
499 
500  port0->getPortRef()->connect(connProfile);
501 
502  //activate object が実行されてたため、正常に動作する 。
503  (*pMyServiceConsumerA)->hello_world();
504 
505  // 切断する port0->getPortRef()->disconnect(connProfile.connector_id); // delete port1; delete port0; delete pMyServiceConsumerA; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB)); delete pMyServiceImplB; delete pMyServiceConsumerB; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA)); delete pMyServiceImplA; } }; }; // namespace CorbaPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests); #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 // CorbaPort_cpp
506  port0->getPortRef()->disconnect(connProfile.connector_id);
507 
508 // delete port1;
509  delete port0;
510  delete pMyServiceConsumerA;
511  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplB));
512  delete pMyServiceImplB;
513  delete pMyServiceConsumerB;
514  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pMyServiceImplA));
515  delete pMyServiceImplA;
516  }
517 
518  };
519 }; // namespace CorbaPort
520 
521 /*
522  * Register test suite
523  */
525 
526 #ifdef LOCAL_MAIN
527 int main(int argc, char* argv[])
528 {
529 
530  FORMAT format = TEXT_OUT;
531  int target = 0;
532  std::string xsl;
533  std::string ns;
534  std::string fname;
535  std::ofstream ofs;
536 
537  int i(1);
538  while (i < argc)
539  {
540  std::string arg(argv[i]);
541  std::string next_arg;
542  if (i + 1 < argc) next_arg = argv[i + 1];
543  else next_arg = "";
544 
545  if (arg == "--text") { format = TEXT_OUT; break; }
546  if (arg == "--xml")
547  {
548  if (next_arg == "")
549  {
550  fname = argv[0];
551  fname += ".xml";
552  }
553  else
554  {
555  fname = next_arg;
556  }
557  format = XML_OUT;
558  ofs.open(fname.c_str());
559  }
560  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
561  if ( arg == "--cerr" ) { target = 1; break; }
562  if ( arg == "--xsl" )
563  {
564  if (next_arg == "") xsl = "default.xsl";
565  else xsl = next_arg;
566  }
567  if ( arg == "--namespace" )
568  {
569  if (next_arg == "")
570  {
571  std::cerr << "no namespace specified" << std::endl;
572  exit(1);
573  }
574  else
575  {
576  xsl = next_arg;
577  }
578  }
579  ++i;
580  }
581  CppUnit::TextUi::TestRunner runner;
582  if ( ns.empty() )
583  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
584  else
585  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
586  CppUnit::Outputter* outputter = 0;
587  std::ostream* stream = target ? &std::cerr : &std::cout;
588  switch ( format )
589  {
590  case TEXT_OUT :
591  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
592  break;
593  case XML_OUT :
594  std::cout << "XML_OUT" << std::endl;
595  outputter = new CppUnit::XmlOutputter(&runner.result(),
596  ofs, "shift_jis");
597  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
598  break;
599  case COMPILER_OUT :
600  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
601  break;
602  }
603  runner.setOutputter(outputter);
604  runner.run();
605  return 0; // runner.run() ? 0 : 1;
606 }
607 #endif // MAIN
608 #endif // CorbaPort_cpp
int main(int argc, char **argv)
void test_activateInterfaces_deactivateInterfaces(void)
registerProvider()メソッドのテスト
CORBA Consumer class.
RT-Component.
void activateInterfaces_public()
virtual void tearDown()
Test finalization.
RT Conponent CORBA service/consumer Port.
Definition: CorbaPort.h:620
void test_registerProvider(void)
registerProvider()メソッドのテスト
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
CorbaPort class.
std::vector< PortInterfaceProfile * > PortInterfaceProfileList
Definition: IPortService.h:38
void setName(const char *name)
void test_disconnect()
disconnect()メソッド、および、そこから呼び出される各protectedメソッドのテスト
void test_get_port_profile()
get_port_profile()メソッドのテスト
void print_msg(const char *msg)
Class represents a set of properties.
Definition: Properties.h:101
virtual ~MyService_impl()
virtual void setUp()
Test initialization.
PortableServer::POA_ptr m_pPOA
bool is_hello_world_called()
CorbaPortMock(const char *name)
virtual ~CorbaPortMock(void)
void deactivateInterfaces_public()
CPPUNIT_TEST_SUITE_REGISTRATION(CorbaPort::CorbaPortTests)
std::string m_name
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
Register the provider.
Definition: CorbaPort.cpp:90


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:42