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> 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;
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;
110 throw (CORBA::SystemException)
112 _notifyConnectTimes.push_back(getNow());
113 return PortBase::notify_connect(connector_profile);
117 throw (CORBA::SystemException)
119 _notifyDisconnectTimes.push_back(getNow());
120 return PortBase::notify_disconnect(connector_id);
131 _publishIfsTimes.push_back(getNow());
137 _subscribeIfsTimes.push_back(getNow());
143 _unsubscribeIfsTimes.push_back(getNow());
173 return _notifyConnectTimes;
178 return _notifyDisconnectTimes;
183 return _publishIfsTimes;
188 return _subscribeIfsTimes;
193 return _unsubscribeIfsTimes;
202 :
public CppUnit::TestFixture
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);
221 CPPUNIT_TEST_SUITE_END();
267 for (
int i = 0; i <
g_argc; i++) {
268 argv[i] = (
char *)g_argv[i].c_str();
272 m_orb = CORBA::ORB_init(g_argc, argv);
273 PortableServer::POA_ptr poa = PortableServer::POA::_narrow(
274 m_orb->resolve_initial_references(
"RootPOA"));
277 RTC::PortInterfaceProfile portIfProfile;
278 portIfProfile.instance_name =
"PortInterfaceProfile-instance_name";
279 portIfProfile.type_name =
"PortInterfaceProfile-type_name";
283 portIfProfiles.length(1);
284 portIfProfiles[0] = portIfProfile;
287 SDOPackage::NameValue connProfileProperty;
288 connProfileProperty.name =
"ConnectorProfile-properties0-name";
289 connProfileProperty.value <<= CORBA::Float(1.1);
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;
300 connProfiles.length(1);
301 connProfiles[0] = connProfile;
304 SDOPackage::NameValue portProfileProperty;
305 portProfileProperty.name =
"PortProfile-properties0-name";
306 portProfileProperty.value <<= CORBA::Float(2.2);
308 portProfileProperties.length(1);
309 portProfileProperties[0] = portProfileProperty;
312 RTC::PortProfile portProfile;
313 portProfile.name =
"inport0";
314 portProfile.interfaces = portIfProfiles;
315 portProfile.connector_profiles = connProfiles;
316 portProfile.properties = portProfileProperties;
324 PortableServer::POAManager_var poaMgr = poa->the_POAManager();
380 const RTC::PortService_ptr portRef = m_pPortBase->
getPortRef();
381 const RTC::PortProfile* pPortProfile = portRef->get_port_profile();
384 CPPUNIT_ASSERT_EQUAL(
385 std::string(
"inport0"),
386 std::string(pPortProfile->name));
389 const RTC::PortInterfaceProfile& portIfProfile = pPortProfile->interfaces[0];
391 CPPUNIT_ASSERT_EQUAL(
392 std::string(
"PortInterfaceProfile-instance_name"),
393 std::string(portIfProfile.instance_name));
396 CPPUNIT_ASSERT_EQUAL(
397 std::string(
"PortInterfaceProfile-type_name"),
398 std::string(portIfProfile.type_name));
404 const RTC::ConnectorProfile& connProfile = pPortProfile->connector_profiles[0];
406 CPPUNIT_ASSERT_EQUAL(
407 std::string(
"ConnectorProfile-name"),
408 std::string(connProfile.name));
411 CPPUNIT_ASSERT_EQUAL(
412 std::string(
"connect_id0"),
413 std::string(connProfile.connector_id));
416 CPPUNIT_ASSERT_EQUAL(
417 std::string(
"ConnectorProfile-properties0-name"),
418 std::string(connProfile.properties[0].name));
422 connProfile.properties[0].value >>= value;
423 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
427 CPPUNIT_ASSERT_EQUAL(
428 std::string(
"PortProfile-properties0-name"),
429 std::string(pPortProfile->properties[0].name));
433 pPortProfile->properties[0].value >>= value;
434 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value);
448 const RTC::PortProfile& portProfile = m_pPortBase->
getPortProfile();
451 CPPUNIT_ASSERT_EQUAL(
452 std::string(
"inport0"),
453 std::string(portProfile.name));
456 const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0];
458 CPPUNIT_ASSERT_EQUAL(
459 std::string(
"PortInterfaceProfile-instance_name"),
460 std::string(portIfProfile.instance_name));
463 CPPUNIT_ASSERT_EQUAL(
464 std::string(
"PortInterfaceProfile-type_name"),
465 std::string(portIfProfile.type_name));
471 const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0];
473 CPPUNIT_ASSERT_EQUAL(
474 std::string(
"ConnectorProfile-name"),
475 std::string(connProfile.name));
478 CPPUNIT_ASSERT_EQUAL(
479 std::string(
"connect_id0"),
480 std::string(connProfile.connector_id));
483 CPPUNIT_ASSERT_EQUAL(
484 std::string(
"ConnectorProfile-properties0-name"),
485 std::string(connProfile.properties[0].name));
489 connProfile.properties[0].value >>= value;
490 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
494 CPPUNIT_ASSERT_EQUAL(
495 std::string(
"PortProfile-properties0-name"),
496 std::string(portProfile.properties[0].name));
500 portProfile.properties[0].value >>= value;
501 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value);
518 const RTC::PortService_ptr portRef = m_pPortBase->
getPortRef();
522 const RTC::ConnectorProfile& connProfile = (*pConnProfList)[0];
524 CPPUNIT_ASSERT_EQUAL(
525 std::string(
"ConnectorProfile-name"),
526 std::string(connProfile.name));
529 CPPUNIT_ASSERT_EQUAL(
530 std::string(
"connect_id0"),
531 std::string(connProfile.connector_id));
534 const SDOPackage::NameValue&
property = connProfile.properties[0];
536 CPPUNIT_ASSERT_EQUAL(
537 std::string(
"ConnectorProfile-properties0-name"),
538 std::string(property.name));
543 property.value >>= value;
544 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
561 const RTC::PortService_ptr portRef = m_pPortBase->
getPortRef();
562 const RTC::ConnectorProfile* pConnProfile = portRef->get_connector_profile(
"connect_id0");
565 CPPUNIT_ASSERT_EQUAL(
566 std::string(
"ConnectorProfile-name"),
567 std::string(pConnProfile->name));
570 CPPUNIT_ASSERT_EQUAL(
571 std::string(
"connect_id0"),
572 std::string(pConnProfile->connector_id));
575 const SDOPackage::NameValue&
property = pConnProfile->properties[0];
577 CPPUNIT_ASSERT_EQUAL(
578 std::string(
"ConnectorProfile-properties0-name"),
579 std::string(property.name));
584 property.value >>= value;
585 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
601 RTC::PortService_ptr portRef = m_pPortBase->
getPortRef();
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;
611 CPPUNIT_ASSERT_EQUAL(
RTC::RTC_OK, portRef->connect(connProfile));
615 CPPUNIT_ASSERT(pPortBaseMock != 0);
616 CPPUNIT_ASSERT_EQUAL(1, (
int) pPortBaseMock->getNotifyConnectTimes().size());
639 RTC::PortService_ptr portRef = m_pPortBase->
getPortRef();
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;
649 CPPUNIT_ASSERT_EQUAL(
RTC::RTC_OK, portRef->connect(connProfile));
652 CPPUNIT_ASSERT_EQUAL(
RTC::RTC_OK, portRef->disconnect(connProfile.connector_id));
656 CPPUNIT_ASSERT(pPortBaseMock != 0);
657 CPPUNIT_ASSERT_EQUAL(1, (
int) pPortBaseMock->getNotifyDisconnectTimes().size());
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();
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;
685 CPPUNIT_ASSERT(pPortBaseMock_1 != 0);
688 CPPUNIT_ASSERT(pPortBaseMock_2 != 0);
689 CPPUNIT_ASSERT_EQUAL(0, (
int) pPortBaseMock_2->getNotifyDisconnectTimes().size());
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());
696 CPPUNIT_ASSERT_EQUAL(1, (
int) pPortBaseMock_2->getNotifyDisconnectTimes().size());
697 CPPUNIT_ASSERT_EQUAL(1, (
int) pPortBaseMock_3->getNotifyDisconnectTimes().size());
709 m_pPortBase->
setName(
"inport0-changed");
712 std::string str(m_pPortBase->
getName());
713 CPPUNIT_ASSERT_EQUAL(std::string(
"inport0-changed"), str);
716 const RTC::PortProfile& portProfile = m_pPortBase->
getPortProfile();
717 CPPUNIT_ASSERT_EQUAL(std::string(
"inport0-changed"), std::string(portProfile.name));
730 const RTC::PortProfile& portProfile = m_pPortBase->
getProfile();
733 CPPUNIT_ASSERT_EQUAL(std::string(
"inport0"), std::string(portProfile.name));
736 const RTC::PortInterfaceProfile& portIfProfile = portProfile.interfaces[0];
738 CPPUNIT_ASSERT_EQUAL(
739 std::string(
"PortInterfaceProfile-instance_name"),
740 std::string(portIfProfile.instance_name));
743 CPPUNIT_ASSERT_EQUAL(
744 std::string(
"PortInterfaceProfile-type_name"),
745 std::string(portIfProfile.type_name));
751 const RTC::ConnectorProfile& connProfile = portProfile.connector_profiles[0];
753 CPPUNIT_ASSERT_EQUAL(
754 std::string(
"ConnectorProfile-name"),
755 std::string(connProfile.name));
758 CPPUNIT_ASSERT_EQUAL(
759 std::string(
"connect_id0"),
760 std::string(connProfile.connector_id));
764 const SDOPackage::NameValue&
property = connProfile.properties[0];
766 CPPUNIT_ASSERT_EQUAL(
767 std::string(
"ConnectorProfile-properties0-name"),
768 std::string(property.name));
773 property.value >>= value;
774 CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.1), value);
780 const SDOPackage::NameValue&
property = portProfile.properties[0];
782 CPPUNIT_ASSERT_EQUAL(
783 std::string(
"PortProfile-properties0-name"),
784 std::string(property.name));
789 property.value >>= value;
790 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.2), value);
803 m_pPortBase->_remove_ref();
808 RTC::PortService_var port = m_pPortBase->_this();
809 RTC::PortService_ptr portRef = port._retn();
812 CPPUNIT_ASSERT_EQUAL(portRef, m_pPortBase->
getPortRef());
832 CPPUNIT_ASSERT(pPortBase != 0);
836 CPPUNIT_ASSERT(uuid.length() > 0);
845 PortableServer::POA_ptr poa = PortableServer::POA::_narrow(
846 m_orb->resolve_initial_references(
"RootPOA"));
848 RTC::RTObject_ptr owner = obj->getObjRef();
849 RTC::PortProfile portprofile = m_pPortBase->
getProfile();
850 CPPUNIT_ASSERT(CORBA::is_nil(portprofile.owner));
853 CPPUNIT_ASSERT(!CORBA::is_nil(portprofile.owner));
855 poa->the_POAManager()->deactivate(
false,
true);
868 int main(
int argc,
char* argv[])
881 std::string arg(argv[i]);
882 std::string next_arg;
883 if (i + 1 < argc) next_arg = argv[i + 1];
886 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
899 ofs.open(fname.c_str());
901 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
902 if ( arg ==
"--cerr" ) { target = 1;
break; }
903 if ( arg ==
"--xsl" )
905 if (next_arg ==
"") xsl =
"default.xsl";
908 if ( arg ==
"--namespace" )
912 std::cerr <<
"no namespace specified" << std::endl;
922 CppUnit::TextUi::TestRunner runner;
924 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
926 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
927 CppUnit::Outputter* outputter = 0;
928 std::ostream* stream = target ? &std::cerr : &std::cout;
932 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
935 std::cout <<
"XML_OUT" << std::endl;
936 outputter =
new CppUnit::XmlOutputter(&runner.result(),
938 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
941 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
944 runner.setOutputter(outputter);
949 #endif // PortBase_cpp void test_getUUID()
getUUID()メソッドのテスト
virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile &connector_profile)
RTC's Port base class.
void setOnSubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on publish interfaces.
int main(int argc, char **argv)
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
const std::string getUUID() const
virtual RTC::ReturnCode_t notify_disconnect(const char *connector_id)
[CORBA interface] Notify the Ports disconnection
void test_get_connector_profiles()
get_connector_profiles()メソッドのテスト
const std::vector< timeval > & getNotifyConnectTimes() const
CPPUNIT_TEST_SUITE_REGISTRATION(PortBase::PortBaseTests)
PortBaseTests()
Constructor.
const PortProfile & getProfile() const
Get the PortProfile of the Port.
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.
ConnectionCallbackMock * m_on_subscribe
std::vector< std::pair< std::string, std::string > > NVList
void setOnPublishInterfaces(ConnectionCallback *on_publish)
Setting callback called on publish interfaces.
void setOnConnected(ConnectionCallback *on_connected)
Setting callback called on connection established.
ConnectionCallbackMock * m_on_disconnected
std::vector< timeval > _publishIfsTimes
void test_disconnect()
disconnect()メソッドのテスト
void setOwner(RTObject_ptr owner)
Set the owner RTObject of the Port.
void test_get_connector_profile()
get_connector_profile()メソッドのテスト
virtual void unsubscribeInterfaces(const RTC::ConnectorProfile &connector_profile)
void setOnUnsubscribeInterfaces(ConnectionCallback *on_subscribe)
Setting callback called on unsubscribe interfaces.
std::vector< timeval > _unsubscribeIfsTimes
void setPortRef(PortService_ptr port_ref)
Set the object reference of this Port.
void test_setOwner()
setOwner()メソッドのテスト
virtual void tearDown()
Test finalization.
std::vector< PortInterfaceProfile * > PortInterfaceProfileList
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
void test_getPortProfile()
getPortProfile()メソッドのテスト
ConnectionCallbackMock * m_on_connection_lost
const std::vector< timeval > & getSubscribeIfsTimes() const
std::vector< ConnectorProfile * > ConnectorProfileList
void test_notify_connect()
notify_connect()メソッドのテスト
const std::vector< timeval > & getPublishIfsTimes() const
~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)
void test_disconnect_all()
ConnectionCallbackMock(const char *name)
void setOnConnectionLost(ConnectionCallback *on_connection_lost)
Setting callback called on connection lost.
void erase_m_profile(void)
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
const std::vector< timeval > & getNotifyDisconnectTimes() const
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...
void test_setName()
setName()メソッドのテスト
virtual ~ConnectionCallbackMock()
void test_get_port_profile()
get_port_profile()メソッドのテスト
Callback functor abstract for connect/notify_connect() funcs.
void setName(const char *name)
Set the name of this Port.
const std::string getUUID() const
Generate the UUID.
RTC::PortBase * m_pPortBase_2
void test_getProfile()
getProfile()メソッドのテスト
const std::vector< timeval > & getUnsubscribeIfsTimes() const
void setOnDisconnected(ConnectionCallback *on_disconnected)
Setting callback called on disconnected.
const char * getName() const
Get the name of this Port.
std::vector< timeval > _notifyConnectTimes
PortBaseMock(const RTC::PortProfile &profile)
const PortProfile & getPortProfile() const
Get the PortProfile of the Port.