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; 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
1232  }
1233 
1235  {
1236  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1237 
1238  // 引数にNULLを指定した場合、意図どおりの例外がスローされるか?
1239  try
1240  {
1241  rto->get_sdo_service(NULL);
1242  CPPUNIT_FAIL("Exception not thrown.");
1243  }
1244  catch (SDOPackage::InvalidParameter expected)
1245  {
1246  // 意図どおりの例外をキャッチした
1247  }
1248  catch (...)
1249  {
1250  // 意図しない例外をキャッチした
1251  CPPUNIT_FAIL("Unexpected exception caught.");
1252  }
1253 
1254  // 引数に、存在しないIDを指定した場合、意図どおりの例外がスローされるか?
1255  try
1256  {
1257  rto->get_sdo_service("INEXIST ID");
1258  CPPUNIT_FAIL("Exception not thrown.");
1259  }
1260  catch (SDOPackage::InvalidParameter expected)
1261  {
1262  // 意図どおりの例外をキャッチした
1263  }
1264  catch (...)
1265  {
1266  // 意図しない例外をキャッチした
1267  CPPUNIT_FAIL("Unexpected exception caught.");
1268  }
1269 
1270  rto->shutdown();
1271  delete rto;
1272  }
1273 
1281  {
1282  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1283 
1284  // DeviceProfileを準備しておく
1285  SDOPackage::DeviceProfile devProf;
1286  devProf.device_type = "DEVICE_TYPE";
1287  devProf.manufacturer = "MANUFACTURER";
1288  devProf.model = "MODEL";
1289  devProf.version = "VERSION";
1290  devProf.properties.length(1);
1291  devProf.properties[0].name = "PROPERTIES NAME";
1292  devProf.properties[0].value <<= "PROPERTIES VALUE";
1293 
1294  // 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
1295  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1296  cfg->set_device_profile(devProf);
1297  // 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
1298  SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile();
1299  CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"),
1300  std::string(devProfRet->device_type));
1301  CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"),
1302  std::string(devProfRet->manufacturer));
1303  CPPUNIT_ASSERT_EQUAL(std::string("MODEL"),
1304  std::string(devProfRet->model));
1305  CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
1306  std::string(devProfRet->version));
1307  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length());
1308  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"),
1309  std::string(devProfRet->properties[0].name));
1310  {
1311  const char* value; devProfRet->properties[0].value >>= value;
1312  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value));
1313  }
1314 
1315  rto->shutdown();
1316  delete rto;
1317  }
1318 
1326  {
1327  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1328 
1329  // 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
1330  SDOServiceMock* sdoSvc1 = new SDOServiceMock();
1331  SDOServiceMock* sdoSvc2 = new SDOServiceMock();
1332 
1333  // ServiceProfileを準備しておく
1334  SDOPackage::ServiceProfile svcProf1;
1335  svcProf1.id = "ID 1";
1336  svcProf1.interface_type = "INTERFACE_TYPE 1";
1337  svcProf1.properties.length(1);
1338  svcProf1.properties[0].name = "PROPERTIES NAME 1";
1339  svcProf1.properties[0].value <<= "3.14159";
1340  svcProf1.service = sdoSvc1->_this();
1341 
1342  SDOPackage::ServiceProfile svcProf2;
1343  svcProf2.id = "ID 2";
1344  svcProf2.interface_type = "INTERFACE_TYPE 2";
1345  svcProf2.properties.length(1);
1346  svcProf2.properties[0].name = "PROPERTIES NAME 2";
1347  svcProf2.properties[0].value <<= "2.71828";
1348  svcProf2.service = sdoSvc2->_this();
1349 
1350  // 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
1351  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1352  CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
1353  cfg->add_service_profile(svcProf1);
1354  cfg->add_service_profile(svcProf2);
1355 
1356  // 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
1357  SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1");
1358  CPPUNIT_ASSERT(svcProfRet1 != NULL);
1359  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id));
1360  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
1361  std::string(svcProfRet1->interface_type));
1362  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length());
1363  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"),
1364  std::string(svcProfRet1->properties[0].name));
1365  {
1366  const char* value; svcProfRet1->properties[0].value >>= value;
1367  CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
1368  }
1369 
1370  SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2");
1371  CPPUNIT_ASSERT(svcProfRet2 != NULL);
1372  CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id));
1373  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"),
1374  std::string(svcProfRet2->interface_type));
1375  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length());
1376  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"),
1377  std::string(svcProfRet2->properties[0].name));
1378  {
1379  const char* value; svcProfRet2->properties[0].value >>= value;
1380  CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
1381  }
1382 
1383  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
1384  delete sdoSvc2;
1385  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
1386  delete sdoSvc1;
1387 
1388  rto->shutdown();
1389  delete rto;
1390  }
1391 
1398  {
1399  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1400 
1401  // 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
1402  SDOServiceMock* sdoSvc1 = new SDOServiceMock();
1403  SDOServiceMock* sdoSvc2 = new SDOServiceMock();
1404 
1405  // ServiceProfileを準備しておく
1406  SDOPackage::ServiceProfile svcProf1;
1407  svcProf1.id = "ID 1";
1408  svcProf1.interface_type = "INTERFACE_TYPE 1";
1409  svcProf1.properties.length(1);
1410  svcProf1.properties[0].name = "PROPERTIES NAME 1";
1411  svcProf1.properties[0].value <<= "3.14159";
1412  svcProf1.service = sdoSvc1->_this();
1413 
1414  SDOPackage::ServiceProfile svcProf2;
1415  svcProf2.id = "ID 2";
1416  svcProf2.interface_type = "INTERFACE_TYPE 2";
1417  svcProf2.properties.length(1);
1418  svcProf2.properties[0].name = "PROPERTIES NAME 2";
1419  svcProf2.properties[0].value <<= "2.71828";
1420  svcProf2.service = sdoSvc2->_this();
1421 
1422  // 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
1423  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1424  CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
1425  cfg->add_service_profile(svcProf1);
1426  cfg->add_service_profile(svcProf2);
1427 
1428  // 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
1429  SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles();
1430  CPPUNIT_ASSERT(svcProfList != NULL);
1431 
1432  CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find(
1433  *svcProfList, ServiceProfileFinder("ID 1"));
1434  CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1);
1435  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
1436  std::string((*svcProfList)[svcProfIdx1].id));
1437  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
1438  std::string((*svcProfList)[svcProfIdx1].interface_type));
1439  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1),
1440  (*svcProfList)[svcProfIdx1].properties.length());
1441  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"),
1442  std::string((*svcProfList)[svcProfIdx1].properties[0].name));
1443  {
1444  const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value;
1445  CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
1446  }
1447 
1448  CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find(
1449  *svcProfList, ServiceProfileFinder("ID 2"));
1450  CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2);
1451  CPPUNIT_ASSERT_EQUAL(std::string("ID 2"),
1452  std::string((*svcProfList)[svcProfIdx2].id));
1453  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"),
1454  std::string((*svcProfList)[svcProfIdx2].interface_type));
1455  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1),
1456  (*svcProfList)[svcProfIdx2].properties.length());
1457  CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"),
1458  std::string((*svcProfList)[svcProfIdx2].properties[0].name));
1459  {
1460  const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value;
1461  CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
1462  }
1463 
1464  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
1465  delete sdoSvc2;
1466  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
1467  delete sdoSvc1;
1468 
1469  rto->shutdown();
1470  delete rto;
1471  }
1472 
1480  {
1481  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1482 
1483  // 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
1484  SDOServiceMock* sdoSvc1 = new SDOServiceMock();
1485  SDOServiceMock* sdoSvc2 = new SDOServiceMock();
1486 
1487  // ServiceProfileを準備しておく
1488  SDOPackage::ServiceProfile svcProf1;
1489  svcProf1.id = "ID 1";
1490  svcProf1.interface_type = "INTERFACE_TYPE 1";
1491  svcProf1.properties.length(1);
1492  svcProf1.properties[0].name = "PROPERTIES NAME 1";
1493  svcProf1.properties[0].value <<= "3.14159";
1494  svcProf1.service = sdoSvc1->_this();
1495 
1496  SDOPackage::ServiceProfile svcProf2;
1497  svcProf2.id = "ID 2";
1498  svcProf2.interface_type = "INTERFACE_TYPE 2";
1499  svcProf2.properties.length(1);
1500  svcProf2.properties[0].name = "PROPERTIES NAME 2";
1501  svcProf2.properties[0].value <<= "2.71828";
1502  svcProf2.service = sdoSvc2->_this();
1503 
1504  // 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
1505  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1506  CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
1507  cfg->add_service_profile(svcProf1);
1508  cfg->add_service_profile(svcProf2);
1509 
1510  // 指定したIDのSDOServiceを正しく取得できるか?
1511  SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1");
1512  CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1));
1513  CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this()));
1514 
1515  SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2");
1516  CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2));
1517  CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this()));
1518 
1519  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
1520  delete sdoSvc2;
1521  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
1522  delete sdoSvc1;
1523 
1524  rto->shutdown();
1525  delete rto;
1526 
1527  }
1528 
1535  {
1536  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1537 
1538  // 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
1539  SDOServiceMock* sdoSvc1 = new SDOServiceMock();
1540  SDOServiceMock* sdoSvc2 = new SDOServiceMock();
1541 
1542  // ServiceProfileを準備しておく
1543  SDOPackage::ServiceProfile svcProf1;
1544  svcProf1.id = "ID 1";
1545  svcProf1.interface_type = "INTERFACE_TYPE 1";
1546  svcProf1.properties.length(1);
1547  svcProf1.properties[0].name = "PROPERTIES NAME 1";
1548  svcProf1.properties[0].value <<= "3.14159";
1549  svcProf1.service = sdoSvc1->_this();
1550 
1551  SDOPackage::ServiceProfile svcProf2;
1552  svcProf2.id = "ID 2";
1553  svcProf2.interface_type = "INTERFACE_TYPE 2";
1554  svcProf2.properties.length(1);
1555  svcProf2.properties[0].name = "PROPERTIES NAME 2";
1556  svcProf2.properties[0].value <<= "2.71828";
1557  svcProf2.service = sdoSvc2->_this();
1558 
1559  // 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
1560  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1561  CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
1562  cfg->add_service_profile(svcProf1);
1563  cfg->add_service_profile(svcProf2);
1564  CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL);
1565  CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL);
1566 
1567  // 設定したうち、片方の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
1568  CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1"));
1569  try
1570  {
1571  rto->get_service_profile("ID 1");
1572  CPPUNIT_FAIL("Expected exception not thrown.");
1573  }
1574  catch (SDOPackage::InvalidParameter expected) {}
1575  CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL);
1576 
1577  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
1578  delete sdoSvc2;
1579  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
1580  delete sdoSvc1;
1581 
1582  rto->shutdown();
1583  delete rto;
1584  }
1585 
1593  {
1594  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1595 
1596  // 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
1597  OrganizationMock* org1 = new OrganizationMock("ORG 1");
1598  OrganizationMock* org2 = new OrganizationMock("ORG 2");
1599 
1600  // 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
1601  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1602  CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
1603  CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this()));
1604  CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this()));
1605 
1606  // get_organizations()を用いてOrganization群を正しく取得できるか?
1607  SDOPackage::OrganizationList* orgList = rto->get_organizations();
1608  CPPUNIT_ASSERT(orgList != NULL);
1609  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length());
1610 
1611  CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1"));
1612  CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1);
1613  CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"),
1614  std::string((*orgList)[orgIdx1]->get_organization_id()));
1615 
1616  CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2"));
1617  CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2);
1618  CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"),
1619  std::string((*orgList)[orgIdx2]->get_organization_id()));
1620 
1621  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2));
1622  delete org2;
1623  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1));
1624  delete org1;
1625 
1626  rto->shutdown();
1627  delete rto;
1628  }
1629 
1636  {
1637  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1638 
1639  // 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
1640  OrganizationMock* org1 = new OrganizationMock("ORG 1");
1641  OrganizationMock* org2 = new OrganizationMock("ORG 2");
1642 
1643  // 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
1644  SDOPackage::Configuration_ptr cfg = rto->get_configuration();
1645  CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
1646  CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this()));
1647  CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this()));
1648 
1649  // 追加されていることを確認しておく
1650  SDOPackage::OrganizationList* orgList = rto->get_organizations();
1651  CPPUNIT_ASSERT(orgList != NULL);
1652  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length());
1653 
1654  // 追加したうち、片方の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
1655  CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1"));
1656  orgList = rto->get_organizations();
1657  CPPUNIT_ASSERT(orgList != NULL);
1658  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length());
1659 
1660  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2));
1661  delete org2;
1662  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1));
1663  delete org1;
1664 
1665  rto->shutdown();
1666  delete rto;
1667  }
1668 
1673  {
1674  // テスト対象が未実装につき、テストも未実装 } /*! * @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
1675  }
1676 
1683  {
1684  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1685 
1686  // Mockの機能を用いてstatusを設定しておく
1687  CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159);
1688  rto->set_status("STATUS 1", valueAny1);
1689 
1690  CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828);
1691  rto->set_status("STATUS 2", valueAny2);
1692 
1693  // 設定したstatusを正しく取得できるか?
1694  CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1");
1695  CPPUNIT_ASSERT(valueAnyRet1 != NULL);
1696  {
1697  CORBA::Float value; *valueAnyRet1 >>= value;
1698  CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
1699  }
1700 
1701  CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2");
1702  CPPUNIT_ASSERT(valueAnyRet2 != NULL);
1703  {
1704  CORBA::Float value; *valueAnyRet2 >>= value;
1705  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
1706  }
1707 
1708  rto->shutdown();
1709  delete rto;
1710 
1711  }
1712 
1719  {
1720  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA); // will be deleted automatically
1721 
1722  // Mockの機能を用いてstatusを設定しておく
1723  CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159);
1724  rto->set_status("STATUS 1", valueAny1);
1725 
1726  CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828);
1727  rto->set_status("STATUS 2", valueAny2);
1728 
1729  // 設定したstatusを正しく取得できるか?
1730  SDOPackage::NVList* statusList = rto->get_status_list();
1731  CPPUNIT_ASSERT(statusList != NULL);
1732  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length());
1733 
1734  const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1");
1735  {
1736  CORBA::Float value; valueAnyRet1 >>= value;
1737  CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
1738  }
1739 
1740  const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2");
1741  {
1742  CORBA::Float value; valueAnyRet2 >>= value;
1743  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
1744  }
1745 
1746  rto->shutdown();
1747  delete rto;
1748  }
1749 
1756  {
1757  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
1759  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
1760  prop.setProperty("exec_cxt.periodic.rate","1000");
1761  rto->setProperties(prop);
1762  // initialize()で、m_eclistへ登録し、m_ecMineをstart
1763  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
1764  CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist());
1765  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
1766  CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist());
1767  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
1768  CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist());
1769 
1770  RTC::ExecutionContext_ptr ec;
1771  ec = rto->get_context(0);
1772  CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
1773  rto->finalizeContexts();
1774 
1775  // 全コンテキストが削除されたか?
1776  CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist());
1777  rto->exit();
1778  delete rto;
1779  }
1780 
1787  {
1788  RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
1790  prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
1791  prop.setProperty("exec_cxt.periodic.rate","1000");
1792  rto->setProperties(prop);
1793 
1794  RTC::ExecutionContext_ptr ec;
1795 
1796  // nilを設定した場合、-1を返すか?
1797  ec = RTC::ExecutionContext::_nil();
1798  int id = (int)(rto->bindContext(ec));
1799  CPPUNIT_ASSERT_EQUAL(-1, id);
1800 
1801  // m_ecMine 未登録の場合、m_ecMineの番号を返すか?
1803  ec = pec->getObjRef();
1804  id = (int)(rto->bindContext(ec));
1805 
1806  // [0]に登録されるか?
1807  CPPUNIT_ASSERT_EQUAL(0, id);
1808 
1809  // 正しく登録されているか?
1810  CPPUNIT_ASSERT(rto->chk_ecMine(id,ec));
1811 
1812  // m_ecMine 登録済みで nil の場合、m_ecMineの番号を返すか?
1813  rto->ecMine[0] = RTC::ExecutionContextService::_nil();
1814  rto->set_ecMine();
1816  ec = pec2->getObjRef();
1817  id = (int)(rto->bindContext(ec));
1818 
1819  // [0]に登録されるか?
1820  CPPUNIT_ASSERT_EQUAL(0, id);
1821 
1822  // 正しく登録されているか?
1823  CPPUNIT_ASSERT(rto->chk_ecMine(id,ec));
1824 
1825  rto->exit();
1826 
1827  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec));
1828  delete pec;
1829  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2));
1830  delete pec2;
1831 
1832  rto->shutdown();
1833  delete rto;
1834 
1835  }
1836 
1837  };
1838 }; // namespace RTObject
1839 
1840 /*
1841  * Register test suite
1842  */
1844 
1845 #ifdef LOCAL_MAIN
1846 int main(int argc, char* argv[])
1847 {
1848 
1849  FORMAT format = TEXT_OUT;
1850  int target = 0;
1851  std::string xsl;
1852  std::string ns;
1853  std::string fname;
1854  std::ofstream ofs;
1855 
1856  int i(1);
1857  while (i < argc)
1858  {
1859  std::string arg(argv[i]);
1860  std::string next_arg;
1861  if (i + 1 < argc) next_arg = argv[i + 1];
1862  else next_arg = "";
1863 
1864  if (arg == "--text") { format = TEXT_OUT; break; }
1865  if (arg == "--xml")
1866  {
1867  if (next_arg == "")
1868  {
1869  fname = argv[0];
1870  fname += ".xml";
1871  }
1872  else
1873  {
1874  fname = next_arg;
1875  }
1876  format = XML_OUT;
1877  ofs.open(fname.c_str());
1878  }
1879  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
1880  if ( arg == "--cerr" ) { target = 1; break; }
1881  if ( arg == "--xsl" )
1882  {
1883  if (next_arg == "") xsl = "default.xsl";
1884  else xsl = next_arg;
1885  }
1886  if ( arg == "--namespace" )
1887  {
1888  if (next_arg == "")
1889  {
1890  std::cerr << "no namespace specified" << std::endl;
1891  exit(1);
1892  }
1893  else
1894  {
1895  xsl = next_arg;
1896  }
1897  }
1898  ++i;
1899  }
1900  CppUnit::TextUi::TestRunner runner;
1901  if ( ns.empty() )
1902  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1903  else
1904  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1905  CppUnit::Outputter* outputter = 0;
1906  std::ostream* stream = target ? &std::cerr : &std::cout;
1907  switch ( format )
1908  {
1909  case TEXT_OUT :
1910  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
1911  break;
1912  case XML_OUT :
1913  std::cout << "XML_OUT" << std::endl;
1914  outputter = new CppUnit::XmlOutputter(&runner.result(),
1915  ofs, "shift_jis");
1916  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
1917  break;
1918  case COMPILER_OUT :
1919  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
1920  break;
1921  }
1922  runner.setOutputter(outputter);
1923  runner.run();
1924  return 0; // runner.run() ? 0 : 1;
1925 }
1926 #endif // MAIN
1927 #endif // RTObject_cpp
int countLog(std::string line)
void test_get_configuration_and_set_service_profile_and_get_sdo_service()
get_configuration()メソッドとget_sdo_service()メソッドのテスト
int main(int argc, char **argv)
void test_bindContext()
bindContext()メソッドのテスト
virtual char * get_organization_id()
virtual SDOPackage::ServiceProfileList * get_service_profiles()
[SDO interface] Get SDO ServiceProfile
Definition: RTObject.cpp:1207
void finalizeContexts()
The ExecutionContextBase list is deleted.
Definition: RTObject.cpp:2109
void log(const std::string &msg)
virtual ComponentProfile * get_component_profile()
[RTObject CORBA interface] Get RTC&#39;s profile
Definition: RTObject.cpp:702
RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
virtual SDOPackage::OrganizationProperty * get_organization_property()
virtual char * get_sdo_id()
[SDO interface] Get the SDO ID
Definition: RTObject.cpp:1128
RT-Component.
PortFinder(const RTC::PortService_ptr &port)
virtual ExecutionContextService_ptr getObjRef(void)
Get the reference to the CORBA object.
void test_get_sdo_service()
get_sdo_service()メソッドのテスト
PortableServer::POA_ptr m_pPOA
virtual ReturnCode_t initialize()
[CORBA interface] Initialize the RTC that realizes this interface.
Definition: RTObject.cpp:314
virtual CORBA::Boolean remove_member(const char *id)
void test_finalize_participating_in_execution_context()
finalize()メソッドのテスト
const RTC::ExecutionContextService_ptr & m_ecSvc
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
Definition: ace/coil/Time.h:40
UniqueId bindContext(ExecutionContext_ptr exec_context)
Definition: RTObject.cpp:624
void test_get_sdo_type()
get_sdo_type()メソッドのテスト
ReturnCode_t detach_context(UniqueId exec_handle)
[CORBA interface] Detach ExecutionContext.
Definition: RTObject.cpp:664
void test_initialize_invoking_on_initialize()
initialize()メソッドのテスト
void test_readAll()
readAll(),setReadAll()メソッドのテスト
ReturnCode_t
Definition: doil.h:53
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void test_finalize_invoking_on_finalize()
finalize()メソッドのテスト
void test_get_context()
get_context()メソッドのテスト
bool removeInPort(InPortBase &port)
[local interface] Unregister InPort
Definition: RTObject.cpp:1690
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile &connector_profile)
RT-Component class.
Definition: RTObject.h:89
ExecutionContextServiceFinder(const RTC::ExecutionContextService_ptr &ecSvc)
virtual SDOPackage::SDOList * get_members()
virtual CORBA::Boolean add_members(const SDOPackage::SDOList &sdo_list)
void test_finalizeContexts()
finalizeContexts()メソッドのテスト
virtual ExecutionContextList * get_participating_contexts()
[CORBA interface] Get participating ExecutionContextList.
Definition: RTObject.cpp:540
std::vector< std::string > m_log
virtual PortServiceList * get_ports()
[RTObject CORBA interface] Get Ports
Definition: RTObject.cpp:752
bool removePort(PortBase &port)
[local interface] Unregister Port
Definition: RTObject.cpp:1750
void test_get_status()
get_status()メソッドのテスト
std::vector< RTC::ExecutionContextBase * > eclist
void test_detach_executioncontext_with_illegal_id()
detach_executioncontext()メソッドのテスト
virtual void tearDown()
Test finalization.
virtual RTC::ReturnCode_t on_finalize()
[ComponentAction CORBA interface] Finalize RTC
virtual SDOPackage::Configuration_ptr get_configuration()
[SDO interface] Get Configuration object
Definition: RTObject.cpp:1306
UniqueId attach_context(ExecutionContext_ptr exec_context)
[CORBA interface] Attach ExecutionContext
Definition: RTObject.cpp:587
SDOPackage::NVList m_sdoStatus
SDO Status.
Definition: RTObject.h:4576
bool addOutPort(const char *name, OutPortBase &outport)
[local interface] Register DataOutPort
Definition: RTObject.cpp:1649
virtual CORBA::Boolean add_organization_property(const SDOPackage::OrganizationProperty &organization_property)
virtual ReturnCode_t on_finalize()
[ComponentAction CORBA interface] Finalize RTC
Definition: RTObject.cpp:815
virtual RTC::ReturnCode_t on_initialize()
[RTObject CORBA interface] Get ExecutionContextAdmin
virtual void unsubscribeInterfaces(const RTC::ConnectorProfile &connector_profile)
void test_get_service_profile()
get_service_profile()メソッドのテスト
virtual ReturnCode_t finalize()
[CORBA interface] Finalize the RTC for destruction
Definition: RTObject.cpp:361
void test_is_alive()
is_alive()メソッドのテスト
const CORBA::Long find_index(const SDOPackage::NVList &nv, const char *name)
Return the index of element specified by name from NVList.
Definition: NVUtil.cpp:227
void test_get_device_profile()
get_device_profile()メソッドのテスト
void test_get_sdo_service_with_illegal_arguments()
std::vector< ExecutionContext * > ExecutionContextList
Definition: IRTC.h:69
void test_get_monitoring()
get_monitoring()メソッドのテスト
void set_status(const char *name, const CORBA::Any &value)
InPortMock(const char *name, const char *data_type)
virtual CORBA::Boolean set_members(const SDOPackage::SDOList &sdos)
void setObjRef(const RTObject_ptr rtobj)
[local interface] Set the object reference
Definition: RTObject.cpp:1474
bool removeOutPort(OutPortBase &port)
[local interface] Unregister OutPort
Definition: RTObject.cpp:1720
bool operator()(const RTC::ExecutionContextService_ptr &ecSvc)
ExecutionContextHandle_t UniqueId
void test_get_ports()
get_ports()メソッドのテスト
Port base class.
Definition: PortBase.h:134
virtual void activateInterfaces()
Activate all Port interfaces.
bool write()
Write data.
void test_exit_in_Created()
exit()メソッドのテスト
std::vector< ExecutionContextBase * > m_eclist
List of ExecutionContextBase.
Definition: RTObject.h:4642
RTObject_impl(Manager *manager)
Constructor.
Definition: RTObject.cpp:64
void test_get_configuration_and_set_service_profile_and_get_service_profiles()
get_configuration()メソッドとget_service_profiles()メソッドのテスト
virtual CORBA::Boolean set_organization_property_value(const char *name, const CORBA::Any &value)
const CORBA::Any & find(const SDOPackage::NVList &nv, const char *name)
Return the value specified by name from NVList.
Definition: NVUtil.cpp:212
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
void test_get_configuration_and_remove_organization()
Configuration::remove_organization()メソッドのテスト
virtual ExecutionContext_ptr get_context(UniqueId exec_handle)
[CORBA interface] Get ExecutionContext.
Definition: RTObject.cpp:465
virtual void deactivateInterfaces()
Deactivate all Port interfaces.
void test_get_owned_organizations()
get_execution_context_services()メソッドのテスト
devProf
Configuration::set_device_profile (in DeviceProfile dProfile);.
RTObjectTests()
Constructor.
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
Definition: Properties.cpp:240
void test_get_configuration_and_remove_service_profile()
Configuration::remove_service_profile()メソッドのテスト
void test_get_component_profile()
get_component_profile()メソッドのテスト
const RTC::PortService_ptr & m_port
Output base class.
Definition: OutPortBase.h:230
virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile &connector_profile)
virtual CORBA::Any * get_organization_property_value(const char *name)
ExecutionContextServiceList m_ecMine
List of owned ExecutionContextService.
Definition: RTObject.h:4633
bool operator()(const SDOPackage::ServiceProfile &svcProf)
virtual ReturnCode_t exit()
[CORBA interface]top the RTC&#39;s execution context(s) and finalize it along with its contents...
Definition: RTObject.cpp:398
void test_get_status_list()
get_status_list()メソッドのテスト
Port for InPort.
Definition: InPortBase.h:67
virtual SDOPackage::NVList * get_status_list()
[SDO interface] Get SDO Status list
Definition: RTObject.cpp:1383
virtual SDOPackage::DeviceProfile * get_device_profile()
[SDO interface] Get SDO DeviceProfile list
Definition: RTObject.cpp:1178
void set_return(bool ret)
RTC::ExecutionContextServiceList ecMine
const char * getInstanceName()
[local interface] Get instance name
Definition: RTObject.h:1952
void set_return(bool ret)
prop
Organization::get_organization_property ();.
void test_detach_executioncontext()
detach_executioncontext()メソッドのテスト
void test_get_configuration_and_add_organization_and_get_organizations()
get_configuration()メソッドとget_organizations()メソッドのテスト
Class represents a set of properties.
Definition: Properties.h:101
bool chk_ecMine(int id, RTC::ExecutionContext_ptr exec_context)
void test_get_configuration_and_set_device_profile_and_get_device_profile()
get_configuration()メソッドのテスト
void test_get_service_profile_with_illegal_arguments()
get_service_profile()メソッドのテスト
OrganizationFinder(const char *id)
std::vector< IPortService * > PortServiceList
Definition: IPortService.h:39
void test_finalize_in_Created()
finalize()メソッドのテスト
virtual void setUp()
Test initialization.
PeriodicExecutionContext class.
void setWriteAll(bool write=true, bool completion=false)
Set whether to execute the writeAll() method.
Definition: RTObject.cpp:2088
void test_get_sdo_id()
get_sdo_id()メソッドのテスト
virtual ReturnCode_t on_initialize()
[RTObject CORBA interface] Get ExecutionContextAdmin
Definition: RTObject.cpp:779
bool addPort(PortBase &port)
[local interface] Register Port
Definition: RTObject.cpp:1562
virtual RTC::UniqueId bindContext(RTC::ExecutionContext_ptr exec_context)
bool writeAll()
The write() method of all OutPort is called.
Definition: RTObject.cpp:2012
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
virtual SDOPackage::SDOService_ptr get_sdo_service(const char *id)
[SDO interface] Get specified SDO Service&#39;s reference
Definition: RTObject.cpp:1272
void test_get_configuration_and_set_service_profile_and_get_service_profile()
get_configuration()メソッドとget_serivce_profile()メソッドのテスト
void setInstanceName(const char *instance_name)
[local interface] Set instance name
Definition: RTObject.cpp:1441
void setReadAll(bool read=true, bool completion=false)
Set whether to execute the readAll() method.
Definition: RTObject.cpp:2058
RTComponent header.
virtual SDOPackage::SDOSystemElement_ptr get_owner()
PeriodicExecutionContext class.
bool operator()(const SDOPackage::Organization_ptr &org)
bool operator()(const RTC::PortService_ptr &port)
virtual SDOPackage::OrganizationList * get_organizations()
[SDO interface] Get Organization list
Definition: RTObject.cpp:1357
void test_add_removePort()
add[In/Out]Port(),addPort()メソッドのテスト
CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests)
virtual CORBA::Boolean remove_organization_property(const char *name)
virtual CORBA::Boolean is_alive(ExecutionContext_ptr exec_context)
[CORBA interface] Confirm whether RTC is the alive state
Definition: RTObject.cpp:437
void test_writeAll()
writeAll(),setWriteAll()メソッドのテスト
virtual SDOPackage::DependencyType get_dependency()
OutPortMock(const char *name, const char *data_type)
virtual ~RTObjectTests()
Destructor.
void test_get_contexts()
get_contexts()メソッドのテスト
bool addInPort(const char *name, InPortBase &inport)
[local interface] Register DataInPort
Definition: RTObject.cpp:1608
virtual ReturnCode_t on_execute(UniqueId exec_handle)
[DataFlowComponentAction CORBA interface] Primary Periodic Operation of RTC
Definition: RTObject.cpp:1020
void test_initialize_in_Alive()
initialize()メソッドのテスト
virtual char * get_sdo_type()
[SDO interface] Get SDO type
Definition: RTObject.cpp:1152
bool readAll()
Readout the value from All InPorts.
Definition: RTObject.cpp:1980
void setName(const char *name)
Set the name of this Port.
Definition: PortBase.cpp:488
void setProperties(const coil::Properties &prop)
[local interface] Set RTC property
Definition: RTObject.cpp:1501
virtual CORBA::Any * get_status(const char *name)
[SDO interface] Get SDO Status
Definition: RTObject.cpp:1408
SDOPackage::NameValue newNVAny(const char *name, const CORBA::Any &value)
Create NameValue typed CORBA::Any.
Definition: NVUtil.cpp:92
void test_exit()
exit()メソッドのテスト
virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
OrganizationMock(const char *id)
virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
virtual SDOPackage::ServiceProfile * get_service_profile(const char *id)
[SDO interface] Get specified ServiceProfile
Definition: RTObject.cpp:1235
bool read()
It is a virtual method that is called from RTObject_impl::readAll(). This method reads out data from ...


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