PortBaseTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 /*
22  * $Log: PortBaseTests.cpp,v $
23  * Revision 1.2 2008/02/08 10:57:23 arafune
24  * Some tests were added.
25  *
26  * Revision 1.1 2007/12/20 07:50:17 arafune
27  * *** empty log message ***
28  *
29  * Revision 1.3 2007/04/13 15:05:10 n-ando
30  * Now RTC::OK becomes RTC::RTC_OK in RTC.idl.
31  *
32  * Revision 1.2 2007/01/12 14:44:43 n-ando
33  * Some fixes for distribution control.
34  *
35  * Revision 1.1 2006/11/27 08:35:12 n-ando
36  * TestSuites are devided into each directory.
37  *
38  * Revision 1.2 2006/11/13 12:30:06 kurihara
39  *
40  * document is added.
41  *
42  * Revision 1.1 2006/11/08 01:19:07 kurihara
43  *
44  * test program for PortBase class.
45  *
46  */
47 
48 #ifndef PortBase_cpp
49 #define PortBase_cpp
50 
51 #include <cppunit/ui/text/TestRunner.h>
52 #include <cppunit/TextOutputter.h>
53 #include <cppunit/extensions/TestFactoryRegistry.h>
54 #include <cppunit/extensions/HelperMacros.h>
55 #include <cppunit/TestAssert.h>
56 
57 #include <vector>
58 #include <string>
59 #include <rtm/RTC.h>
60 #include <rtm/PortBase.h>
61 #include <rtm/RTObject.h>
62 #include <rtm/PortCallback.h>
63 
69 namespace PortBase
70 {
71 
73  {
74  public:
75  ConnectionCallbackMock(const char* name) : m_name(name) {}
77  {
78  //std::cout << "dtor of " << m_name << std::endl;
79  }
80 
81  virtual void operator()(RTC::ConnectorProfile& profile)
82  {
83  std::cout << "---------------------------------------------" << std::endl;
84  std::cout << "Connection Callback: " << m_name << std::endl;
85  std::cout << "Profile::name: " << profile.name << std::endl;
86  std::cout << "---------------------------------------------" << std::endl;
87  };
88  std::string m_name;
89  };
90 
91 
92  class PortBaseMock : public RTC::PortBase
93  {
94  public:
95 
96  PortBaseMock(const RTC::PortProfile& profile)
97  {
98  this->m_profile = profile;
99  this->m_profile.connector_profiles[0].ports.length(1);
100  this->m_profile.connector_profiles[0].ports[0] = this->m_objref;
101  this->m_profile.port_ref = this->m_objref;
102  }
103 
104  const std::string getUUID() const
105  {
106  return RTC::PortBase::getUUID();
107  }
108 
109  virtual RTC::ReturnCode_t notify_connect(RTC::ConnectorProfile& connector_profile)
110  throw (CORBA::SystemException)
111  {
112  _notifyConnectTimes.push_back(getNow());
113  return PortBase::notify_connect(connector_profile);
114  }
115 
116  virtual RTC::ReturnCode_t notify_disconnect(const char* connector_id)
117  throw (CORBA::SystemException)
118  {
119  _notifyDisconnectTimes.push_back(getNow());
120  return PortBase::notify_disconnect(connector_id);
121  }
122  void erase_m_profile(void)
123  {
124  CORBA_SeqUtil::erase(this->m_profile.connector_profiles, 0);
125  }
126 
127  protected:
128 
129  virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile& connector_profile)
130  {
131  _publishIfsTimes.push_back(getNow());
132  return RTC::RTC_OK;
133  }
134 
135  virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
136  {
137  _subscribeIfsTimes.push_back(getNow());
138  return RTC::RTC_OK;
139  }
140 
141  virtual void unsubscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
142  {
143  _unsubscribeIfsTimes.push_back(getNow());
144  }
145  virtual void activateInterfaces()
146  {
147  }
148  virtual void deactivateInterfaces()
149  {
150  }
151 
152  private:
153 
154  std::vector<timeval> _notifyConnectTimes;
155  std::vector<timeval> _notifyDisconnectTimes;
156  std::vector<timeval> _publishIfsTimes;
157  std::vector<timeval> _subscribeIfsTimes;
158  std::vector<timeval> _unsubscribeIfsTimes;
159 
160  private:
161 
162  timeval getNow() const
163  {
164  timeval now;
165  gettimeofday(&now, 0);
166  return now;
167  }
168 
169  public:
170 
171  const std::vector<timeval>& getNotifyConnectTimes() const
172  {
173  return _notifyConnectTimes;
174  }
175 
176  const std::vector<timeval>& getNotifyDisconnectTimes() const
177  {
178  return _notifyDisconnectTimes;
179  }
180 
181  const std::vector<timeval>& getPublishIfsTimes() const
182  {
183  return _publishIfsTimes;
184  }
185 
186  const std::vector<timeval>& getSubscribeIfsTimes() const
187  {
188  return _subscribeIfsTimes;
189  }
190 
191  const std::vector<timeval>& getUnsubscribeIfsTimes() const
192  {
193  return _unsubscribeIfsTimes;
194  }
195  };
196 
197 
198  int g_argc;
199  std::vector<std::string> g_argv;
200 
202  : public CppUnit::TestFixture
203  {
204  CPPUNIT_TEST_SUITE(PortBaseTests);
205 
206  CPPUNIT_TEST(test_get_port_profile);
207  CPPUNIT_TEST(test_getPortProfile);
208  CPPUNIT_TEST(test_get_connector_profiles);
209  CPPUNIT_TEST(test_get_connector_profile);
210  CPPUNIT_TEST(test_connect);
211  CPPUNIT_TEST(test_notify_connect);
212  CPPUNIT_TEST(test_disconnect);
213  CPPUNIT_TEST(test_setName);
214  CPPUNIT_TEST(test_getProfile);
215  CPPUNIT_TEST(test_setPortRef);
216  CPPUNIT_TEST(test_getPortRef);
217  CPPUNIT_TEST(test_getUUID);
218  CPPUNIT_TEST(test_disconnect_all);
219  CPPUNIT_TEST(test_setOwner);
220 
221  CPPUNIT_TEST_SUITE_END();
222 
223  private:
224 
225  CORBA::ORB_ptr m_orb;
229 
230  public:
237 
242  {
243  }
244 
249  {
250  }
251 
264  virtual void setUp()
265  {
266  char* argv[g_argc];
267  for (int i = 0; i < g_argc; i++) {
268  argv[i] = (char *)g_argv[i].c_str();
269  }
270 
271  // ORBの初期化
272  m_orb = CORBA::ORB_init(g_argc, argv);
273  PortableServer::POA_ptr poa = PortableServer::POA::_narrow(
274  m_orb->resolve_initial_references("RootPOA"));
275 
276  // PortProfile.interfacesの構築準備 RTC::PortInterfaceProfile portIfProfile; portIfProfile.instance_name = "PortInterfaceProfile-instance_name"; portIfProfile.type_name = "PortInterfaceProfile-type_name"; portIfProfile.polarity = RTC::REQUIRED; RTC::PortInterfaceProfileList portIfProfiles; portIfProfiles.length(1); portIfProfiles[0] = portIfProfile; // PortProfile.connector_profilesの構築準備 SDOPackage::NameValue connProfileProperty; connProfileProperty.name = "ConnectorProfile-properties0-name"; connProfileProperty.value <<= CORBA::Float(1.1); SDOPackage::NVList connProfileProperties; connProfileProperties.length(1); connProfileProperties[0] = connProfileProperty; RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id0"; connProfile.properties = connProfileProperties; RTC::ConnectorProfileList connProfiles; connProfiles.length(1); connProfiles[0] = connProfile; // PortProfile.propertiesの構築準備 SDOPackage::NameValue portProfileProperty; portProfileProperty.name = "PortProfile-properties0-name"; portProfileProperty.value <<= CORBA::Float(2.2); SDOPackage::NVList portProfileProperties; portProfileProperties.length(1); portProfileProperties[0] = portProfileProperty; // PortProfileを構築する RTC::PortProfile portProfile; portProfile.name = "inport0"; portProfile.interfaces = portIfProfiles; portProfile.connector_profiles = connProfiles; portProfile.properties = portProfileProperties; // PortBaseのインスタンスを生成する m_pPortBase = new PortBaseMock(portProfile); m_pPortBase_2 = new PortBaseMock(portProfile); m_pPortBase_3 = new PortBaseMock(portProfile); // POAを活性化する PortableServer::POAManager_var poaMgr = poa->the_POAManager(); poaMgr->activate(); m_on_publish = new ConnectionCallbackMock("OnPublishInterfaces"); m_on_subscribe = new ConnectionCallbackMock("OnSubscribeInterfaces"); m_on_connected = new ConnectionCallbackMock("OnConnected"); m_on_unsubscribe = new ConnectionCallbackMock("OnUnsubscribeInterfaces"); m_on_disconnected = new ConnectionCallbackMock("OnDisconnected"); m_on_connection_lost = new ConnectionCallbackMock("OnConnectionLost"); m_pPortBase->setOnPublishInterfaces(m_on_publish); m_pPortBase->setOnSubscribeInterfaces(m_on_subscribe); m_pPortBase->setOnConnected(m_on_connected); m_pPortBase->setOnUnsubscribeInterfaces(m_on_unsubscribe); m_pPortBase->setOnDisconnected(m_on_disconnected); m_pPortBase->setOnConnectionLost(m_on_connection_lost); } /*! * @brief Test finalization */ virtual void tearDown() { /* delete m_on_connection_lost; delete m_on_disconnected; delete m_on_unsubscribe; delete m_on_connected; delete m_on_subscribe; delete m_on_publish; delete m_pPortBase_3; delete m_pPortBase_2; delete m_pPortBase; */ //if (m_orb != 0) { // m_orb->destroy(); // m_orb = 0; // m_pPortBase = 0; // } } /*! * @brief get_port_profile()メソッドのテスト * * - オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_get_port_profile() { // (1) オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? // get_port_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::PortProfile* pPortProfile = portRef->get_port_profile(); // (2) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(pPortProfile->name)); // (3) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0]; // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (3-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (4) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0]; // (4-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (4-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (5) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(pPortProfile->properties[0].name)); { CORBA::Float value; pPortProfile->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief getPortProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getPortProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (4) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(portProfile.properties[0].name)); { CORBA::Float value; portProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief get_connector_profiles()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profiles() { // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
277  RTC::PortInterfaceProfile portIfProfile;
278  portIfProfile.instance_name = "PortInterfaceProfile-instance_name";
279  portIfProfile.type_name = "PortInterfaceProfile-type_name";
280  portIfProfile.polarity = RTC::REQUIRED;
281 
282  RTC::PortInterfaceProfileList portIfProfiles;
283  portIfProfiles.length(1);
284  portIfProfiles[0] = portIfProfile;
285 
286  // PortProfile.connector_profilesの構築準備 SDOPackage::NameValue connProfileProperty; connProfileProperty.name = "ConnectorProfile-properties0-name"; connProfileProperty.value <<= CORBA::Float(1.1); SDOPackage::NVList connProfileProperties; connProfileProperties.length(1); connProfileProperties[0] = connProfileProperty; RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id0"; connProfile.properties = connProfileProperties; RTC::ConnectorProfileList connProfiles; connProfiles.length(1); connProfiles[0] = connProfile; // PortProfile.propertiesの構築準備 SDOPackage::NameValue portProfileProperty; portProfileProperty.name = "PortProfile-properties0-name"; portProfileProperty.value <<= CORBA::Float(2.2); SDOPackage::NVList portProfileProperties; portProfileProperties.length(1); portProfileProperties[0] = portProfileProperty; // PortProfileを構築する RTC::PortProfile portProfile; portProfile.name = "inport0"; portProfile.interfaces = portIfProfiles; portProfile.connector_profiles = connProfiles; portProfile.properties = portProfileProperties; // PortBaseのインスタンスを生成する m_pPortBase = new PortBaseMock(portProfile); m_pPortBase_2 = new PortBaseMock(portProfile); m_pPortBase_3 = new PortBaseMock(portProfile); // POAを活性化する PortableServer::POAManager_var poaMgr = poa->the_POAManager(); poaMgr->activate(); m_on_publish = new ConnectionCallbackMock("OnPublishInterfaces"); m_on_subscribe = new ConnectionCallbackMock("OnSubscribeInterfaces"); m_on_connected = new ConnectionCallbackMock("OnConnected"); m_on_unsubscribe = new ConnectionCallbackMock("OnUnsubscribeInterfaces"); m_on_disconnected = new ConnectionCallbackMock("OnDisconnected"); m_on_connection_lost = new ConnectionCallbackMock("OnConnectionLost"); m_pPortBase->setOnPublishInterfaces(m_on_publish); m_pPortBase->setOnSubscribeInterfaces(m_on_subscribe); m_pPortBase->setOnConnected(m_on_connected); m_pPortBase->setOnUnsubscribeInterfaces(m_on_unsubscribe); m_pPortBase->setOnDisconnected(m_on_disconnected); m_pPortBase->setOnConnectionLost(m_on_connection_lost); } /*! * @brief Test finalization */ virtual void tearDown() { /* delete m_on_connection_lost; delete m_on_disconnected; delete m_on_unsubscribe; delete m_on_connected; delete m_on_subscribe; delete m_on_publish; delete m_pPortBase_3; delete m_pPortBase_2; delete m_pPortBase; */ //if (m_orb != 0) { // m_orb->destroy(); // m_orb = 0; // m_pPortBase = 0; // } } /*! * @brief get_port_profile()メソッドのテスト * * - オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_get_port_profile() { // (1) オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? // get_port_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::PortProfile* pPortProfile = portRef->get_port_profile(); // (2) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(pPortProfile->name)); // (3) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0]; // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (3-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (4) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0]; // (4-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (4-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (5) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(pPortProfile->properties[0].name)); { CORBA::Float value; pPortProfile->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief getPortProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getPortProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (4) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(portProfile.properties[0].name)); { CORBA::Float value; portProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief get_connector_profiles()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profiles() { // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
287  SDOPackage::NameValue connProfileProperty;
288  connProfileProperty.name = "ConnectorProfile-properties0-name";
289  connProfileProperty.value <<= CORBA::Float(1.1);
290 
291  SDOPackage::NVList connProfileProperties;
292  connProfileProperties.length(1);
293  connProfileProperties[0] = connProfileProperty;
294  RTC::ConnectorProfile connProfile;
295  connProfile.name = "ConnectorProfile-name";
296  connProfile.connector_id = "connect_id0";
297  connProfile.properties = connProfileProperties;
298 
299  RTC::ConnectorProfileList connProfiles;
300  connProfiles.length(1);
301  connProfiles[0] = connProfile;
302 
303  // PortProfile.propertiesの構築準備 SDOPackage::NameValue portProfileProperty; portProfileProperty.name = "PortProfile-properties0-name"; portProfileProperty.value <<= CORBA::Float(2.2); SDOPackage::NVList portProfileProperties; portProfileProperties.length(1); portProfileProperties[0] = portProfileProperty; // PortProfileを構築する RTC::PortProfile portProfile; portProfile.name = "inport0"; portProfile.interfaces = portIfProfiles; portProfile.connector_profiles = connProfiles; portProfile.properties = portProfileProperties; // PortBaseのインスタンスを生成する m_pPortBase = new PortBaseMock(portProfile); m_pPortBase_2 = new PortBaseMock(portProfile); m_pPortBase_3 = new PortBaseMock(portProfile); // POAを活性化する PortableServer::POAManager_var poaMgr = poa->the_POAManager(); poaMgr->activate(); m_on_publish = new ConnectionCallbackMock("OnPublishInterfaces"); m_on_subscribe = new ConnectionCallbackMock("OnSubscribeInterfaces"); m_on_connected = new ConnectionCallbackMock("OnConnected"); m_on_unsubscribe = new ConnectionCallbackMock("OnUnsubscribeInterfaces"); m_on_disconnected = new ConnectionCallbackMock("OnDisconnected"); m_on_connection_lost = new ConnectionCallbackMock("OnConnectionLost"); m_pPortBase->setOnPublishInterfaces(m_on_publish); m_pPortBase->setOnSubscribeInterfaces(m_on_subscribe); m_pPortBase->setOnConnected(m_on_connected); m_pPortBase->setOnUnsubscribeInterfaces(m_on_unsubscribe); m_pPortBase->setOnDisconnected(m_on_disconnected); m_pPortBase->setOnConnectionLost(m_on_connection_lost); } /*! * @brief Test finalization */ virtual void tearDown() { /* delete m_on_connection_lost; delete m_on_disconnected; delete m_on_unsubscribe; delete m_on_connected; delete m_on_subscribe; delete m_on_publish; delete m_pPortBase_3; delete m_pPortBase_2; delete m_pPortBase; */ //if (m_orb != 0) { // m_orb->destroy(); // m_orb = 0; // m_pPortBase = 0; // } } /*! * @brief get_port_profile()メソッドのテスト * * - オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_get_port_profile() { // (1) オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? // get_port_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::PortProfile* pPortProfile = portRef->get_port_profile(); // (2) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(pPortProfile->name)); // (3) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0]; // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (3-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (4) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0]; // (4-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (4-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (5) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(pPortProfile->properties[0].name)); { CORBA::Float value; pPortProfile->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief getPortProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getPortProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (4) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(portProfile.properties[0].name)); { CORBA::Float value; portProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief get_connector_profiles()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profiles() { // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
304  SDOPackage::NameValue portProfileProperty;
305  portProfileProperty.name = "PortProfile-properties0-name";
306  portProfileProperty.value <<= CORBA::Float(2.2);
307  SDOPackage::NVList portProfileProperties;
308  portProfileProperties.length(1);
309  portProfileProperties[0] = portProfileProperty;
310 
311  // PortProfileを構築する RTC::PortProfile portProfile; portProfile.name = "inport0"; portProfile.interfaces = portIfProfiles; portProfile.connector_profiles = connProfiles; portProfile.properties = portProfileProperties; // PortBaseのインスタンスを生成する m_pPortBase = new PortBaseMock(portProfile); m_pPortBase_2 = new PortBaseMock(portProfile); m_pPortBase_3 = new PortBaseMock(portProfile); // POAを活性化する PortableServer::POAManager_var poaMgr = poa->the_POAManager(); poaMgr->activate(); m_on_publish = new ConnectionCallbackMock("OnPublishInterfaces"); m_on_subscribe = new ConnectionCallbackMock("OnSubscribeInterfaces"); m_on_connected = new ConnectionCallbackMock("OnConnected"); m_on_unsubscribe = new ConnectionCallbackMock("OnUnsubscribeInterfaces"); m_on_disconnected = new ConnectionCallbackMock("OnDisconnected"); m_on_connection_lost = new ConnectionCallbackMock("OnConnectionLost"); m_pPortBase->setOnPublishInterfaces(m_on_publish); m_pPortBase->setOnSubscribeInterfaces(m_on_subscribe); m_pPortBase->setOnConnected(m_on_connected); m_pPortBase->setOnUnsubscribeInterfaces(m_on_unsubscribe); m_pPortBase->setOnDisconnected(m_on_disconnected); m_pPortBase->setOnConnectionLost(m_on_connection_lost); } /*! * @brief Test finalization */ virtual void tearDown() { /* delete m_on_connection_lost; delete m_on_disconnected; delete m_on_unsubscribe; delete m_on_connected; delete m_on_subscribe; delete m_on_publish; delete m_pPortBase_3; delete m_pPortBase_2; delete m_pPortBase; */ //if (m_orb != 0) { // m_orb->destroy(); // m_orb = 0; // m_pPortBase = 0; // } } /*! * @brief get_port_profile()メソッドのテスト * * - オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_get_port_profile() { // (1) オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? // get_port_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::PortProfile* pPortProfile = portRef->get_port_profile(); // (2) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(pPortProfile->name)); // (3) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0]; // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (3-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (4) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0]; // (4-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (4-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (5) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(pPortProfile->properties[0].name)); { CORBA::Float value; pPortProfile->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief getPortProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getPortProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (4) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(portProfile.properties[0].name)); { CORBA::Float value; portProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief get_connector_profiles()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profiles() { // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
312  RTC::PortProfile portProfile;
313  portProfile.name = "inport0";
314  portProfile.interfaces = portIfProfiles;
315  portProfile.connector_profiles = connProfiles;
316  portProfile.properties = portProfileProperties;
317 
318  // PortBaseのインスタンスを生成する m_pPortBase = new PortBaseMock(portProfile); m_pPortBase_2 = new PortBaseMock(portProfile); m_pPortBase_3 = new PortBaseMock(portProfile); // POAを活性化する PortableServer::POAManager_var poaMgr = poa->the_POAManager(); poaMgr->activate(); m_on_publish = new ConnectionCallbackMock("OnPublishInterfaces"); m_on_subscribe = new ConnectionCallbackMock("OnSubscribeInterfaces"); m_on_connected = new ConnectionCallbackMock("OnConnected"); m_on_unsubscribe = new ConnectionCallbackMock("OnUnsubscribeInterfaces"); m_on_disconnected = new ConnectionCallbackMock("OnDisconnected"); m_on_connection_lost = new ConnectionCallbackMock("OnConnectionLost"); m_pPortBase->setOnPublishInterfaces(m_on_publish); m_pPortBase->setOnSubscribeInterfaces(m_on_subscribe); m_pPortBase->setOnConnected(m_on_connected); m_pPortBase->setOnUnsubscribeInterfaces(m_on_unsubscribe); m_pPortBase->setOnDisconnected(m_on_disconnected); m_pPortBase->setOnConnectionLost(m_on_connection_lost); } /*! * @brief Test finalization */ virtual void tearDown() { /* delete m_on_connection_lost; delete m_on_disconnected; delete m_on_unsubscribe; delete m_on_connected; delete m_on_subscribe; delete m_on_publish; delete m_pPortBase_3; delete m_pPortBase_2; delete m_pPortBase; */ //if (m_orb != 0) { // m_orb->destroy(); // m_orb = 0; // m_pPortBase = 0; // } } /*! * @brief get_port_profile()メソッドのテスト * * - オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_get_port_profile() { // (1) オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか? // get_port_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::PortProfile* pPortProfile = portRef->get_port_profile(); // (2) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(pPortProfile->name)); // (3) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0]; // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (3-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (4) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0]; // (4-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (4-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (5) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(pPortProfile->properties[0].name)); { CORBA::Float value; pPortProfile->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief getPortProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getPortProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (4) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(portProfile.properties[0].name)); { CORBA::Float value; portProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief get_connector_profiles()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profiles() { // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
319  m_pPortBase = new PortBaseMock(portProfile);
320  m_pPortBase_2 = new PortBaseMock(portProfile);
321  m_pPortBase_3 = new PortBaseMock(portProfile);
322 
323  // POAを活性化する
324  PortableServer::POAManager_var poaMgr = poa->the_POAManager();
325  poaMgr->activate();
326 
327  m_on_publish = new ConnectionCallbackMock("OnPublishInterfaces");
328  m_on_subscribe = new ConnectionCallbackMock("OnSubscribeInterfaces");
329  m_on_connected = new ConnectionCallbackMock("OnConnected");
330  m_on_unsubscribe = new ConnectionCallbackMock("OnUnsubscribeInterfaces");
331  m_on_disconnected = new ConnectionCallbackMock("OnDisconnected");
332  m_on_connection_lost = new ConnectionCallbackMock("OnConnectionLost");
333 
334  m_pPortBase->setOnPublishInterfaces(m_on_publish);
335  m_pPortBase->setOnSubscribeInterfaces(m_on_subscribe);
336  m_pPortBase->setOnConnected(m_on_connected);
337  m_pPortBase->setOnUnsubscribeInterfaces(m_on_unsubscribe);
338  m_pPortBase->setOnDisconnected(m_on_disconnected);
339  m_pPortBase->setOnConnectionLost(m_on_connection_lost);
340 
341  }
342 
346  virtual void tearDown()
347  {
348 /*
349  delete m_on_connection_lost;
350  delete m_on_disconnected;
351  delete m_on_unsubscribe;
352  delete m_on_connected;
353  delete m_on_subscribe;
354  delete m_on_publish;
355  delete m_pPortBase_3;
356  delete m_pPortBase_2;
357  delete m_pPortBase;
358 */
359  //if (m_orb != 0) {
360  // m_orb->destroy();
361  // m_orb = 0;
362  // m_pPortBase = 0;
363  // }
364  }
365 
376  {
377  // (1) オブジェクト参照経由で、get_port_profile()に正しくアクセスできるか?
378  // get_port_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、
379  // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::PortProfile* pPortProfile = portRef->get_port_profile(); // (2) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(pPortProfile->name)); // (3) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0]; // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (3-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (4) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0]; // (4-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (4-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (5) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(pPortProfile->properties[0].name)); { CORBA::Float value; pPortProfile->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief getPortProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfaceを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getPortProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfaceを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(connProfile.properties[0].name)); { CORBA::Float value; connProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } // (4) PortProfile.propertiesを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(portProfile.properties[0].name)); { CORBA::Float value; portProfile.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } /*! * @brief get_connector_profiles()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profiles() { // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか? // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
380  const RTC::PortService_ptr portRef = m_pPortBase->getPortRef();
381  const RTC::PortProfile* pPortProfile = portRef->get_port_profile();
382 
383  // (2) PortProfile.nameを正しく取得できるか?
384  CPPUNIT_ASSERT_EQUAL(
385  std::string("inport0"),
386  std::string(pPortProfile->name));
387 
388  // (3) PortProfile.interfaceを正しく取得できるか?
389  const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0];
390  // (3-a) PortInterfaceProfile.instance_nameを正しく取得できるか?
391  CPPUNIT_ASSERT_EQUAL(
392  std::string("PortInterfaceProfile-instance_name"),
393  std::string(portIfProfile.instance_name));
394 
395  // (3-b) PortInterfaceProfile.type_nameを正しく取得できるか?
396  CPPUNIT_ASSERT_EQUAL(
397  std::string("PortInterfaceProfile-type_name"),
398  std::string(portIfProfile.type_name));
399 
400  // (3-c) PortInterfaceProfile.polarityを正しく取得できるか?
401  CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity);
402 
403  // (4) PortProfile.connector_profilesを正しく取得できるか?
404  const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0];
405  // (4-a) ConnectorProfile.nameを正しく取得できるか?
406  CPPUNIT_ASSERT_EQUAL(
407  std::string("ConnectorProfile-name"),
408  std::string(connProfile.name));
409 
410  // (4-b) ConnectorProfile.connector_idを正しく取得できるか?
411  CPPUNIT_ASSERT_EQUAL(
412  std::string("connect_id0"),
413  std::string(connProfile.connector_id));
414 
415  // (4-c) ConnectorProfile.propertiesを正しく取得できるか?
416  CPPUNIT_ASSERT_EQUAL(
417  std::string("ConnectorProfile-properties0-name"),
418  std::string(connProfile.properties[0].name));
419 
420  {
421  CORBA::Float value;
422  connProfile.properties[0].value >>= value;
423  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
424  }
425 
426  // (5) PortProfile.propertiesを正しく取得できるか?
427  CPPUNIT_ASSERT_EQUAL(
428  std::string("PortProfile-properties0-name"),
429  std::string(pPortProfile->properties[0].name));
430 
431  {
432  CORBA::Float value;
433  pPortProfile->properties[0].value >>= value;
434  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value);
435  }
436  }
437 
447  {
448  const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile();
449 
450  // (1) PortProfile.nameを正しく取得できるか?
451  CPPUNIT_ASSERT_EQUAL(
452  std::string("inport0"),
453  std::string(portProfile.name));
454 
455  // (2) PortProfile.interfaceを正しく取得できるか?
456  const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0];
457  // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか?
458  CPPUNIT_ASSERT_EQUAL(
459  std::string("PortInterfaceProfile-instance_name"),
460  std::string(portIfProfile.instance_name));
461 
462  // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか?
463  CPPUNIT_ASSERT_EQUAL(
464  std::string("PortInterfaceProfile-type_name"),
465  std::string(portIfProfile.type_name));
466 
467  // (2-c) PortInterfaceProfile.polarityを正しく取得できるか?
468  CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity);
469 
470  // (3) PortProfile.connector_profilesを正しく取得できるか?
471  const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0];
472  // (3-a) ConnectorProfile.nameを正しく取得できるか?
473  CPPUNIT_ASSERT_EQUAL(
474  std::string("ConnectorProfile-name"),
475  std::string(connProfile.name));
476 
477  // (3-b) ConnectorProfile.connector_idを正しく取得できるか?
478  CPPUNIT_ASSERT_EQUAL(
479  std::string("connect_id0"),
480  std::string(connProfile.connector_id));
481 
482  // (3-c) ConnectorProfile.propertiesを正しく取得できるか?
483  CPPUNIT_ASSERT_EQUAL(
484  std::string("ConnectorProfile-properties0-name"),
485  std::string(connProfile.properties[0].name));
486 
487  {
488  CORBA::Float value;
489  connProfile.properties[0].value >>= value;
490  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
491  }
492 
493  // (4) PortProfile.propertiesを正しく取得できるか?
494  CPPUNIT_ASSERT_EQUAL(
495  std::string("PortProfile-properties0-name"),
496  std::string(portProfile.properties[0].name));
497 
498  {
499  CORBA::Float value;
500  portProfile.properties[0].value >>= value;
501  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value);
502  }
503  }
504 
514  {
515  // (1) オブジェクト参照経由で、get_connector_profiles()に正しくアクセスできるか?
516  // get_connector_profiles()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、
517  // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles(); // ConnectorProfileList内のConnectorProfileのチェック const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0]; // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = connProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief get_connector_profile()メソッドのテスト * * - オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? * - ConnectorProfile.nameを正しく取得できるか? * - ConnectorProfile.connector_idを正しく取得できるか? * - ConnectorProfile.propertiesを正しく取得できるか? */ void test_get_connector_profile() { // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか? // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
518  const RTC::PortService_ptr portRef = m_pPortBase->getPortRef();
519  const RTC::ConnectorProfileList* pConnProfList = portRef->get_connector_profiles();
520 
521  // ConnectorProfileList内のConnectorProfileのチェック
522  const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0];
523  // (2) ConnectorProfile.nameを正しく取得できるか?
524  CPPUNIT_ASSERT_EQUAL(
525  std::string("ConnectorProfile-name"),
526  std::string(connProfile.name));
527 
528  // (3) ConnectorProfile.connector_idを正しく取得できるか?
529  CPPUNIT_ASSERT_EQUAL(
530  std::string("connect_id0"),
531  std::string(connProfile.connector_id));
532 
533  // (4) ConnectorProfile.propertiesを正しく取得できるか?
534  const SDOPackage::NameValue& property = connProfile.properties[0];
535  // (4-a) nameを正しく取得できるか?
536  CPPUNIT_ASSERT_EQUAL(
537  std::string("ConnectorProfile-properties0-name"),
538  std::string(property.name));
539 
540  // (4-b) valueを正しく取得できるか?
541  {
542  CORBA::Float value;
543  property.value >>= value;
544  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
545  }
546  }
547 
557  {
558  // (1) オブジェクト参照経由で、get_connector_profile()に正しくアクセスできるか?
559  // get_connector_profile()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、
560  // CORBAインタフェースとして機能していることを確認する const RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0"); // (2) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(pConnProfile->name)); // (3) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(pConnProfile->connector_id)); // (4) ConnectorProfile.propertiesを正しく取得できるか? const SDOPackage::NameValue& property = pConnProfile->properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } /*! * @brief connect()メソッドのテスト * * - オブジェクト参照経由で、connect()に正しくアクセスできるか? * - 接続が成功するか? * - 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? */ void test_connect() { // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか? // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
561  const RTC::PortService_ptr portRef = m_pPortBase->getPortRef();
562  const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile("connect_id0");
563 
564  // (2) ConnectorProfile.nameを正しく取得できるか?
565  CPPUNIT_ASSERT_EQUAL(
566  std::string("ConnectorProfile-name"),
567  std::string(pConnProfile->name));
568 
569  // (3) ConnectorProfile.connector_idを正しく取得できるか?
570  CPPUNIT_ASSERT_EQUAL(
571  std::string("connect_id0"),
572  std::string(pConnProfile->connector_id));
573 
574  // (4) ConnectorProfile.propertiesを正しく取得できるか?
575  const SDOPackage::NameValue& property = pConnProfile->properties[0];
576  // (4-a) nameを正しく取得できるか?
577  CPPUNIT_ASSERT_EQUAL(
578  std::string("ConnectorProfile-properties0-name"),
579  std::string(property.name));
580 
581  // (4-b) valueを正しく取得できるか?
582  {
583  CORBA::Float value;
584  property.value >>= value;
585  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
586  }
587  }
588 
597  {
598  // (1) オブジェクト参照経由で、connect()に正しくアクセスできるか?
599  // connect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、
600  // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
601  RTC::PortService_ptr portRef = m_pPortBase->getPortRef();
602 
603  // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id1"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // (2) 接続が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size()); } /*! * @brief notify_connect()メソッドのテスト */ void test_notify_connect() { // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
604  RTC::ConnectorProfile connProfile;
605  connProfile.name = "ConnectorProfile-name";
606  connProfile.connector_id = "connect_id1";
607  connProfile.ports.length(1);
608  connProfile.ports[0] = portRef;
609 
610  // (2) 接続が成功するか?
611  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile));
612 
613  // (3) 接続時にnotify_connect()が意図どおりに1回だけ呼び出されたか?
614  const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase);
615  CPPUNIT_ASSERT(pPortBaseMock != 0);
616  CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyConnectTimes().size());
617  }
618 
623  {
624  // notify_connect()メソッドは、test_connectにて間接的にテストされているので、ここではテスト不要である } /*! * @brief disconnect()メソッドのテスト * * - オブジェクト参照経由で、disconnect()に正しくアクセスできるか? * - 切断が成功するか? * - 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? */ void test_disconnect() { // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか? // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、 // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
625  }
626 
635  {
636  // (1) オブジェクト参照経由で、disconnect()に正しくアクセスできるか?
637  // disconnect()はCORBAインタフェースなので、オブジェクト参照経由でアクセスし、
638  // CORBAインタフェースとして機能していることを確認する RTC::PortService_ptr portRef = m_pPortBase->getPortRef(); // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
639  RTC::PortService_ptr portRef = m_pPortBase->getPortRef();
640 
641  // 接続時に必要となるConnectorProfileを構築する RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id2"; connProfile.ports.length(1); connProfile.ports[0] = portRef; // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
642  RTC::ConnectorProfile connProfile;
643  connProfile.name = "ConnectorProfile-name";
644  connProfile.connector_id = "connect_id2";
645  connProfile.ports.length(1);
646  connProfile.ports[0] = portRef;
647 
648  // まずは接続する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile)); // (2) 切断が成功するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id)); // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか? const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock != 0); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size()); } void test_disconnect_all() { RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef(); RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef(); RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef(); // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
649  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->connect(connProfile));
650 
651  // (2) 切断が成功するか?
652  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef->disconnect(connProfile.connector_id));
653 
654  // (3) 切断時にnotify_disconnect()が、意図どおり1回だけ呼び出されているか?
655  const PortBaseMock* pPortBaseMock = dynamic_cast<const PortBaseMock*>(m_pPortBase);
656  CPPUNIT_ASSERT(pPortBaseMock != 0);
657  CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock->getNotifyDisconnectTimes().size());
658  }
659 
661  {
662  RTC::PortService_ptr portRef_1 = m_pPortBase->getPortRef();
663  RTC::PortService_ptr portRef_2 = m_pPortBase_2->getPortRef();
664  RTC::PortService_ptr portRef_3 = m_pPortBase_3->getPortRef();
665 
666  // ここでは、 setUp() の PortBaseMockのコンストラクタ内で // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
667  // テストの為設定されている connect_id0 は不要なため削除する // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
668  // connect_id0 は // get_port_profile(),getPortProfile(),get_connector_profiles() // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
669  // get_port_profile(),getPortProfile(),get_connector_profiles()
670  // のテストで使用している PortBaseMock* pPBMock = dynamic_cast<PortBaseMock*>(m_pPortBase); pPBMock->erase_m_profile(); RTC::ConnectorProfile connProfile; connProfile.name = "ConnectorProfile-name"; connProfile.connector_id = "connect_id3"; connProfile.ports.length(3); connProfile.ports[0] = portRef_1; connProfile.ports[1] = portRef_2; connProfile.ports[2] = portRef_3; const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBaseMock_1 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2); CPPUNIT_ASSERT(pPortBaseMock_2 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3); CPPUNIT_ASSERT(pPortBaseMock_3 != 0); CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile)); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size()); CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size()); } /*! * @brief setName()メソッドのテスト * * - setName()により、意図どおりにPortProfile.nameが書き換えられているか? */ void test_setName() { // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
671  PortBaseMock* pPBMock
672  = dynamic_cast<PortBaseMock*>(m_pPortBase);
673  pPBMock->erase_m_profile();
674 
675 
676  RTC::ConnectorProfile connProfile;
677  connProfile.name = "ConnectorProfile-name";
678  connProfile.connector_id = "connect_id3";
679  connProfile.ports.length(3);
680  connProfile.ports[0] = portRef_1;
681  connProfile.ports[1] = portRef_2;
682  connProfile.ports[2] = portRef_3;
683 
684  const PortBaseMock* pPortBaseMock_1 = dynamic_cast<const PortBaseMock*>(m_pPortBase);
685  CPPUNIT_ASSERT(pPortBaseMock_1 != 0);
686  CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size());
687  const PortBaseMock* pPortBaseMock_2 = dynamic_cast<const PortBaseMock*>(m_pPortBase_2);
688  CPPUNIT_ASSERT(pPortBaseMock_2 != 0);
689  CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size());
690  const PortBaseMock* pPortBaseMock_3 = dynamic_cast<const PortBaseMock*>(m_pPortBase_3);
691  CPPUNIT_ASSERT(pPortBaseMock_3 != 0);
692  CPPUNIT_ASSERT_EQUAL(0, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size());
693  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->connect(connProfile));
694  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, portRef_1->disconnect_all());
695  CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_1->getNotifyDisconnectTimes().size());
696  CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_2->getNotifyDisconnectTimes().size());
697  CPPUNIT_ASSERT_EQUAL(1, (int) pPortBaseMock_3->getNotifyDisconnectTimes().size());
698 
699  }
700 
707  {
708  // setName()を用いて、PortProfile.nameを書き換える m_pPortBase->setName("inport0-changed"); // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
709  m_pPortBase->setName("inport0-changed");
710 
711  // setName()を用いて、PortProfile.nameを書き換える std::string str(m_pPortBase->getName()); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str); // setName()により、意図どおりにPortProfile.nameが書き換えられているか? const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile(); CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name)); } /*! * @brief getProfile()メソッドのテスト * * - PortProfile.nameを正しく取得できるか? * - PortProfile.interfacesを正しく取得できるか? * - PortProfile.connector_profilesを正しく取得できるか? * - PortProfile.propertiesを正しく取得できるか? */ void test_getProfile() { const RTC::PortProfile& portProfile = m_pPortBase->getProfile(); // (1) PortProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name)); // (2) PortProfile.interfacesを正しく取得できるか? const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0]; // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-instance_name"), std::string(portIfProfile.instance_name)); // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortInterfaceProfile-type_name"), std::string(portIfProfile.type_name)); // (2-c) PortInterfaceProfile.polarityを正しく取得できるか? CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity); // (3) PortProfile.connector_profilesを正しく取得できるか? const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0]; // (3-a) ConnectorProfile.nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-name"), std::string(connProfile.name)); // (3-b) ConnectorProfile.connector_idを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("connect_id0"), std::string(connProfile.connector_id)); // (3-c) ConnectorPofile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = connProfile.properties[0]; // (3-c-1) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("ConnectorProfile-properties0-name"), std::string(property.name)); // (3-c-2) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value); } } // (4) PortProfile.propertiesを正しく取得できるか? { const SDOPackage::NameValue& property = portProfile.properties[0]; // (4-a) nameを正しく取得できるか? CPPUNIT_ASSERT_EQUAL( std::string("PortProfile-properties0-name"), std::string(property.name)); // (4-b) valueを正しく取得できるか? { CORBA::Float value; property.value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value); } } } /*! * @brief setPortRef()メソッドのテスト * * - setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? */ void test_setPortRef() { // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく m_pPortBase->_remove_ref(); // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか? // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、 // 取得した参照が、あらかじめ設定した参照と一致することを確認する) RTC::PortService_var port = m_pPortBase->_this(); RTC::PortService_ptr portRef = port._retn(); m_pPortBase->setPortRef(portRef); CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef()); } /*! * @brief getPortRef()メソッドのテスト */ void test_getPortRef() { // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
712  std::string str(m_pPortBase->getName());
713  CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), str);
714 
715  // setName()により、意図どおりにPortProfile.nameが書き換えられているか?
716  const RTC::PortProfile& portProfile = m_pPortBase->getPortProfile();
717  CPPUNIT_ASSERT_EQUAL(std::string("inport0-changed"), std::string(portProfile.name));
718  }
719 
729  {
730  const RTC::PortProfile& portProfile = m_pPortBase->getProfile();
731 
732  // (1) PortProfile.nameを正しく取得できるか?
733  CPPUNIT_ASSERT_EQUAL(std::string("inport0"), std::string(portProfile.name));
734 
735  // (2) PortProfile.interfacesを正しく取得できるか?
736  const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0];
737  // (2-a) PortInterfaceProfile.instance_nameを正しく取得できるか?
738  CPPUNIT_ASSERT_EQUAL(
739  std::string("PortInterfaceProfile-instance_name"),
740  std::string(portIfProfile.instance_name));
741 
742  // (2-b) PortInterfaceProfile.type_nameを正しく取得できるか?
743  CPPUNIT_ASSERT_EQUAL(
744  std::string("PortInterfaceProfile-type_name"),
745  std::string(portIfProfile.type_name));
746 
747  // (2-c) PortInterfaceProfile.polarityを正しく取得できるか?
748  CPPUNIT_ASSERT_EQUAL(RTC::REQUIRED, portIfProfile.polarity);
749 
750  // (3) PortProfile.connector_profilesを正しく取得できるか?
751  const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0];
752  // (3-a) ConnectorProfile.nameを正しく取得できるか?
753  CPPUNIT_ASSERT_EQUAL(
754  std::string("ConnectorProfile-name"),
755  std::string(connProfile.name));
756 
757  // (3-b) ConnectorProfile.connector_idを正しく取得できるか?
758  CPPUNIT_ASSERT_EQUAL(
759  std::string("connect_id0"),
760  std::string(connProfile.connector_id));
761 
762  // (3-c) ConnectorPofile.propertiesを正しく取得できるか?
763  {
764  const SDOPackage::NameValue& property = connProfile.properties[0];
765  // (3-c-1) nameを正しく取得できるか?
766  CPPUNIT_ASSERT_EQUAL(
767  std::string("ConnectorProfile-properties0-name"),
768  std::string(property.name));
769 
770  // (3-c-2) valueを正しく取得できるか?
771  {
772  CORBA::Float value;
773  property.value >>= value;
774  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
775  }
776  }
777 
778  // (4) PortProfile.propertiesを正しく取得できるか?
779  {
780  const SDOPackage::NameValue& property = portProfile.properties[0];
781  // (4-a) nameを正しく取得できるか?
782  CPPUNIT_ASSERT_EQUAL(
783  std::string("PortProfile-properties0-name"),
784  std::string(property.name));
785 
786  // (4-b) valueを正しく取得できるか?
787  {
788  CORBA::Float value;
789  property.value >>= value;
790  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value);
791  }
792  }
793  }
794 
801  {
802  // 一旦、設定済みのPortBaseオブジェクト参照をリセットしておく
803  m_pPortBase->_remove_ref();
804 
805  // setPortRef()を用いて、PortBaseオブジェクト参照を正しく設定できるか?
806  // (getPortRef()を用いて、Portインタフェースのオブジェクト参照を取得し、
807  // 取得した参照が、あらかじめ設定した参照と一致することを確認する)
808  RTC::PortService_var port = m_pPortBase->_this();
809  RTC::PortService_ptr portRef = port._retn();
810  m_pPortBase->setPortRef(portRef);
811 
812  CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->getPortRef());
813  }
814 
819  {
820  // test_setPortRef()によりテストされている } /*! * @brief getUUID()メソッドのテスト * * - UUIDを取得できるか?(空文字列でないかどうかのみでチェック) */ void test_getUUID() { // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
821  }
822 
829  {
830  // getUUID()メソッドはprotectedであるため、PortBaseMockにダウンキャストしてからアクセスする PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase); CPPUNIT_ASSERT(pPortBase != 0); // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
831  PortBaseMock* pPortBase = dynamic_cast<PortBaseMock*>(m_pPortBase);
832  CPPUNIT_ASSERT(pPortBase != 0);
833 
834  // UUIDを取得できるか?(空文字列でないかどうかのみでチェック) std::string uuid = pPortBase->getUUID(); CPPUNIT_ASSERT(uuid.length() > 0); //std::cout << std::endl << "uuid: " << uuid << std::endl; } /*! * @brief setOwner()メソッドのテスト * */ void test_setOwner() { PortableServer::POA_ptr poa = PortableServer::POA::_narrow( m_orb->resolve_initial_references("RootPOA")); RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa); RTC::RTObject_ptr owner = obj->getObjRef(); RTC::PortProfile portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner)); m_pPortBase->setOwner(owner); portprofile = m_pPortBase->getProfile(); CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner)); poa->the_POAManager()->deactivate(false, true); obj->finalize(); delete obj; } }; }; // namespace PortBase /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests); #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 // PortBase_cpp
835  std::string uuid = pPortBase->getUUID();
836  CPPUNIT_ASSERT(uuid.length() > 0);
837  //std::cout << std::endl << "uuid: " << uuid << std::endl;
838  }
844  {
845  PortableServer::POA_ptr poa = PortableServer::POA::_narrow(
846  m_orb->resolve_initial_references("RootPOA"));
847  RTC::RTObject_impl* obj = new RTC::RTObject_impl(m_orb,poa);
848  RTC::RTObject_ptr owner = obj->getObjRef();
849  RTC::PortProfile portprofile = m_pPortBase->getProfile();
850  CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner));
851  m_pPortBase->setOwner(owner);
852  portprofile = m_pPortBase->getProfile();
853  CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner));
854 
855  poa->the_POAManager()->deactivate(false, true);
856  obj->finalize();
857  delete obj;
858  }
859  };
860 }; // namespace PortBase
861 
862 /*
863  * Register test suite
864  */
866 
867 #ifdef LOCAL_MAIN
868 int main(int argc, char* argv[])
869 {
870 
871  FORMAT format = TEXT_OUT;
872  int target = 0;
873  std::string xsl;
874  std::string ns;
875  std::string fname;
876  std::ofstream ofs;
877 
878  int i(1);
879  while (i < argc)
880  {
881  std::string arg(argv[i]);
882  std::string next_arg;
883  if (i + 1 < argc) next_arg = argv[i + 1];
884  else next_arg = "";
885 
886  if (arg == "--text") { format = TEXT_OUT; break; }
887  if (arg == "--xml")
888  {
889  if (next_arg == "")
890  {
891  fname = argv[0];
892  fname += ".xml";
893  }
894  else
895  {
896  fname = next_arg;
897  }
898  format = XML_OUT;
899  ofs.open(fname.c_str());
900  }
901  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
902  if ( arg == "--cerr" ) { target = 1; break; }
903  if ( arg == "--xsl" )
904  {
905  if (next_arg == "") xsl = "default.xsl";
906  else xsl = next_arg;
907  }
908  if ( arg == "--namespace" )
909  {
910  if (next_arg == "")
911  {
912  std::cerr << "no namespace specified" << std::endl;
913  exit(1);
914  }
915  else
916  {
917  xsl = next_arg;
918  }
919  }
920  ++i;
921  }
922  CppUnit::TextUi::TestRunner runner;
923  if ( ns.empty() )
924  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
925  else
926  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
927  CppUnit::Outputter* outputter = 0;
928  std::ostream* stream = target ? &std::cerr : &std::cout;
929  switch ( format )
930  {
931  case TEXT_OUT :
932  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
933  break;
934  case XML_OUT :
935  std::cout << "XML_OUT" << std::endl;
936  outputter = new CppUnit::XmlOutputter(&runner.result(),
937  ofs, "shift_jis");
938  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
939  break;
940  case COMPILER_OUT :
941  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
942  break;
943  }
944  runner.setOutputter(outputter);
945  runner.run();
946  return 0; // runner.run() ? 0 : 1;
947 }
948 #endif // MAIN
949 #endif // PortBase_cpp
void test_getUUID()
getUUID()メソッドのテスト
virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile &connector_profile)
RTC&#39;s Port base class.
void setOnSubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on publish interfaces.
Definition: PortBase.cpp:584
int main(int argc, char **argv)
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
virtual RTC::ReturnCode_t notify_disconnect(const char *connector_id)
[CORBA interface] Notify the Ports disconnection
void test_get_connector_profiles()
get_connector_profiles()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests)
PortBaseTests()
Constructor.
void test_setPortRef()
setPortRef()メソッドのテスト
ConnectionCallbackMock * m_on_unsubscribe
virtual void deactivateInterfaces()
Deactivate all Port interfaces.
PortService_ptr getPortRef()
Get the object reference of this Port.
Definition: PortBase.cpp:545
ConnectionCallbackMock * m_on_subscribe
ReturnCode_t
Definition: doil.h:53
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void setOnPublishInterfaces(ConnectionCallback *on_publish)
Setting callback called on publish interfaces.
Definition: PortBase.cpp:579
void setOnConnected(ConnectionCallback *on_connected)
Setting callback called on connection established.
Definition: PortBase.cpp:589
ConnectionCallbackMock * m_on_disconnected
std::vector< timeval > _publishIfsTimes
RT-Component class.
Definition: RTObject.h:89
void test_disconnect()
disconnect()メソッドのテスト
const char * getName() const
Get the name of this Port.
Definition: PortBase.cpp:504
void setOwner(RTObject_ptr owner)
Set the owner RTObject of the Port.
Definition: PortBase.cpp:559
void test_get_connector_profile()
get_connector_profile()メソッドのテスト
virtual void unsubscribeInterfaces(const RTC::ConnectorProfile &connector_profile)
const std::string getUUID() const
PortCallback class.
void setOnUnsubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on unsubscribe interfaces.
Definition: PortBase.cpp:594
std::vector< timeval > _unsubscribeIfsTimes
void setPortRef(PortService_ptr port_ref)
Set the object reference of this Port.
Definition: PortBase.cpp:531
timeval getNow() const
void test_setOwner()
setOwner()メソッドのテスト
virtual void tearDown()
Test finalization.
std::vector< PortInterfaceProfile * > PortInterfaceProfileList
Definition: IPortService.h:38
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
void test_getPortProfile()
getPortProfile()メソッドのテスト
ConnectionCallbackMock * m_on_connection_lost
std::vector< ConnectorProfile * > ConnectorProfileList
Definition: IPortService.h:50
void test_notify_connect()
notify_connect()メソッドのテスト
Port base class.
Definition: PortBase.h:134
~PortBaseTests()
Destructor.
ConnectionCallbackMock * m_on_connected
std::vector< std::string > g_argv
ConnectionCallbackMock * m_on_publish
virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile &connector_profile)
ConnectionCallbackMock(const char *name)
const std::vector< timeval > & getNotifyConnectTimes() const
const PortProfile & getProfile() const
Get the PortProfile of the Port.
Definition: PortBase.cpp:517
const std::vector< timeval > & getUnsubscribeIfsTimes() const
void setOnConnectionLost(ConnectionCallback *on_connection_lost)
Setting callback called on connection lost.
Definition: PortBase.cpp:604
virtual RTC::ReturnCode_t notify_connect(RTC::ConnectorProfile &connector_profile)
RTC::PortBase * m_pPortBase_3
virtual void operator()(RTC::ConnectorProfile &profile)
Callback method.
std::vector< timeval > _subscribeIfsTimes
RTC::PortBase * m_pPortBase
std::vector< timeval > _notifyDisconnectTimes
void test_getPortRef()
getPortRef()メソッドのテスト
virtual void activateInterfaces()
Activate all Port interfaces.
void test_connect()
connect()メソッドのテスト
virtual void setUp()
初期化 (1) ORBの初期化,POAのactivate (2) PortBaseのインスタンス生成 (3) PortInterfaceProfileオブジェクト要素のセット (4...
RTComponent header.
const std::vector< timeval > & getSubscribeIfsTimes() const
void test_setName()
setName()メソッドのテスト
const std::string getUUID() const
Generate the UUID.
Definition: PortBase.cpp:728
void test_get_port_profile()
get_port_profile()メソッドのテスト
Callback functor abstract for connect/notify_connect() funcs.
Definition: PortCallback.h:55
void setName(const char *name)
Set the name of this Port.
Definition: PortBase.cpp:488
const std::vector< timeval > & getPublishIfsTimes() const
RTC::PortBase * m_pPortBase_2
void test_getProfile()
getProfile()メソッドのテスト
void setOnDisconnected(ConnectionCallback *on_disconnected)
Setting callback called on disconnected.
Definition: PortBase.cpp:599
const std::vector< timeval > & getNotifyDisconnectTimes() const
const PortProfile & getPortProfile() const
Get the PortProfile of the Port.
Definition: PortBase.cpp:119
std::vector< timeval > _notifyConnectTimes
PortBaseMock(const RTC::PortProfile &profile)


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