RTObjectTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
11 /*
12  * $Log: RTObjectTests.cpp,v $
13  * Revision 1.1 2008/04/24 08:49:57 arafune
14  * The first commitment.
15  *
16  */
17 
18 #ifndef RTObject_cpp
19 #define RTObject_cpp
20 
21 #include <cppunit/ui/text/TestRunner.h>
22 #include <cppunit/TextOutputter.h>
23 #include <cppunit/extensions/TestFactoryRegistry.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppunit/TestAssert.h>
26 
27 #include <rtm/RTC.h>
29 #include <rtm/RTObject.h>
30 
35 namespace RTObject
36 {
38  : public RTC::RTObject_impl
39  {
40  public:
41  RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
42  : RTC::RTObject_impl(orb, poa)
43  {
44  }
45 
46  virtual ~RTObjectMock()
47  {
48  }
49 
51  throw (CORBA::SystemException)
52  {
53  log("on_initialize");
55  }
56 
58  throw (CORBA::SystemException)
59  {
60  log("on_finalize");
62  }
63 
64  virtual RTC::UniqueId bindContext(RTC::ExecutionContext_ptr exec_context)
65  {
67  id = RTC::RTObject_impl::bindContext(exec_context);
69  return id;
70  }
71  RTC::ExecutionContextServiceList ecMine;
72 
73  // protected: m_ecMineの設定 void set_ecMine() { RTC::RTObject_impl::m_ecMine = ecMine; } // protected: m_ecMineの判定 bool chk_ecMine(int id, RTC::ExecutionContext_ptr exec_context) { RTC::ExecutionContextService_var ecs; ecs = RTC::ExecutionContextService::_narrow(exec_context); if (RTC::RTObject_impl::m_ecMine[id] == ecs) { return true; } else { return false; } } std::vector<RTC::ExecutionContextBase*> eclist; // protected: m_eclistの取得 int get_eclist() { int len(RTC::RTObject_impl::m_eclist.size()); eclist = RTC::RTObject_impl::m_eclist; return len; } public: // helper for test int countLog(std::string line) { int count = 0; for (int i = 0; i < (int) m_log.size(); ++i) { if (m_log[i] == line) ++count; } return count; } void set_status(const char* name, const CORBA::Any& value) { CORBA::Long idx = NVUtil::find_index(m_sdoStatus, name); if (idx < 0) { SDOPackage::NameValue nv = NVUtil::newNVAny(name, value); CORBA_SeqUtil::push_back(m_sdoStatus, nv); } else { m_sdoStatus[idx].value <<= value; } } void shutdown() { RTObject_impl::shutdown(); } private: void log(const std::string& msg) { m_log.push_back(msg); } private: std::vector<std::string> m_log; }; class PortMock : public RTC::PortBase { protected: virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile& connector_profile) { return RTC::RTC_OK; } virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile& connector_profile) { return RTC::RTC_OK; } virtual void unsubscribeInterfaces(const RTC::ConnectorProfile& connector_profile) { } virtual void activateInterfaces() { } virtual void deactivateInterfaces() { } }; class InPortMock : public RTC::InPortBase { public: InPortMock(const char* name, const char* data_type) :RTC::InPortBase(name, data_type), m_return(true), m_cnt(0) { return; } bool read(){ ++m_cnt; return m_return; } void set_return(bool ret) { m_return = ret; } int get_counter() { return m_cnt; } private: bool m_return; int m_cnt; }; class OutPortMock : public RTC::OutPortBase { public: OutPortMock(const char* name, const char* data_type) : OutPortBase(name, data_type), m_return(true), m_cnt(0) { return; } bool write() { ++m_cnt; return m_return; } void set_return(bool ret) { m_return = ret; } int get_counter() { return m_cnt; } private: bool m_return; int m_cnt; }; class SDOServiceMock : public POA_SDOPackage::SDOService, public virtual PortableServer::RefCountServantBase { }; struct PortFinder { PortFinder(const RTC::PortService_ptr& port) : m_port(port) {} bool operator()(const RTC::PortService_ptr& port) { return m_port->_is_equivalent(port); } const RTC::PortService_ptr& m_port; }; class SDOSystemElementMock : public POA_SDOPackage::SDOSystemElement, public virtual PortableServer::RefCountServantBase { }; class OrganizationMock : public POA_SDOPackage::Organization, public virtual PortableServer::RefCountServantBase { public: OrganizationMock(const char* id) : m_id(id) { } virtual char* get_organization_id() { return CORBA::string_dup(m_id); } virtual SDOPackage::OrganizationProperty* get_organization_property() { return NULL; } virtual CORBA::Any* get_organization_property_value(const char* name) { return NULL; } virtual CORBA::Boolean add_organization_property(const SDOPackage::OrganizationProperty& organization_property) { return false; } virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value) { return false; } virtual CORBA::Boolean remove_organization_property(const char* name) { return false; } virtual SDOPackage::SDOSystemElement_ptr get_owner() { return NULL; } virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo) { return false; } virtual SDOPackage::SDOList* get_members() { return NULL; } virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos) { return false; } virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list) { return false; } virtual CORBA::Boolean remove_member(const char* id) { return false; } virtual SDOPackage::DependencyType get_dependency() { return SDOPackage::NO_DEPENDENCY; } virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency) { return false; } private: const char* m_id; }; struct ExecutionContextServiceFinder { ExecutionContextServiceFinder(const RTC::ExecutionContextService_ptr& ecSvc) : m_ecSvc(ecSvc) {} bool operator()(const RTC::ExecutionContextService_ptr& ecSvc) { return m_ecSvc->_is_equivalent(ecSvc); } const RTC::ExecutionContextService_ptr& m_ecSvc; }; struct ServiceProfileFinder { ServiceProfileFinder(const char* id) : m_id(id) {} bool operator()(const SDOPackage::ServiceProfile& svcProf) { return strcmp(m_id, (const char*)(svcProf.id)) == 0; } const char* m_id; }; struct OrganizationFinder { OrganizationFinder(const char* id) : m_id(id) {} bool operator()(const SDOPackage::Organization_ptr& org) { return strcmp(m_id, org->get_organization_id()) == 0; } const char* m_id; }; class RTObjectTests : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RTObjectTests); CPPUNIT_TEST(test_finalizeContexts); CPPUNIT_TEST(test_bindContext); CPPUNIT_TEST(test_add_removePort); CPPUNIT_TEST(test_readAll); CPPUNIT_TEST(test_writeAll); CPPUNIT_TEST(test_initialize_invoking_on_initialize); CPPUNIT_TEST(test_initialize_in_Alive); CPPUNIT_TEST(test_finalize_invoking_on_finalize); CPPUNIT_TEST(test_finalize_participating_in_execution_context); CPPUNIT_TEST(test_finalize_in_Created); // CPPUNIT_TEST(test_is_alive); CPPUNIT_TEST(test_exit); CPPUNIT_TEST(test_exit_in_Created); CPPUNIT_TEST(test_detach_executioncontext); CPPUNIT_TEST(test_detach_executioncontext_with_illegal_id); CPPUNIT_TEST(test_get_context); CPPUNIT_TEST(test_get_contexts); CPPUNIT_TEST(test_get_component_profile); CPPUNIT_TEST(test_get_ports); // CPPUNIT_TEST(test_get_execution_context_services); // CPPUNIT_TEST(test_get_owned_organizations); CPPUNIT_TEST(test_get_sdo_id); CPPUNIT_TEST(test_get_sdo_type); // CPPUNIT_TEST(test_get_device_profile); // CPPUNIT_TEST(test_get_service_profile); CPPUNIT_TEST(test_get_service_profile_with_illegal_arguments); CPPUNIT_TEST(test_get_sdo_service); CPPUNIT_TEST(test_get_sdo_service_with_illegal_arguments); CPPUNIT_TEST(test_get_configuration_and_set_device_profile_and_get_device_profile); CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profile); CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profiles); CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_sdo_service); CPPUNIT_TEST(test_get_configuration_and_remove_service_profile); CPPUNIT_TEST(test_get_configuration_and_add_organization_and_get_organizations); CPPUNIT_TEST(test_get_configuration_and_remove_organization); // CPPUNIT_TEST(test_get_monitoring); CPPUNIT_TEST(test_get_status); CPPUNIT_TEST(test_get_status_list); CPPUNIT_TEST_SUITE_END(); private: CORBA::ORB_ptr m_pORB; PortableServer::POA_ptr m_pPOA; public: /*! * @brief Constructor */ RTObjectTests() { int argc(0); char** argv(NULL); m_pORB = CORBA::ORB_init(argc, argv); m_pPOA = PortableServer::POA::_narrow( m_pORB->resolve_initial_references("RootPOA")); m_pPOA->the_POAManager()->activate(); } /*! * @brief Destructor */ virtual ~RTObjectTests() { } /*! * @brief Test initialization */ virtual void setUp() { } /*! * @brief Test finalization */ virtual void tearDown() { } /*! * @brief initialize()メソッドのテスト * * - initialize()メソッド呼出により、on_initialize()コールバックが呼び出されるか? */ void test_initialize_invoking_on_initialize() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出により、on_initialize()コールバックが呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_initialize")); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_initialize")); rto->exit(); delete rto; } /*! * @brief initialize()メソッドのテスト * * - Alive状態の時にinitialize()メソッドを呼出た場合、正常に動作するか? */ void test_initialize_in_Alive() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // Alive状態でinitialize()メソッド呼出しを行った場合、正常に動作するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - finalize()呼出により、on_finalize()コールバックが呼び出されるか? */ void test_finalize_invoking_on_finalize() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // finalize()呼出しにより、on_finalize()コールバックが呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // exit()呼び出しで、finalize()が有効となり実行される rto->exit(); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); delete rto; } /*! * @brief finalize()メソッドのテスト * * - ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? */ void test_finalize_participating_in_execution_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // ExecutionContextに登録しておく CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this())); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? */ void test_finalize_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); rto->shutdown(); delete rto; } /*! * @brief is_alive()メソッドのテスト */ void test_is_alive() { // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
74  void set_ecMine()
75  {
77  }
78 
79  // protected: m_ecMineの判定
80  bool chk_ecMine(int id, RTC::ExecutionContext_ptr exec_context)
81  {
82  RTC::ExecutionContextService_var ecs;
83  ecs = RTC::ExecutionContextService::_narrow(exec_context);
84  if (RTC::RTObject_impl::m_ecMine[id] == ecs)
85  {
86  return true;
87  }
88  else
89  {
90  return false;
91  }
92  }
93 
94  std::vector<RTC::ExecutionContextBase*> eclist;
95  // protected: m_eclistの取得 int get_eclist() { int len(RTC::RTObject_impl::m_eclist.size()); eclist = RTC::RTObject_impl::m_eclist; return len; } public: // helper for test int countLog(std::string line) { int count = 0; for (int i = 0; i < (int) m_log.size(); ++i) { if (m_log[i] == line) ++count; } return count; } void set_status(const char* name, const CORBA::Any& value) { CORBA::Long idx = NVUtil::find_index(m_sdoStatus, name); if (idx < 0) { SDOPackage::NameValue nv = NVUtil::newNVAny(name, value); CORBA_SeqUtil::push_back(m_sdoStatus, nv); } else { m_sdoStatus[idx].value <<= value; } } void shutdown() { RTObject_impl::shutdown(); } private: void log(const std::string& msg) { m_log.push_back(msg); } private: std::vector<std::string> m_log; }; class PortMock : public RTC::PortBase { protected: virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile& connector_profile) { return RTC::RTC_OK; } virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile& connector_profile) { return RTC::RTC_OK; } virtual void unsubscribeInterfaces(const RTC::ConnectorProfile& connector_profile) { } virtual void activateInterfaces() { } virtual void deactivateInterfaces() { } }; class InPortMock : public RTC::InPortBase { public: InPortMock(const char* name, const char* data_type) :RTC::InPortBase(name, data_type), m_return(true), m_cnt(0) { return; } bool read(){ ++m_cnt; return m_return; } void set_return(bool ret) { m_return = ret; } int get_counter() { return m_cnt; } private: bool m_return; int m_cnt; }; class OutPortMock : public RTC::OutPortBase { public: OutPortMock(const char* name, const char* data_type) : OutPortBase(name, data_type), m_return(true), m_cnt(0) { return; } bool write() { ++m_cnt; return m_return; } void set_return(bool ret) { m_return = ret; } int get_counter() { return m_cnt; } private: bool m_return; int m_cnt; }; class SDOServiceMock : public POA_SDOPackage::SDOService, public virtual PortableServer::RefCountServantBase { }; struct PortFinder { PortFinder(const RTC::PortService_ptr& port) : m_port(port) {} bool operator()(const RTC::PortService_ptr& port) { return m_port->_is_equivalent(port); } const RTC::PortService_ptr& m_port; }; class SDOSystemElementMock : public POA_SDOPackage::SDOSystemElement, public virtual PortableServer::RefCountServantBase { }; class OrganizationMock : public POA_SDOPackage::Organization, public virtual PortableServer::RefCountServantBase { public: OrganizationMock(const char* id) : m_id(id) { } virtual char* get_organization_id() { return CORBA::string_dup(m_id); } virtual SDOPackage::OrganizationProperty* get_organization_property() { return NULL; } virtual CORBA::Any* get_organization_property_value(const char* name) { return NULL; } virtual CORBA::Boolean add_organization_property(const SDOPackage::OrganizationProperty& organization_property) { return false; } virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value) { return false; } virtual CORBA::Boolean remove_organization_property(const char* name) { return false; } virtual SDOPackage::SDOSystemElement_ptr get_owner() { return NULL; } virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo) { return false; } virtual SDOPackage::SDOList* get_members() { return NULL; } virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos) { return false; } virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list) { return false; } virtual CORBA::Boolean remove_member(const char* id) { return false; } virtual SDOPackage::DependencyType get_dependency() { return SDOPackage::NO_DEPENDENCY; } virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency) { return false; } private: const char* m_id; }; struct ExecutionContextServiceFinder { ExecutionContextServiceFinder(const RTC::ExecutionContextService_ptr& ecSvc) : m_ecSvc(ecSvc) {} bool operator()(const RTC::ExecutionContextService_ptr& ecSvc) { return m_ecSvc->_is_equivalent(ecSvc); } const RTC::ExecutionContextService_ptr& m_ecSvc; }; struct ServiceProfileFinder { ServiceProfileFinder(const char* id) : m_id(id) {} bool operator()(const SDOPackage::ServiceProfile& svcProf) { return strcmp(m_id, (const char*)(svcProf.id)) == 0; } const char* m_id; }; struct OrganizationFinder { OrganizationFinder(const char* id) : m_id(id) {} bool operator()(const SDOPackage::Organization_ptr& org) { return strcmp(m_id, org->get_organization_id()) == 0; } const char* m_id; }; class RTObjectTests : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RTObjectTests); CPPUNIT_TEST(test_finalizeContexts); CPPUNIT_TEST(test_bindContext); CPPUNIT_TEST(test_add_removePort); CPPUNIT_TEST(test_readAll); CPPUNIT_TEST(test_writeAll); CPPUNIT_TEST(test_initialize_invoking_on_initialize); CPPUNIT_TEST(test_initialize_in_Alive); CPPUNIT_TEST(test_finalize_invoking_on_finalize); CPPUNIT_TEST(test_finalize_participating_in_execution_context); CPPUNIT_TEST(test_finalize_in_Created); // CPPUNIT_TEST(test_is_alive); CPPUNIT_TEST(test_exit); CPPUNIT_TEST(test_exit_in_Created); CPPUNIT_TEST(test_detach_executioncontext); CPPUNIT_TEST(test_detach_executioncontext_with_illegal_id); CPPUNIT_TEST(test_get_context); CPPUNIT_TEST(test_get_contexts); CPPUNIT_TEST(test_get_component_profile); CPPUNIT_TEST(test_get_ports); // CPPUNIT_TEST(test_get_execution_context_services); // CPPUNIT_TEST(test_get_owned_organizations); CPPUNIT_TEST(test_get_sdo_id); CPPUNIT_TEST(test_get_sdo_type); // CPPUNIT_TEST(test_get_device_profile); // CPPUNIT_TEST(test_get_service_profile); CPPUNIT_TEST(test_get_service_profile_with_illegal_arguments); CPPUNIT_TEST(test_get_sdo_service); CPPUNIT_TEST(test_get_sdo_service_with_illegal_arguments); CPPUNIT_TEST(test_get_configuration_and_set_device_profile_and_get_device_profile); CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profile); CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profiles); CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_sdo_service); CPPUNIT_TEST(test_get_configuration_and_remove_service_profile); CPPUNIT_TEST(test_get_configuration_and_add_organization_and_get_organizations); CPPUNIT_TEST(test_get_configuration_and_remove_organization); // CPPUNIT_TEST(test_get_monitoring); CPPUNIT_TEST(test_get_status); CPPUNIT_TEST(test_get_status_list); CPPUNIT_TEST_SUITE_END(); private: CORBA::ORB_ptr m_pORB; PortableServer::POA_ptr m_pPOA; public: /*! * @brief Constructor */ RTObjectTests() { int argc(0); char** argv(NULL); m_pORB = CORBA::ORB_init(argc, argv); m_pPOA = PortableServer::POA::_narrow( m_pORB->resolve_initial_references("RootPOA")); m_pPOA->the_POAManager()->activate(); } /*! * @brief Destructor */ virtual ~RTObjectTests() { } /*! * @brief Test initialization */ virtual void setUp() { } /*! * @brief Test finalization */ virtual void tearDown() { } /*! * @brief initialize()メソッドのテスト * * - initialize()メソッド呼出により、on_initialize()コールバックが呼び出されるか? */ void test_initialize_invoking_on_initialize() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出により、on_initialize()コールバックが呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_initialize")); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_initialize")); rto->exit(); delete rto; } /*! * @brief initialize()メソッドのテスト * * - Alive状態の時にinitialize()メソッドを呼出た場合、正常に動作するか? */ void test_initialize_in_Alive() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // Alive状態でinitialize()メソッド呼出しを行った場合、正常に動作するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - finalize()呼出により、on_finalize()コールバックが呼び出されるか? */ void test_finalize_invoking_on_finalize() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // finalize()呼出しにより、on_finalize()コールバックが呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // exit()呼び出しで、finalize()が有効となり実行される rto->exit(); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); delete rto; } /*! * @brief finalize()メソッドのテスト * * - ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? */ void test_finalize_participating_in_execution_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // ExecutionContextに登録しておく CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this())); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? */ void test_finalize_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); rto->shutdown(); delete rto; } /*! * @brief is_alive()メソッドのテスト */ void test_is_alive() { // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
96  int get_eclist()
97  {
98  int len(RTC::RTObject_impl::m_eclist.size());
100  return len;
101  }
102 
103 
104  public: // helper for test
105  int countLog(std::string line)
106  {
107  int count = 0;
108  for (int i = 0; i < (int) m_log.size(); ++i)
109  {
110  if (m_log[i] == line) ++count;
111  }
112  return count;
113  }
114 
115  void set_status(const char* name, const CORBA::Any& value)
116  {
117  CORBA::Long idx = NVUtil::find_index(m_sdoStatus, name);
118  if (idx < 0)
119  {
120  SDOPackage::NameValue nv = NVUtil::newNVAny(name, value);
122  }
123  else
124  {
125  m_sdoStatus[idx].value <<= value;
126  }
127  }
128 
129  void shutdown()
130  {
131  RTObject_impl::shutdown();
132  }
133 
134 
135  private:
136  void log(const std::string& msg)
137  {
138  m_log.push_back(msg);
139  }
140 
141  private:
142  std::vector<std::string> m_log;
143  };
144 
145  class PortMock
146  : public RTC::PortBase
147  {
148  protected:
149  virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile& connector_profile)
150  {
151  return RTC::RTC_OK;
152  }
153  virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
154  {
155  return RTC::RTC_OK;
156  }
157  virtual void unsubscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
158  {
159  }
160  virtual void activateInterfaces()
161  {
162  }
163  virtual void deactivateInterfaces()
164  {
165  }
166  };
167 
169  : public RTC::InPortBase
170  {
171  public:
172  InPortMock(const char* name, const char* data_type)
173  :RTC::InPortBase(name, data_type),
174  m_return(true),
175  m_cnt(0)
176  {
177  return;
178  }
179 
180  bool read(){
181  ++m_cnt;
182  return m_return;
183  }
184 
185  void set_return(bool ret)
186  {
187  m_return = ret;
188  }
189 
191  {
192  return m_cnt;
193  }
194 
195  private:
196  bool m_return;
197  int m_cnt;
198  };
199 
201  : public RTC::OutPortBase
202  {
203  public:
204  OutPortMock(const char* name, const char* data_type)
205  : OutPortBase(name, data_type),
206  m_return(true),
207  m_cnt(0)
208  {
209  return;
210  }
211 
212  bool write() {
213  ++m_cnt;
214  return m_return;
215  }
216  void set_return(bool ret)
217  {
218  m_return = ret;
219  }
220 
222  {
223  return m_cnt;
224  }
225  private:
226  bool m_return;
227  int m_cnt;
228  };
229 
231  : public POA_SDOPackage::SDOService,
232  public virtual PortableServer::RefCountServantBase
233  {
234  };
235 
236  struct PortFinder
237  {
238  PortFinder(const RTC::PortService_ptr& port) : m_port(port) {}
239  bool operator()(const RTC::PortService_ptr& port)
240  {
241  return m_port->_is_equivalent(port);
242  }
243 
244  const RTC::PortService_ptr& m_port;
245  };
246 
248  : public POA_SDOPackage::SDOSystemElement,
249  public virtual PortableServer::RefCountServantBase
250  {
251  };
252 
254  : public POA_SDOPackage::Organization,
255  public virtual PortableServer::RefCountServantBase
256  {
257  public:
258  OrganizationMock(const char* id) : m_id(id)
259  {
260  }
261 
262  virtual char* get_organization_id()
263  {
264  return CORBA::string_dup(m_id);
265  }
266 
267  virtual SDOPackage::OrganizationProperty* get_organization_property()
268  {
269  return NULL;
270  }
271 
272  virtual CORBA::Any* get_organization_property_value(const char* name)
273  {
274  return NULL;
275  }
276 
277  virtual CORBA::Boolean add_organization_property(const SDOPackage::OrganizationProperty& organization_property)
278  {
279  return false;
280  }
281 
282  virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value)
283  {
284  return false;
285  }
286 
287  virtual CORBA::Boolean remove_organization_property(const char* name)
288  {
289  return false;
290  }
291 
292  virtual SDOPackage::SDOSystemElement_ptr get_owner()
293  {
294  return NULL;
295  }
296 
297  virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
298  {
299  return false;
300  }
301 
302  virtual SDOPackage::SDOList* get_members()
303  {
304  return NULL;
305  }
306 
307  virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos)
308  {
309  return false;
310  }
311 
312  virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list)
313  {
314  return false;
315  }
316 
317  virtual CORBA::Boolean remove_member(const char* id)
318  {
319  return false;
320  }
321 
322  virtual SDOPackage::DependencyType get_dependency()
323  {
324  return SDOPackage::NO_DEPENDENCY;
325  }
326 
327  virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
328  {
329  return false;
330  }
331 
332  private:
333  const char* m_id;
334  };
335 
337  {
338  ExecutionContextServiceFinder(const RTC::ExecutionContextService_ptr& ecSvc)
339  : m_ecSvc(ecSvc) {}
340  bool operator()(const RTC::ExecutionContextService_ptr& ecSvc)
341  {
342  return m_ecSvc->_is_equivalent(ecSvc);
343  }
344  const RTC::ExecutionContextService_ptr& m_ecSvc;
345  };
346 
348  {
349  ServiceProfileFinder(const char* id) : m_id(id) {}
350  bool operator()(const SDOPackage::ServiceProfile& svcProf)
351  {
352  return strcmp(m_id, (const char*)(svcProf.id)) == 0;
353  }
354  const char* m_id;
355  };
356 
358  {
359  OrganizationFinder(const char* id) : m_id(id) {}
360  bool operator()(const SDOPackage::Organization_ptr& org)
361  {
362  return strcmp(m_id, org->get_organization_id()) == 0;
363  }
364  const char* m_id;
365  };
366 
368  : public CppUnit::TestFixture
369  {
370  CPPUNIT_TEST_SUITE(RTObjectTests);
371 
372  CPPUNIT_TEST(test_finalizeContexts);
373  CPPUNIT_TEST(test_bindContext);
374  CPPUNIT_TEST(test_add_removePort);
375  CPPUNIT_TEST(test_readAll);
376  CPPUNIT_TEST(test_writeAll);
377  CPPUNIT_TEST(test_initialize_invoking_on_initialize);
378  CPPUNIT_TEST(test_initialize_in_Alive);
379  CPPUNIT_TEST(test_finalize_invoking_on_finalize);
380  CPPUNIT_TEST(test_finalize_participating_in_execution_context);
381  CPPUNIT_TEST(test_finalize_in_Created);
382  // CPPUNIT_TEST(test_is_alive);
383  CPPUNIT_TEST(test_exit);
384  CPPUNIT_TEST(test_exit_in_Created);
385  CPPUNIT_TEST(test_detach_executioncontext);
386  CPPUNIT_TEST(test_detach_executioncontext_with_illegal_id);
387  CPPUNIT_TEST(test_get_context);
388  CPPUNIT_TEST(test_get_contexts);
389  CPPUNIT_TEST(test_get_component_profile);
390  CPPUNIT_TEST(test_get_ports);
391 // CPPUNIT_TEST(test_get_execution_context_services);
392  // CPPUNIT_TEST(test_get_owned_organizations);
393  CPPUNIT_TEST(test_get_sdo_id);
394  CPPUNIT_TEST(test_get_sdo_type);
395  // CPPUNIT_TEST(test_get_device_profile);
396  // CPPUNIT_TEST(test_get_service_profile);
397  CPPUNIT_TEST(test_get_service_profile_with_illegal_arguments);
398  CPPUNIT_TEST(test_get_sdo_service);
399  CPPUNIT_TEST(test_get_sdo_service_with_illegal_arguments);
400  CPPUNIT_TEST(test_get_configuration_and_set_device_profile_and_get_device_profile);
401  CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profile);
402  CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profiles);
403  CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_sdo_service);
404  CPPUNIT_TEST(test_get_configuration_and_remove_service_profile);
405  CPPUNIT_TEST(test_get_configuration_and_add_organization_and_get_organizations);
406  CPPUNIT_TEST(test_get_configuration_and_remove_organization);
407  // CPPUNIT_TEST(test_get_monitoring);
408  CPPUNIT_TEST(test_get_status);
409  CPPUNIT_TEST(test_get_status_list);
410 
411  CPPUNIT_TEST_SUITE_END();
412 
413  private:
414  CORBA::ORB_ptr m_pORB;
415  PortableServer::POA_ptr m_pPOA;
416 
417  public:
422  {
423  int argc(0);
424  char** argv(NULL);
425  m_pORB = CORBA::ORB_init(argc, argv);
426  m_pPOA = PortableServer::POA::_narrow(
427  m_pORB->resolve_initial_references("RootPOA"));
428  m_pPOA->the_POAManager()->activate();
429  }
430 
434  virtual ~RTObjectTests()
435  {
436  }
437 
441  virtual void setUp()
442  {
443  }
444 
448  virtual void tearDown()
449  {
450  }
451 
458  {
459  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
460 
461  // initialize()メソッド呼出により、on_initialize()コールバックが呼び出されるか?
462  CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_initialize"));
464  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
465  prop.setProperty("exec_cxt.periodic.rate","1000");
466  rto->setProperties(prop);
467  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
468  CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_initialize"));
469  rto->exit();
470  delete rto;
471  }
472 
479  {
480  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
481 
482  // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // Alive状態でinitialize()メソッド呼出しを行った場合、正常に動作するか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - finalize()呼出により、on_finalize()コールバックが呼び出されるか? */ void test_finalize_invoking_on_finalize() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // finalize()呼出しにより、on_finalize()コールバックが呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // exit()呼び出しで、finalize()が有効となり実行される rto->exit(); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); delete rto; } /*! * @brief finalize()メソッドのテスト * * - ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? */ void test_finalize_participating_in_execution_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // ExecutionContextに登録しておく CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this())); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? */ void test_finalize_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); rto->shutdown(); delete rto; } /*! * @brief is_alive()メソッドのテスト */ void test_is_alive() { // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
484  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
485  prop.setProperty("exec_cxt.periodic.rate","1000");
486  rto->setProperties(prop);
487  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
488 
489  RTC::ExecutionContext_ptr ec;
490  ec = rto->get_context(0);
491  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
492 
493  // Alive状態でinitialize()メソッド呼出しを行った場合、正常に動作するか?
494  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
495  rto->exit();
496  delete rto;
497  }
498 
505  {
506  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
507 
508  // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // finalize()呼出しにより、on_finalize()コールバックが呼び出されるか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // exit()呼び出しで、finalize()が有効となり実行される rto->exit(); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); delete rto; } /*! * @brief finalize()メソッドのテスト * * - ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? */ void test_finalize_participating_in_execution_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // ExecutionContextに登録しておく CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this())); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? */ void test_finalize_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); rto->shutdown(); delete rto; } /*! * @brief is_alive()メソッドのテスト */ void test_is_alive() { // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
510  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
511  prop.setProperty("exec_cxt.periodic.rate","1000");
512  rto->setProperties(prop);
513  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
514  RTC::ExecutionContext_ptr ec;
515  ec = rto->get_context(0);
516  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
517 
518  // finalize()呼出しにより、on_finalize()コールバックが呼び出されるか?
519  CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize"));
520 
521  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
522  // exit()呼び出しで、finalize()が有効となり実行される rto->exit(); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); delete rto; } /*! * @brief finalize()メソッドのテスト * * - ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? */ void test_finalize_participating_in_execution_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // ExecutionContextに登録しておく CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this())); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? */ void test_finalize_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); rto->shutdown(); delete rto; } /*! * @brief is_alive()メソッドのテスト */ void test_is_alive() { // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
523  rto->exit();
524  CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize"));
525  delete rto;
526  }
527 
534  {
535  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
536 
537  // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // ExecutionContextに登録しておく CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this())); rto->exit(); delete rto; } /*! * @brief finalize()メソッドのテスト * * - Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? */ void test_finalize_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize()); rto->shutdown(); delete rto; } /*! * @brief is_alive()メソッドのテスト */ void test_is_alive() { // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
539  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
540  prop.setProperty("exec_cxt.periodic.rate","1000");
541  rto->setProperties(prop);
542  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
543 
544  RTC::ExecutionContext_ptr ec;
545  ec = rto->get_context(0);
546  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
547 
548  // ExecutionContextに登録しておく
549  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
550 
551  // ExecutionContextに登録された状態でfinalize()を呼び出した場合、意図どおりのエラーを返すか?
552  CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize());
553 
554  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this()));
555  rto->exit();
556  delete rto;
557  }
558 
565  {
566  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
567 
568  // Created状態でfinalize()を呼出した場合、意図どおりのエラーで返るか?
569  CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize());
570  rto->shutdown();
571  delete rto;
572  }
573 
578  {
579  // test_initialize_in_Alive()にてテストを兼ねている } /*! * @brief exit()メソッドのテスト * * - exit()呼出しにより、当該コンポーネントがfinalize()されるか? * - exit()呼出しにより、当該コンポーネントが終状態に遷移するか? */ void test_exit() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
580  }
581 
588  void test_exit()
589  {
590  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
591  rto->setObjRef(rto->_this());
592 
593  // initialize()メソッド呼出しを行い、Alive状態に遷移させる coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
595  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
596  prop.setProperty("exec_cxt.periodic.rate","1000");
597  rto->setProperties(prop);
598  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
599 
600  RTC::ExecutionContext_ptr ec;
601  ec = rto->get_context(0);
602  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
603 
604  // コンポーネントをExecutionContextに登録してアクティブ化する CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this())); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this())); //Call start() for the state machine drive. ec->start(); coil::sleep(1); // exit()呼出しにより、当該コンポーネントがfinalize()されるか? // exit()呼出しにより、当該コンポーネントが終状態に遷移するか? CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this())); ec->stop(); coil::sleep(1); //Call remove_component(),to cancel the registered component. ec->remove_component(rto->_this()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit()); CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize")); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); delete rto; } /*! * @brief exit()メソッドのテスト * * - Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? */ void test_exit_in_Created() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto->setObjRef(rto->_this()); // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit()); rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - attach済みのRTCを正常にdetachできるか? */ void test_detach_executioncontext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
605  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
606  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
607  //Call start() for the state machine drive.
608  ec->start();
609  coil::sleep(1);
610 
611  // exit()呼出しにより、当該コンポーネントがfinalize()されるか?
612  // exit()呼出しにより、当該コンポーネントが終状態に遷移するか?
613  CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize"));
614  CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
615  ec->stop();
616  coil::sleep(1);
617  //Call remove_component(),to cancel the registered component.
618  ec->remove_component(rto->_this());
619  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit());
620  CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize"));
621  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
622 
623  delete rto;
624  }
625 
632  {
633  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
634  rto->setObjRef(rto->_this());
635 
636  // Create状態でexit()を呼出した場合、意図どおりのエラーを返すか?
637  CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit());
638 
639  rto->shutdown();
640  delete rto;
641  }
642 
649  {
650  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
651 
652  // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id = rto->attach_context(ec->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id); // 正常にdetachできるか? CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id)); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec)); delete ec; rto->shutdown(); delete rto; } /*! * @brief detach_executioncontext()メソッドのテスト * * - 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? */ void test_detach_executioncontext_with_illegal_id() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか? CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER, rto->detach_context(RTC::UniqueId(1))); rto->shutdown(); delete rto; } /*! * @brief get_context()メソッドのテスト * * - 指定したIDのExecutionContextを正しく取得できるか? */ void test_get_context() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
654  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
655 
656  // ExecutionContextにattachしておく
657  RTC::UniqueId id = rto->attach_context(ec->_this());
658  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id);
659 
660  // 正常にdetachできるか?
661  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id));
662  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
663  delete ec;
664  rto->shutdown();
665  delete rto;
666  }
667 
674  {
675  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
676 
677  // 存在しないIDでRTCのdetachを試みた場合、意図どおりのエラーを返すか?
678  CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,
679  rto->detach_context(RTC::UniqueId(1)));
680  rto->shutdown();
681  delete rto;
682  }
683 
690  {
691  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
692 
693  // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); CPPUNIT_ASSERT(id1 != id2); // 指定したIDのExecutionContextを正しく取得できるか? RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1); CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this())); RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2); CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_contexts()メソッドのテスト * * - attachされているExecutionContextをすべて正しく取得できるか? */ void test_get_contexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
695  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
697  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
698 
699  // ExecutionContextにattachしておく
700  RTC::UniqueId id1 = rto->attach_context(ec1->_this());
701  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
702  RTC::UniqueId id2 = rto->attach_context(ec2->_this());
703  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
704  CPPUNIT_ASSERT(id1 != id2);
705 
706  // 指定したIDのExecutionContextを正しく取得できるか?
707  RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1);
708  CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this()));
709  RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2);
710  CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this()));
711 
712  rto->detach_context(id2);
713  rto->detach_context(id1);
714  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2));
715  delete ec2;
716  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1));
717  delete ec1;
718 
719  rto->shutdown();
720  delete rto;
721 
722  }
723 
730  {
731  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
732 
733  // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // attachされているExecutionContextをすべて正しく取得できるか? RTC::ExecutionContextList* ecList = rto->get_participating_contexts(); CPPUNIT_ASSERT(ecList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length()); CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1])); CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this()) || (*ecList)[0]->_is_equivalent(ec2->_this())); CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this()) || (*ecList)[1]->_is_equivalent(ec2->_this())); rto->detach_context(id2); rto->detach_context(id1); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2)); delete ec2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1)); delete ec1; rto->shutdown(); delete rto; } /*! * @brief get_component_profile()メソッドのテスト * * - ComponentProfileを正しく取得できるか? */ void test_get_component_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく coil::Properties prop; prop.setProperty("instance_name", "INSTANCE_NAME"); prop.setProperty("type_name", "TYPE_NAME"); prop.setProperty("description", "DESCRIPTION"); prop.setProperty("version", "VERSION"); prop.setProperty("vendor", "VENDOR"); prop.setProperty("category", "CATEGORY"); rto->setProperties(prop); // ComponentProfileを正しく取得できるか? RTC::ComponentProfile* compProf = rto->get_component_profile(); CPPUNIT_ASSERT(compProf != NULL); CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"), std::string(compProf->instance_name)); CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"), std::string(compProf->type_name)); CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"), std::string(compProf->description)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(compProf->version)); CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"), std::string(compProf->vendor)); CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"), std::string(compProf->category)); rto->shutdown(); delete rto; } /*! * @brief add[In/Out]Port(),addPort()メソッドのテスト * * - Portを正しく登録できるか? * - 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? * - 登録済みのPortを正しく削除できるか? */ void test_add_removePort() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically PortMock* port0 = new PortMock(); port0->setName("port0"); // Portを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0)); PortMock* port1 = new PortMock(); port1->setName("port1"); CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1)); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); InPortMock* inport0 = new InPortMock("in","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); // InPort, OutPortを正しく登録できるか? CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0)); // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか? // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、 // 処理が戻ってこない。(デッドロック???) // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0)); // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0)); // 登録したPort参照をすべて正しく取得できるか? portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); // 登録済みのPortを正しく削除できるか? CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0)); CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0)); portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length()); delete outport0; delete inport0; delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief readAll(),setReadAll()メソッドのテスト * * - readAll()で全てのInPortのread()がコールされるか? * - setReadAll()で全てのInPortのread()がコールされるか? * - setReadAll()が正しく機能しているか? */ void test_readAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically InPortMock* inport0 = new InPortMock("in","TimedLong"); InPortMock* inport1 = new InPortMock("in2","TimedLong"); OutPortMock* outport0 = new OutPortMock("out","TimedLong"); rto->addInPort("in",*inport0); rto->addInPort("in2",*inport1); rto->addOutPort("out", *outport0); // readAll()で全てのInPortのread()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->readAll()); CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter()); // setReadAll()で全てのInPortのread()がコールされるか? rto->setReadAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); // setReadAll(),readAll()が正しく機能しているか? inport0->set_return(false); rto->setReadAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter()); // Because setReadAll(true,false) was called, // inport1.read() was not called. // inport0.read() return false. CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter()); rto->setReadAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->readAll()); CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); // Because setReadAll(true,true) was called, // inport0.read() return false, // but inport1.read() was called. CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,true); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->setReadAll(false,false); rto->on_execute(0); // Because setReadAll(false,true) was called, // inport0.read() and inport1.read() was not called. CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter()); rto->removeInPort(*inport0); rto->removeInPort(*inport1); rto->removeOutPort(*outport0); delete outport0; delete inport0; delete inport1; rto->shutdown(); delete rto; } /*! * @brief writeAll(),setWriteAll()メソッドのテスト * * - setWriteAll()で全てのOutPortのwrite()がコールされるか? * - writeAll()で全てのOutPortのwrite()がコールされるか? * - setWriteAll()が正しく機能しているか? */ void test_writeAll() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically OutPortMock* outport0 = new OutPortMock("out","TimedLong"); OutPortMock* outport1 = new OutPortMock("out2","TimedLong"); InPortMock* inport0 = new InPortMock("in","TimedLong"); rto->addOutPort("out",*outport0); rto->addOutPort("out2",*outport1); rto->addInPort("in", *inport0); // writeAll()で全てのOutPortのwrite()がコールされるか? CPPUNIT_ASSERT_EQUAL(true, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter()); // setWriteAll()で全てのOutPortのwrite()がコールされるか? rto->setWriteAll(); rto->on_execute(0); CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); // setWriteAll(),writeAll()が正しく機能しているか? outport0->set_return(false); rto->setWriteAll(true,false); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter()); // Because setWriteAll(true,false) was called, // outport1.write() was not called. // outport0.write() return false. CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter()); rto->setWriteAll(true,true); CPPUNIT_ASSERT_EQUAL(false, rto->writeAll()); CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); // Because setWriteAll(true,true) was called, // outport0.write() return false, // but outport1.write() was called. CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,true); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->setWriteAll(false,false); rto->on_execute(0); // Because setWriteAll(false,true) was called, // outport0.write() and outport1.write() was not called. CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter()); CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter()); rto->removeOutPort(*outport0); rto->removeOutPort(*outport1); rto->removeInPort(*inport0); delete outport0; delete outport1; delete inport0; rto->shutdown(); delete rto; } /*! * @brief get_ports()メソッドのテスト * * - 登録したPort参照をすべて正しく取得できるか? */ void test_get_ports() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Portを登録しておく PortMock* port0 = new PortMock(); port0->setName("port0"); rto->addPort(*port0); PortMock* port1 = new PortMock(); port1->setName("port1"); rto->addPort(*port1); // 登録したPort参照をすべて正しく取得できるか? RTC::PortServiceList* portList = rto->get_ports(); CPPUNIT_ASSERT(portList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length()); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this()))); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1)); CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0)); delete port1; delete port0; rto->shutdown(); delete rto; } /*! * @brief get_execution_context_services()メソッドのテスト * * - ExecutionContextServiceをすべて正しく取得できるか? */ /* void test_get_execution_context_services() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
735  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
737  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
738 
739  // ExecutionContextにattachしておく
740  RTC::UniqueId id1 = rto->attach_context(ec1->_this());
741  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
742  RTC::UniqueId id2 = rto->attach_context(ec2->_this());
743  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
744 
745  // attachされているExecutionContextをすべて正しく取得できるか?
747  CPPUNIT_ASSERT(ecList != NULL);
748  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length());
749  CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1]));
750  CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this())
751  || (*ecList)[0]->_is_equivalent(ec2->_this()));
752  CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this())
753  || (*ecList)[1]->_is_equivalent(ec2->_this()));
754 
755 
756  rto->detach_context(id2);
757  rto->detach_context(id1);
758 
759  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2));
760  delete ec2;
761  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1));
762  delete ec1;
763 
764  rto->shutdown();
765  delete rto;
766  }
767 
774  {
775  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
776 
777  // ComponentProfileとして取得されるべき情報をあらかじめ設定しておく
779  prop.setProperty("instance_name", "INSTANCE_NAME");
780  prop.setProperty("type_name", "TYPE_NAME");
781  prop.setProperty("description", "DESCRIPTION");
782  prop.setProperty("version", "VERSION");
783  prop.setProperty("vendor", "VENDOR");
784  prop.setProperty("category", "CATEGORY");
785  rto->setProperties(prop);
786 
787  // ComponentProfileを正しく取得できるか?
788  RTC::ComponentProfile* compProf = rto->get_component_profile();
789  CPPUNIT_ASSERT(compProf != NULL);
790 
791  CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"),
792  std::string(compProf->instance_name));
793  CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"),
794  std::string(compProf->type_name));
795  CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"),
796  std::string(compProf->description));
797  CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
798  std::string(compProf->version));
799  CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"),
800  std::string(compProf->vendor));
801  CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"),
802  std::string(compProf->category));
803  rto->shutdown();
804  delete rto;
805 
806  }
807 
816  {
817  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
818 
819  PortMock* port0 = new PortMock();
820  port0->setName("port0");
821  // Portを正しく登録できるか?
822  CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0));
823  // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか?
824  // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、
825  // 処理が戻ってこない。(デッドロック???)
826  // CPPUNIT_ASSERT_EQUAL(false, rto->addPort(*port0));
827 
828  PortMock* port1 = new PortMock();
829  port1->setName("port1");
830  CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1));
831 
832  // 登録したPort参照をすべて正しく取得できるか?
833  RTC::PortServiceList* portList = rto->get_ports();
834  CPPUNIT_ASSERT(portList != NULL);
835  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
836 
837  // 登録済みのPortを正しく削除できるか?
838  CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1));
839  CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0));
840 
841  InPortMock* inport0 = new InPortMock("in","TimedLong");
842  OutPortMock* outport0 = new OutPortMock("out","TimedLong");
843  // InPort, OutPortを正しく登録できるか?
844  CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0));
845  CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0));
846  // 既に登録済みのポートと同じポート名のPortを登録しようとした場合に失敗するか?
847  // PortBase::updateConnectors()内、Guard guard(m_profile_mutex);でロックされ、
848  // 処理が戻ってこない。(デッドロック???)
849  // CPPUNIT_ASSERT_EQUAL(false, rto->addInPort("in",*inport0));
850  // CPPUNIT_ASSERT_EQUAL(false, rto->addOutPort("out", *outport0));
851 
852  // 登録したPort参照をすべて正しく取得できるか?
853  portList = rto->get_ports();
854  CPPUNIT_ASSERT(portList != NULL);
855  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
856 
857  // 登録済みのPortを正しく削除できるか?
858  CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0));
859  CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0));
860 
861  portList = rto->get_ports();
862  CPPUNIT_ASSERT(portList != NULL);
863  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length());
864 
865  delete outport0;
866  delete inport0;
867  delete port1;
868  delete port0;
869 
870  rto->shutdown();
871  delete rto;
872 
873  }
874 
883  {
884  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
885 
886  InPortMock* inport0 = new InPortMock("in","TimedLong");
887  InPortMock* inport1 = new InPortMock("in2","TimedLong");
888  OutPortMock* outport0 = new OutPortMock("out","TimedLong");
889 
890  rto->addInPort("in",*inport0);
891  rto->addInPort("in2",*inport1);
892  rto->addOutPort("out", *outport0);
893 
894  // readAll()で全てのInPortのread()がコールされるか?
895  CPPUNIT_ASSERT_EQUAL(true, rto->readAll());
896  CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter());
897  CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter());
898 
899  // setReadAll()で全てのInPortのread()がコールされるか?
900  rto->setReadAll();
901  rto->on_execute(0);
902  CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter());
903  CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter());
904 
905  // setReadAll(),readAll()が正しく機能しているか?
906  inport0->set_return(false);
907  rto->setReadAll(true,false);
908  CPPUNIT_ASSERT_EQUAL(false, rto->readAll());
909  CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter());
910  // Because setReadAll(true,false) was called,
911  // inport1.read() was not called.
912  // inport0.read() return false.
913  CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter());
914 
915  rto->setReadAll(true,true);
916  CPPUNIT_ASSERT_EQUAL(false, rto->readAll());
917  CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
918  // Because setReadAll(true,true) was called,
919  // inport0.read() return false,
920  // but inport1.read() was called.
921  CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
922 
923  rto->setReadAll(false,true);
924  rto->on_execute(0);
925  // Because setReadAll(false,true) was called,
926  // inport0.read() and inport1.read() was not called.
927  CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
928  CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
929 
930  rto->setReadAll(false,false);
931  rto->on_execute(0);
932  // Because setReadAll(false,true) was called,
933  // inport0.read() and inport1.read() was not called.
934  CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
935  CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
936 
937  rto->removeInPort(*inport0);
938  rto->removeInPort(*inport1);
939  rto->removeOutPort(*outport0);
940 
941  delete outport0;
942  delete inport0;
943  delete inport1;
944 
945  rto->shutdown();
946  delete rto;
947  }
948 
949 
958  {
959  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
960 
961  OutPortMock* outport0 = new OutPortMock("out","TimedLong");
962  OutPortMock* outport1 = new OutPortMock("out2","TimedLong");
963  InPortMock* inport0 = new InPortMock("in","TimedLong");
964 
965  rto->addOutPort("out",*outport0);
966  rto->addOutPort("out2",*outport1);
967  rto->addInPort("in", *inport0);
968 
969  // writeAll()で全てのOutPortのwrite()がコールされるか?
970  CPPUNIT_ASSERT_EQUAL(true, rto->writeAll());
971  CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter());
972  CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter());
973 
974  // setWriteAll()で全てのOutPortのwrite()がコールされるか?
975  rto->setWriteAll();
976  rto->on_execute(0);
977  CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter());
978  CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter());
979 
980  // setWriteAll(),writeAll()が正しく機能しているか?
981  outport0->set_return(false);
982  rto->setWriteAll(true,false);
983  CPPUNIT_ASSERT_EQUAL(false, rto->writeAll());
984  CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter());
985  // Because setWriteAll(true,false) was called,
986  // outport1.write() was not called.
987  // outport0.write() return false.
988  CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter());
989 
990  rto->setWriteAll(true,true);
991  CPPUNIT_ASSERT_EQUAL(false, rto->writeAll());
992  CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
993  // Because setWriteAll(true,true) was called,
994  // outport0.write() return false,
995  // but outport1.write() was called.
996  CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
997 
998  rto->setWriteAll(false,true);
999  rto->on_execute(0);
1000  // Because setWriteAll(false,true) was called,
1001  // outport0.write() and outport1.write() was not called.
1002  CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
1003  CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
1004 
1005  rto->setWriteAll(false,false);
1006  rto->on_execute(0);
1007  // Because setWriteAll(false,true) was called,
1008  // outport0.write() and outport1.write() was not called.
1009  CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
1010  CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
1011 
1012  rto->removeOutPort(*outport0);
1013  rto->removeOutPort(*outport1);
1014  rto->removeInPort(*inport0);
1015 
1016  delete outport0;
1017  delete outport1;
1018  delete inport0;
1019 
1020  rto->shutdown();
1021  delete rto;
1022  }
1023 
1024 
1031  {
1032  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1033 
1034  // Portを登録しておく
1035  PortMock* port0 = new PortMock();
1036  port0->setName("port0");
1037  rto->addPort(*port0);
1038 
1039  PortMock* port1 = new PortMock();
1040  port1->setName("port1");
1041  rto->addPort(*port1);
1042 
1043  // 登録したPort参照をすべて正しく取得できるか?
1044  RTC::PortServiceList* portList = rto->get_ports();
1045  CPPUNIT_ASSERT(portList != NULL);
1046  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
1047  CPPUNIT_ASSERT(CORBA::Long(-1)
1048  != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this())));
1049  CPPUNIT_ASSERT(CORBA::Long(-1)
1050  != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this())));
1051 
1052  CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1));
1053  CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0));
1054 
1055  delete port1;
1056  delete port0;
1057 
1058  rto->shutdown();
1059  delete rto;
1060 
1061  }
1062 
1068 /*
1069  void test_get_execution_context_services()
1070  {
1071  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1072 
1073  // ExecutionContextを生成する RTC::PeriodicExecutionContext* ec1 = new RTC::PeriodicExecutionContext(); // will be deleted automatically RTC::PeriodicExecutionContext* ec2 = new RTC::PeriodicExecutionContext(); // will be deleted automatically // ExecutionContextにattachしておく RTC::UniqueId id1 = rto->attach_context(ec1->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1); RTC::UniqueId id2 = rto->attach_context(ec2->_this()); CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2); // ExecutionContextServiceをすべて正しく取得できるか? // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。 RTC::ExecutionContextServiceList* ecSvcList // = rto->get_execution_context_services(); = rto->get_owned_contexts(); CPPUNIT_ASSERT(ecSvcList != NULL); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this()))); CPPUNIT_ASSERT(CORBA::Long(-1) != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this()))); } */ void test_get_owned_organizations() { // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
1074  RTC::PeriodicExecutionContext* ec1
1075  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
1076  RTC::PeriodicExecutionContext* ec2
1077  = new RTC::PeriodicExecutionContext(); // will be deleted automatically
1078 
1079  // ExecutionContextにattachしておく
1080  RTC::UniqueId id1 = rto->attach_context(ec1->_this());
1081  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
1082  RTC::UniqueId id2 = rto->attach_context(ec2->_this());
1083  CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
1084 
1085  // ExecutionContextServiceをすべて正しく取得できるか?
1086  // (注) RTC::PeriodicExecutionContextはExecutionContextServiceのサブクラスになっている。
1087  RTC::ExecutionContextServiceList* ecSvcList
1088 // = rto->get_execution_context_services();
1089  = rto->get_owned_contexts();
1090  CPPUNIT_ASSERT(ecSvcList != NULL);
1091  CPPUNIT_ASSERT(CORBA::Long(-1)
1092  != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec1->_this())));
1093  CPPUNIT_ASSERT(CORBA::Long(-1)
1094  != CORBA_SeqUtil::find(*ecSvcList, ExecutionContextServiceFinder(ec2->_this())));
1095  }
1096 */
1098  {
1099  // テスト対象が未実装につき、テスト未実装 } /*! * @brief get_sdo_id()メソッドのテスト * * - SDO IDを取得できるか? * - 取得されたSDO IDは一意か? */ void test_get_sdo_id() { RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto1->setInstanceName("INSTANCE_NAME 1"); std::string str1(rto1->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1); RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically rto2->setInstanceName("INSTANCE_NAME 2"); std::string str2(rto2->getInstanceName()); CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2); // SDO IDを取得できるか? char* id1 = rto1->get_sdo_id(); CPPUNIT_ASSERT(id1 != NULL); char* id2 = rto2->get_sdo_id(); CPPUNIT_ASSERT(id2 != NULL); // 取得されたSDO IDは一意か? // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。 // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。 // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。 CPPUNIT_ASSERT(id1 != id2); rto2->shutdown(); delete rto2; rto1->shutdown(); delete rto1; } /*! * @brief get_sdo_type()メソッドのテスト * * - SDOタイプを取得できるか? */ void test_get_sdo_type() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
1100  }
1101 
1109  {
1110  RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1111  rto1->setInstanceName("INSTANCE_NAME 1");
1112  std::string str1(rto1->getInstanceName());
1113  CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1);
1114  RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1115  rto2->setInstanceName("INSTANCE_NAME 2");
1116  std::string str2(rto2->getInstanceName());
1117  CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2);
1118 
1119  // SDO IDを取得できるか?
1120  char* id1 = rto1->get_sdo_id();
1121  CPPUNIT_ASSERT(id1 != NULL);
1122  char* id2 = rto2->get_sdo_id();
1123  CPPUNIT_ASSERT(id2 != NULL);
1124 
1125  // 取得されたSDO IDは一意か?
1126  // (注) instance_nameがSDO IDとしてそのまま使用されることに注意。
1127  // つまり、実装上、SDO IDの一意性はinstance_nameの一意性に基づいている。
1128  // 仕様上、instance_nameは一意でなければならないので、首尾一貫している。
1129  CPPUNIT_ASSERT(id1 != id2);
1130 
1131  rto2->shutdown();
1132  delete rto2;
1133  rto1->shutdown();
1134  delete rto1;
1135  }
1136 
1143  {
1144  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1145 
1146  // ※ 実装上、type_nameがSDOタイプとして使用されているため、ここで準備設定している coil::Properties prop; prop.setProperty("type_name", "TYPE_NAME"); rto->setProperties(prop); // SDOタイプを取得できるか? char* sdoType = rto->get_sdo_type(); CPPUNIT_ASSERT(sdoType != NULL); rto->shutdown(); delete rto; } /*! * @brief get_device_profile()メソッドのテスト * * - DeviceProfileを正しく取得できるか? */ void test_get_device_profile() { // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
1148  prop.setProperty("type_name", "TYPE_NAME");
1149  rto->setProperties(prop);
1150 
1151  // SDOタイプを取得できるか?
1152  char* sdoType = rto->get_sdo_type();
1153  CPPUNIT_ASSERT(sdoType != NULL);
1154 
1155  rto->shutdown();
1156  delete rto;
1157  }
1158 
1165  {
1166  // test_get_configuration_and_set_device_profile_and_get_device_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく取得できるか? */ void test_get_service_profile() { // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
1167  }
1168 
1175  {
1176  // test_get_configuration_and_set_service_profile_and_get_service_profileで兼ねる } /*! * @brief get_service_profile()メソッドのテスト * * - 引数にNULLを指定した場合、意図どおりの例外がスローされるか? * - 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? */ void test_get_service_profile_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_service_profile("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_sdo_service()メソッドのテスト * * - 指定したIDのSDOServiceを正しく取得できるか? */ void test_get_sdo_service() { // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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 // RTObject_cpp
1177  }
1178 
1186  {
1187  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1188 
1189  // 引数にNULLを指定した場合、意図どおりの例外がスローされるか?
1190  try
1191  {
1192  rto->get_service_profile(NULL);
1193  CPPUNIT_FAIL("Exception not thrown.");
1194  }
1195  catch (SDOPackage::InvalidParameter expected)
1196  {
1197  // 意図どおりの例外をキャッチした
1198  }
1199  catch (...)
1200  {
1201  // 意図しない例外をキャッチした
1202  CPPUNIT_FAIL("Unexpected exception caught.");
1203  }
1204 
1205  // 引数に存在しないIDを指定した場合、意図どおりの例外がスローされるか?
1206  try
1207  {
1208  rto->get_service_profile("INEXIST ID");
1209  CPPUNIT_FAIL("Exception not thrown.");
1210  }
1211  catch (SDOPackage::InvalidParameter expected)
1212  {
1213  // 意図どおりの例外をキャッチした
1214  }
1215  catch (...)
1216  {
1217  // 意図しない例外をキャッチした
1218  CPPUNIT_FAIL("Unexpected exception caught.");
1219  }
1220  rto->shutdown();
1221  delete rto;
1222  }
1223 
1230  {
1231  // test_get_configuration_and_set_service_profile_and_get_sdo_serviceで兼ねる } void test_get_sdo_service_with_illegal_arguments() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // 引数にNULLを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service(NULL); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか? try { rto->get_sdo_service("INEXIST ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { // 意図どおりの例外をキャッチした } catch (...) { // 意図しない例外をキャッチした CPPUNIT_FAIL("Unexpected exception caught."); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドのテスト * * - Configuration::set_device_profile()を通して、DeviceProfileを正しく設定できるか? * - 設定されたDeviceProfileを、get_device_profile()で正しく取得できるか? */ void test_get_configuration_and_set_device_profile_and_get_device_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // DeviceProfileを準備しておく SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; devProf.properties.length(1); devProf.properties[0].name = "PROPERTIES NAME"; devProf.properties[0].value <<= "PROPERTIES VALUE"; // Configurationインタフェースを取得し、DeviceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); cfg->set_device_profile(devProf); // DeviceProfileを取得して、正しく設定されたことを確認する SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet->device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet->manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet->model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet->version)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"), std::string(devProfRet->properties[0].name)); { const char* value; devProfRet->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value)); } rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_serivce_profile()メソッドのテスト * * - Configuration::set_service_profile()を通して、ServiceProfileを正しく設定できるか? * - 設定されたServiceProfileを、get_service_profile()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profile()を用いてServiceProfileを取得して、正しく設定されたことを確認する SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1"); CPPUNIT_ASSERT(svcProfRet1 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfRet1->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string(svcProfRet1->properties[0].name)); { const char* value; svcProfRet1->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2"); CPPUNIT_ASSERT(svcProfRet2 != NULL); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string(svcProfRet2->interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string(svcProfRet2->properties[0].name)); { const char* value; svcProfRet2->properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_service_profiles()メソッドのテスト * * - 設定されたServiceProfileを、get_service_profiles()で正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_service_profiles() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // get_service_profiles()を使ってServiceProfile群を取得して、正しく設定されたことを確認する SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles(); CPPUNIT_ASSERT(svcProfList != NULL); CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string((*svcProfList)[svcProfIdx1].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string((*svcProfList)[svcProfIdx1].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx1].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"), std::string((*svcProfList)[svcProfIdx1].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find( *svcProfList, ServiceProfileFinder("ID 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string((*svcProfList)[svcProfIdx2].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"), std::string((*svcProfList)[svcProfIdx2].interface_type)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), (*svcProfList)[svcProfIdx2].properties.length()); CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"), std::string((*svcProfList)[svcProfIdx2].properties[0].name)); { const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_sdo_service()メソッドのテスト * * - Configuration::set_service_profile()を通して、SDOServiceを正しく設定できるか? * - get_sdo_service()を用いて、設定されているSDPServiceを正しく取得できるか? */ void test_get_configuration_and_set_service_profile_and_get_sdo_service() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); // 指定したIDのSDOServiceを正しく取得できるか? SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1)); CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this())); SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2"); CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2)); CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_service_profile()メソッドのテスト * * - 指定したIDのServiceProfileを正しく削除できるか? */ void test_get_configuration_and_remove_service_profile() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // SDOServiceを準備する SDOServiceMock* sdoSvc1 = new SDOServiceMock(); SDOServiceMock* sdoSvc2 = new SDOServiceMock(); // ServiceProfileを準備しておく SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; svcProf1.properties.length(1); svcProf1.properties[0].name = "PROPERTIES NAME 1"; svcProf1.properties[0].value <<= "3.14159"; svcProf1.service = sdoSvc1->_this(); SDOPackage::ServiceProfile svcProf2; svcProf2.id = "ID 2"; svcProf2.interface_type = "INTERFACE_TYPE 2"; svcProf2.properties.length(1); svcProf2.properties[0].name = "PROPERTIES NAME 2"; svcProf2.properties[0].value <<= "2.71828"; svcProf2.service = sdoSvc2->_this(); // Configurationインタフェースを取得し、ServiceProfileを設定する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); cfg->add_service_profile(svcProf1); cfg->add_service_profile(svcProf2); CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL); CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); // 設定したうち、片方のServiceProfileをremoveして、正しくremoveされたことを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1")); try { rto->get_service_profile("ID 1"); CPPUNIT_FAIL("Expected exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2)); delete sdoSvc2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1)); delete sdoSvc1; rto->shutdown(); delete rto; } /*! * @brief get_configuration()メソッドとget_organizations()メソッドのテスト * * - Configuration::add_organization()でOrganizationを正しく追加できるか? * - get_organizations()で、登録されているOrganizationを正しく取得できるか? */ void test_get_configuration_and_add_organization_and_get_organizations() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // get_organizations()を用いてOrganization群を正しく取得できるか? SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1); CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"), std::string((*orgList)[orgIdx1]->get_organization_id())); CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2")); CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2); CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"), std::string((*orgList)[orgIdx2]->get_organization_id())); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief Configuration::remove_organization()メソッドのテスト * * - 指定したIDのOrganizationを正しく削除できるか? */ void test_get_configuration_and_remove_organization() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Organizationを準備する OrganizationMock* org1 = new OrganizationMock("ORG 1"); OrganizationMock* org2 = new OrganizationMock("ORG 2"); // Configurationインタフェースを取得し、Organizationを追加する SDOPackage::Configuration_ptr cfg = rto->get_configuration(); CPPUNIT_ASSERT(! CORBA::is_nil(cfg)); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this())); CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this())); // 追加されていることを確認しておく SDOPackage::OrganizationList* orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length()); // 追加したうち、片方のOrganizationをremoveし、正しくremoveされていることを確認する CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1")); orgList = rto->get_organizations(); CPPUNIT_ASSERT(orgList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length()); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2)); delete org2; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1)); delete org1; rto->shutdown(); delete rto; } /*! * @brief get_monitoring()メソッドのテスト */ void test_get_monitoring() { // テスト対象が未実装につき、テストも未実装 } /*! * @brief get_status()メソッドのテスト * * - 指定した名称のstatus値を正しく取得できるか? */ void test_get_status() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1"); CPPUNIT_ASSERT(valueAnyRet1 != NULL); { CORBA::Float value; *valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2"); CPPUNIT_ASSERT(valueAnyRet2 != NULL); { CORBA::Float value; *valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief get_status_list()メソッドのテスト * * - 設定されているすべてのstatusを正しく取得できるか? */ void test_get_status_list() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically // Mockの機能を用いてstatusを設定しておく CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159); rto->set_status("STATUS 1", valueAny1); CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828); rto->set_status("STATUS 2", valueAny2); // 設定したstatusを正しく取得できるか? SDOPackage::NVList* statusList = rto->get_status_list(); CPPUNIT_ASSERT(statusList != NULL); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length()); const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1"); { CORBA::Float value; valueAnyRet1 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2"); { CORBA::Float value; valueAnyRet2 >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } rto->shutdown(); delete rto; } /*! * @brief finalizeContexts()メソッドのテスト * * - 全コンテキストの登録を削除できるか? */ void test_finalizeContexts() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); // initialize()で、m_eclistへ登録し、m_ecMineをstart CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize()); CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist()); RTC::ExecutionContext_ptr ec; ec = rto->get_context(0); CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec)); rto->finalizeContexts(); // 全コンテキストが削除されたか? CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist()); rto->exit(); delete rto; } /*! * @brief bindContext()メソッドのテスト * * - ExecutionContextを正しく設定できるか? */ void test_bindContext() { RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); coil::Properties prop; prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext"); prop.setProperty("exec_cxt.periodic.rate","1000"); rto->setProperties(prop); RTC::ExecutionContext_ptr ec; // nilを設定した場合、-1を返すか? ec = RTC::ExecutionContext::_nil(); int id = (int)(rto->bindContext(ec)); CPPUNIT_ASSERT_EQUAL(-1, id); // m_ecMine 未登録の場合、m_ecMineの番号を返すか? RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext(); ec = pec->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか? rto->ecMine[0] = RTC::ExecutionContextService::_nil(); rto->set_ecMine(); RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext(); ec = pec2->getObjRef(); id = (int)(rto->bindContext(ec)); // [0]に登録されるか? CPPUNIT_ASSERT_EQUAL(0, id); // 正しく登録されているか? CPPUNIT_ASSERT(rto->chk_ecMine(id,ec)); rto->exit(); m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec)); delete pec; m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2)); delete pec2; rto->shutdown(); delete rto; } }; }; // namespace RTObject /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests); #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;