00001
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RTObject_cpp
00019 #define RTObject_cpp
00020
00021 #include <cppunit/ui/text/TestRunner.h>
00022 #include <cppunit/TextOutputter.h>
00023 #include <cppunit/extensions/TestFactoryRegistry.h>
00024 #include <cppunit/extensions/HelperMacros.h>
00025 #include <cppunit/TestAssert.h>
00026
00027 #include <rtm/RTC.h>
00028 #include <rtm/PeriodicExecutionContext.h>
00029 #include <rtm/RTObject.h>
00030
00035 namespace RTObject
00036 {
00037 class RTObjectMock
00038 : public RTC::RTObject_impl
00039 {
00040 public:
00041 RTObjectMock(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00042 : RTC::RTObject_impl(orb, poa)
00043 {
00044 }
00045
00046 virtual ~RTObjectMock()
00047 {
00048 }
00049
00050 virtual RTC::ReturnCode_t on_initialize()
00051 throw (CORBA::SystemException)
00052 {
00053 log("on_initialize");
00054 return RTC::RTObject_impl::on_initialize();
00055 }
00056
00057 virtual RTC::ReturnCode_t on_finalize()
00058 throw (CORBA::SystemException)
00059 {
00060 log("on_finalize");
00061 return RTC::RTObject_impl::on_finalize();
00062 }
00063
00064 virtual RTC::UniqueId bindContext(RTC::ExecutionContext_ptr exec_context)
00065 {
00066 RTC::UniqueId id;
00067 id = RTC::RTObject_impl::bindContext(exec_context);
00068 ecMine = RTC::RTObject_impl::m_ecMine;
00069 return id;
00070 }
00071 RTC::ExecutionContextServiceList ecMine;
00072
00073
00074 void set_ecMine()
00075 {
00076 RTC::RTObject_impl::m_ecMine = ecMine;
00077 }
00078
00079
00080 bool chk_ecMine(int id, RTC::ExecutionContext_ptr exec_context)
00081 {
00082 RTC::ExecutionContextService_var ecs;
00083 ecs = RTC::ExecutionContextService::_narrow(exec_context);
00084 if (RTC::RTObject_impl::m_ecMine[id] == ecs)
00085 {
00086 return true;
00087 }
00088 else
00089 {
00090 return false;
00091 }
00092 }
00093
00094 std::vector<RTC::ExecutionContextBase*> eclist;
00095
00096 int get_eclist()
00097 {
00098 int len(RTC::RTObject_impl::m_eclist.size());
00099 eclist = RTC::RTObject_impl::m_eclist;
00100 return len;
00101 }
00102
00103
00104 public:
00105 int countLog(std::string line)
00106 {
00107 int count = 0;
00108 for (int i = 0; i < (int) m_log.size(); ++i)
00109 {
00110 if (m_log[i] == line) ++count;
00111 }
00112 return count;
00113 }
00114
00115 void set_status(const char* name, const CORBA::Any& value)
00116 {
00117 CORBA::Long idx = NVUtil::find_index(m_sdoStatus, name);
00118 if (idx < 0)
00119 {
00120 SDOPackage::NameValue nv = NVUtil::newNVAny(name, value);
00121 CORBA_SeqUtil::push_back(m_sdoStatus, nv);
00122 }
00123 else
00124 {
00125 m_sdoStatus[idx].value <<= value;
00126 }
00127 }
00128
00129 void shutdown()
00130 {
00131 RTObject_impl::shutdown();
00132 }
00133
00134
00135 private:
00136 void log(const std::string& msg)
00137 {
00138 m_log.push_back(msg);
00139 }
00140
00141 private:
00142 std::vector<std::string> m_log;
00143 };
00144
00145 class PortMock
00146 : public RTC::PortBase
00147 {
00148 protected:
00149 virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile& connector_profile)
00150 {
00151 return RTC::RTC_OK;
00152 }
00153 virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
00154 {
00155 return RTC::RTC_OK;
00156 }
00157 virtual void unsubscribeInterfaces(const RTC::ConnectorProfile& connector_profile)
00158 {
00159 }
00160 virtual void activateInterfaces()
00161 {
00162 }
00163 virtual void deactivateInterfaces()
00164 {
00165 }
00166 };
00167
00168 class InPortMock
00169 : public RTC::InPortBase
00170 {
00171 public:
00172 InPortMock(const char* name, const char* data_type)
00173 :RTC::InPortBase(name, data_type),
00174 m_return(true),
00175 m_cnt(0)
00176 {
00177 return;
00178 }
00179
00180 bool read(){
00181 ++m_cnt;
00182 return m_return;
00183 }
00184
00185 void set_return(bool ret)
00186 {
00187 m_return = ret;
00188 }
00189
00190 int get_counter()
00191 {
00192 return m_cnt;
00193 }
00194
00195 private:
00196 bool m_return;
00197 int m_cnt;
00198 };
00199
00200 class OutPortMock
00201 : public RTC::OutPortBase
00202 {
00203 public:
00204 OutPortMock(const char* name, const char* data_type)
00205 : OutPortBase(name, data_type),
00206 m_return(true),
00207 m_cnt(0)
00208 {
00209 return;
00210 }
00211
00212 bool write() {
00213 ++m_cnt;
00214 return m_return;
00215 }
00216 void set_return(bool ret)
00217 {
00218 m_return = ret;
00219 }
00220
00221 int get_counter()
00222 {
00223 return m_cnt;
00224 }
00225 private:
00226 bool m_return;
00227 int m_cnt;
00228 };
00229
00230 class SDOServiceMock
00231 : public POA_SDOPackage::SDOService,
00232 public virtual PortableServer::RefCountServantBase
00233 {
00234 };
00235
00236 struct PortFinder
00237 {
00238 PortFinder(const RTC::PortService_ptr& port) : m_port(port) {}
00239 bool operator()(const RTC::PortService_ptr& port)
00240 {
00241 return m_port->_is_equivalent(port);
00242 }
00243
00244 const RTC::PortService_ptr& m_port;
00245 };
00246
00247 class SDOSystemElementMock
00248 : public POA_SDOPackage::SDOSystemElement,
00249 public virtual PortableServer::RefCountServantBase
00250 {
00251 };
00252
00253 class OrganizationMock
00254 : public POA_SDOPackage::Organization,
00255 public virtual PortableServer::RefCountServantBase
00256 {
00257 public:
00258 OrganizationMock(const char* id) : m_id(id)
00259 {
00260 }
00261
00262 virtual char* get_organization_id()
00263 {
00264 return CORBA::string_dup(m_id);
00265 }
00266
00267 virtual SDOPackage::OrganizationProperty* get_organization_property()
00268 {
00269 return NULL;
00270 }
00271
00272 virtual CORBA::Any* get_organization_property_value(const char* name)
00273 {
00274 return NULL;
00275 }
00276
00277 virtual CORBA::Boolean add_organization_property(const SDOPackage::OrganizationProperty& organization_property)
00278 {
00279 return false;
00280 }
00281
00282 virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value)
00283 {
00284 return false;
00285 }
00286
00287 virtual CORBA::Boolean remove_organization_property(const char* name)
00288 {
00289 return false;
00290 }
00291
00292 virtual SDOPackage::SDOSystemElement_ptr get_owner()
00293 {
00294 return NULL;
00295 }
00296
00297 virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
00298 {
00299 return false;
00300 }
00301
00302 virtual SDOPackage::SDOList* get_members()
00303 {
00304 return NULL;
00305 }
00306
00307 virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos)
00308 {
00309 return false;
00310 }
00311
00312 virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list)
00313 {
00314 return false;
00315 }
00316
00317 virtual CORBA::Boolean remove_member(const char* id)
00318 {
00319 return false;
00320 }
00321
00322 virtual SDOPackage::DependencyType get_dependency()
00323 {
00324 return SDOPackage::NO_DEPENDENCY;
00325 }
00326
00327 virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
00328 {
00329 return false;
00330 }
00331
00332 private:
00333 const char* m_id;
00334 };
00335
00336 struct ExecutionContextServiceFinder
00337 {
00338 ExecutionContextServiceFinder(const RTC::ExecutionContextService_ptr& ecSvc)
00339 : m_ecSvc(ecSvc) {}
00340 bool operator()(const RTC::ExecutionContextService_ptr& ecSvc)
00341 {
00342 return m_ecSvc->_is_equivalent(ecSvc);
00343 }
00344 const RTC::ExecutionContextService_ptr& m_ecSvc;
00345 };
00346
00347 struct ServiceProfileFinder
00348 {
00349 ServiceProfileFinder(const char* id) : m_id(id) {}
00350 bool operator()(const SDOPackage::ServiceProfile& svcProf)
00351 {
00352 return strcmp(m_id, (const char*)(svcProf.id)) == 0;
00353 }
00354 const char* m_id;
00355 };
00356
00357 struct OrganizationFinder
00358 {
00359 OrganizationFinder(const char* id) : m_id(id) {}
00360 bool operator()(const SDOPackage::Organization_ptr& org)
00361 {
00362 return strcmp(m_id, org->get_organization_id()) == 0;
00363 }
00364 const char* m_id;
00365 };
00366
00367 class RTObjectTests
00368 : public CppUnit::TestFixture
00369 {
00370 CPPUNIT_TEST_SUITE(RTObjectTests);
00371
00372 CPPUNIT_TEST(test_finalizeContexts);
00373 CPPUNIT_TEST(test_bindContext);
00374 CPPUNIT_TEST(test_add_removePort);
00375 CPPUNIT_TEST(test_readAll);
00376 CPPUNIT_TEST(test_writeAll);
00377 CPPUNIT_TEST(test_initialize_invoking_on_initialize);
00378 CPPUNIT_TEST(test_initialize_in_Alive);
00379 CPPUNIT_TEST(test_finalize_invoking_on_finalize);
00380 CPPUNIT_TEST(test_finalize_participating_in_execution_context);
00381 CPPUNIT_TEST(test_finalize_in_Created);
00382
00383 CPPUNIT_TEST(test_exit);
00384 CPPUNIT_TEST(test_exit_in_Created);
00385 CPPUNIT_TEST(test_detach_executioncontext);
00386 CPPUNIT_TEST(test_detach_executioncontext_with_illegal_id);
00387 CPPUNIT_TEST(test_get_context);
00388 CPPUNIT_TEST(test_get_contexts);
00389 CPPUNIT_TEST(test_get_component_profile);
00390 CPPUNIT_TEST(test_get_ports);
00391
00392
00393 CPPUNIT_TEST(test_get_sdo_id);
00394 CPPUNIT_TEST(test_get_sdo_type);
00395
00396
00397 CPPUNIT_TEST(test_get_service_profile_with_illegal_arguments);
00398 CPPUNIT_TEST(test_get_sdo_service);
00399 CPPUNIT_TEST(test_get_sdo_service_with_illegal_arguments);
00400 CPPUNIT_TEST(test_get_configuration_and_set_device_profile_and_get_device_profile);
00401 CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profile);
00402 CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_service_profiles);
00403 CPPUNIT_TEST(test_get_configuration_and_set_service_profile_and_get_sdo_service);
00404 CPPUNIT_TEST(test_get_configuration_and_remove_service_profile);
00405 CPPUNIT_TEST(test_get_configuration_and_add_organization_and_get_organizations);
00406 CPPUNIT_TEST(test_get_configuration_and_remove_organization);
00407
00408 CPPUNIT_TEST(test_get_status);
00409 CPPUNIT_TEST(test_get_status_list);
00410
00411 CPPUNIT_TEST_SUITE_END();
00412
00413 private:
00414 CORBA::ORB_ptr m_pORB;
00415 PortableServer::POA_ptr m_pPOA;
00416
00417 public:
00421 RTObjectTests()
00422 {
00423 int argc(0);
00424 char** argv(NULL);
00425 m_pORB = CORBA::ORB_init(argc, argv);
00426 m_pPOA = PortableServer::POA::_narrow(
00427 m_pORB->resolve_initial_references("RootPOA"));
00428 m_pPOA->the_POAManager()->activate();
00429 }
00430
00434 virtual ~RTObjectTests()
00435 {
00436 }
00437
00441 virtual void setUp()
00442 {
00443 }
00444
00448 virtual void tearDown()
00449 {
00450 }
00451
00457 void test_initialize_invoking_on_initialize()
00458 {
00459 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00460
00461
00462 CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_initialize"));
00463 coil::Properties prop;
00464 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00465 prop.setProperty("exec_cxt.periodic.rate","1000");
00466 rto->setProperties(prop);
00467 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00468 CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_initialize"));
00469 rto->exit();
00470 delete rto;
00471 }
00472
00478 void test_initialize_in_Alive()
00479 {
00480 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00481
00482
00483 coil::Properties prop;
00484 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00485 prop.setProperty("exec_cxt.periodic.rate","1000");
00486 rto->setProperties(prop);
00487 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00488
00489 RTC::ExecutionContext_ptr ec;
00490 ec = rto->get_context(0);
00491 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00492
00493
00494 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00495 rto->exit();
00496 delete rto;
00497 }
00498
00504 void test_finalize_invoking_on_finalize()
00505 {
00506 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00507
00508
00509 coil::Properties prop;
00510 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00511 prop.setProperty("exec_cxt.periodic.rate","1000");
00512 rto->setProperties(prop);
00513 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00514 RTC::ExecutionContext_ptr ec;
00515 ec = rto->get_context(0);
00516 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00517
00518
00519 CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize"));
00520
00521 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00522
00523 rto->exit();
00524 CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize"));
00525 delete rto;
00526 }
00527
00533 void test_finalize_participating_in_execution_context()
00534 {
00535 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00536
00537
00538 coil::Properties prop;
00539 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00540 prop.setProperty("exec_cxt.periodic.rate","1000");
00541 rto->setProperties(prop);
00542 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00543
00544 RTC::ExecutionContext_ptr ec;
00545 ec = rto->get_context(0);
00546 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00547
00548
00549 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00550
00551
00552 CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize());
00553
00554 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->remove_component(rto->_this()));
00555 rto->exit();
00556 delete rto;
00557 }
00558
00564 void test_finalize_in_Created()
00565 {
00566 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00567
00568
00569 CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->finalize());
00570 rto->shutdown();
00571 delete rto;
00572 }
00573
00577 void test_is_alive()
00578 {
00579
00580 }
00581
00588 void test_exit()
00589 {
00590 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00591 rto->setObjRef(rto->_this());
00592
00593
00594 coil::Properties prop;
00595 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
00596 prop.setProperty("exec_cxt.periodic.rate","1000");
00597 rto->setProperties(prop);
00598 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
00599
00600 RTC::ExecutionContext_ptr ec;
00601 ec = rto->get_context(0);
00602 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00603
00604
00605 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->add_component(rto->_this()));
00606 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ec->activate_component(rto->_this()));
00607
00608 ec->start();
00609 coil::sleep(1);
00610
00611
00612
00613 CPPUNIT_ASSERT_EQUAL(0, rto->countLog("on_finalize"));
00614 CPPUNIT_ASSERT_EQUAL(RTC::ACTIVE_STATE, ec->get_component_state(rto->_this()));
00615 ec->stop();
00616 coil::sleep(1);
00617
00618 ec->remove_component(rto->_this());
00619 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->exit());
00620 CPPUNIT_ASSERT_EQUAL(1, rto->countLog("on_finalize"));
00621 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
00622
00623 delete rto;
00624 }
00625
00631 void test_exit_in_Created()
00632 {
00633 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00634 rto->setObjRef(rto->_this());
00635
00636
00637 CPPUNIT_ASSERT_EQUAL(RTC::PRECONDITION_NOT_MET, rto->exit());
00638
00639 rto->shutdown();
00640 delete rto;
00641 }
00642
00648 void test_detach_executioncontext()
00649 {
00650 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00651
00652
00653 RTC::PeriodicExecutionContext* ec
00654 = new RTC::PeriodicExecutionContext();
00655
00656
00657 RTC::UniqueId id = rto->attach_context(ec->_this());
00658 CPPUNIT_ASSERT(RTC::UniqueId(-1) != id);
00659
00660
00661 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->detach_context(id));
00662 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec));
00663 delete ec;
00664 rto->shutdown();
00665 delete rto;
00666 }
00667
00673 void test_detach_executioncontext_with_illegal_id()
00674 {
00675 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00676
00677
00678 CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,
00679 rto->detach_context(RTC::UniqueId(1)));
00680 rto->shutdown();
00681 delete rto;
00682 }
00683
00689 void test_get_context()
00690 {
00691 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00692
00693
00694 RTC::PeriodicExecutionContext* ec1
00695 = new RTC::PeriodicExecutionContext();
00696 RTC::PeriodicExecutionContext* ec2
00697 = new RTC::PeriodicExecutionContext();
00698
00699
00700 RTC::UniqueId id1 = rto->attach_context(ec1->_this());
00701 CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
00702 RTC::UniqueId id2 = rto->attach_context(ec2->_this());
00703 CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
00704 CPPUNIT_ASSERT(id1 != id2);
00705
00706
00707 RTC::ExecutionContext_ptr ecPtr1 = rto->get_context(id1);
00708 CPPUNIT_ASSERT(ecPtr1->_is_equivalent(ec1->_this()));
00709 RTC::ExecutionContext_ptr ecPtr2 = rto->get_context(id2);
00710 CPPUNIT_ASSERT(ecPtr2->_is_equivalent(ec2->_this()));
00711
00712 rto->detach_context(id2);
00713 rto->detach_context(id1);
00714 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2));
00715 delete ec2;
00716 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1));
00717 delete ec1;
00718
00719 rto->shutdown();
00720 delete rto;
00721
00722 }
00723
00729 void test_get_contexts()
00730 {
00731 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00732
00733
00734 RTC::PeriodicExecutionContext* ec1
00735 = new RTC::PeriodicExecutionContext();
00736 RTC::PeriodicExecutionContext* ec2
00737 = new RTC::PeriodicExecutionContext();
00738
00739
00740 RTC::UniqueId id1 = rto->attach_context(ec1->_this());
00741 CPPUNIT_ASSERT(RTC::UniqueId(-1) != id1);
00742 RTC::UniqueId id2 = rto->attach_context(ec2->_this());
00743 CPPUNIT_ASSERT(RTC::UniqueId(-1) != id2);
00744
00745
00746 RTC::ExecutionContextList* ecList = rto->get_participating_contexts();
00747 CPPUNIT_ASSERT(ecList != NULL);
00748 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), ecList->length());
00749 CPPUNIT_ASSERT(! (*ecList)[0]->_is_equivalent((*ecList)[1]));
00750 CPPUNIT_ASSERT((*ecList)[0]->_is_equivalent(ec1->_this())
00751 || (*ecList)[0]->_is_equivalent(ec2->_this()));
00752 CPPUNIT_ASSERT((*ecList)[1]->_is_equivalent(ec1->_this())
00753 || (*ecList)[1]->_is_equivalent(ec2->_this()));
00754
00755
00756 rto->detach_context(id2);
00757 rto->detach_context(id1);
00758
00759 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec2));
00760 delete ec2;
00761 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(ec1));
00762 delete ec1;
00763
00764 rto->shutdown();
00765 delete rto;
00766 }
00767
00773 void test_get_component_profile()
00774 {
00775 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00776
00777
00778 coil::Properties prop;
00779 prop.setProperty("instance_name", "INSTANCE_NAME");
00780 prop.setProperty("type_name", "TYPE_NAME");
00781 prop.setProperty("description", "DESCRIPTION");
00782 prop.setProperty("version", "VERSION");
00783 prop.setProperty("vendor", "VENDOR");
00784 prop.setProperty("category", "CATEGORY");
00785 rto->setProperties(prop);
00786
00787
00788 RTC::ComponentProfile* compProf = rto->get_component_profile();
00789 CPPUNIT_ASSERT(compProf != NULL);
00790
00791 CPPUNIT_ASSERT_EQUAL(std::string("INSTANCE_NAME"),
00792 std::string(compProf->instance_name));
00793 CPPUNIT_ASSERT_EQUAL(std::string("TYPE_NAME"),
00794 std::string(compProf->type_name));
00795 CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION"),
00796 std::string(compProf->description));
00797 CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
00798 std::string(compProf->version));
00799 CPPUNIT_ASSERT_EQUAL(std::string("VENDOR"),
00800 std::string(compProf->vendor));
00801 CPPUNIT_ASSERT_EQUAL(std::string("CATEGORY"),
00802 std::string(compProf->category));
00803 rto->shutdown();
00804 delete rto;
00805
00806 }
00807
00815 void test_add_removePort()
00816 {
00817 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00818
00819 PortMock* port0 = new PortMock();
00820 port0->setName("port0");
00821
00822 CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port0));
00823
00824
00825
00826
00827
00828 PortMock* port1 = new PortMock();
00829 port1->setName("port1");
00830 CPPUNIT_ASSERT_EQUAL(true, rto->addPort(*port1));
00831
00832
00833 RTC::PortServiceList* portList = rto->get_ports();
00834 CPPUNIT_ASSERT(portList != NULL);
00835 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
00836
00837
00838 CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1));
00839 CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0));
00840
00841 InPortMock* inport0 = new InPortMock("in","TimedLong");
00842 OutPortMock* outport0 = new OutPortMock("out","TimedLong");
00843
00844 CPPUNIT_ASSERT_EQUAL(true, rto->addInPort("in",*inport0));
00845 CPPUNIT_ASSERT_EQUAL(true, rto->addOutPort("out", *outport0));
00846
00847
00848
00849
00850
00851
00852
00853 portList = rto->get_ports();
00854 CPPUNIT_ASSERT(portList != NULL);
00855 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
00856
00857
00858 CPPUNIT_ASSERT_EQUAL(true, rto->removeInPort(*inport0));
00859 CPPUNIT_ASSERT_EQUAL(true, rto->removeOutPort(*outport0));
00860
00861 portList = rto->get_ports();
00862 CPPUNIT_ASSERT(portList != NULL);
00863 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), portList->length());
00864
00865 delete outport0;
00866 delete inport0;
00867 delete port1;
00868 delete port0;
00869
00870 rto->shutdown();
00871 delete rto;
00872
00873 }
00874
00882 void test_readAll()
00883 {
00884 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00885
00886 InPortMock* inport0 = new InPortMock("in","TimedLong");
00887 InPortMock* inport1 = new InPortMock("in2","TimedLong");
00888 OutPortMock* outport0 = new OutPortMock("out","TimedLong");
00889
00890 rto->addInPort("in",*inport0);
00891 rto->addInPort("in2",*inport1);
00892 rto->addOutPort("out", *outport0);
00893
00894
00895 CPPUNIT_ASSERT_EQUAL(true, rto->readAll());
00896 CPPUNIT_ASSERT_EQUAL(1, inport0->get_counter());
00897 CPPUNIT_ASSERT_EQUAL(1, inport1->get_counter());
00898
00899
00900 rto->setReadAll();
00901 rto->on_execute(0);
00902 CPPUNIT_ASSERT_EQUAL(2, inport0->get_counter());
00903 CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter());
00904
00905
00906 inport0->set_return(false);
00907 rto->setReadAll(true,false);
00908 CPPUNIT_ASSERT_EQUAL(false, rto->readAll());
00909 CPPUNIT_ASSERT_EQUAL(3, inport0->get_counter());
00910
00911
00912
00913 CPPUNIT_ASSERT_EQUAL(2, inport1->get_counter());
00914
00915 rto->setReadAll(true,true);
00916 CPPUNIT_ASSERT_EQUAL(false, rto->readAll());
00917 CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
00918
00919
00920
00921 CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
00922
00923 rto->setReadAll(false,true);
00924 rto->on_execute(0);
00925
00926
00927 CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
00928 CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
00929
00930 rto->setReadAll(false,false);
00931 rto->on_execute(0);
00932
00933
00934 CPPUNIT_ASSERT_EQUAL(4, inport0->get_counter());
00935 CPPUNIT_ASSERT_EQUAL(3, inport1->get_counter());
00936
00937 rto->removeInPort(*inport0);
00938 rto->removeInPort(*inport1);
00939 rto->removeOutPort(*outport0);
00940
00941 delete outport0;
00942 delete inport0;
00943 delete inport1;
00944
00945 rto->shutdown();
00946 delete rto;
00947 }
00948
00949
00957 void test_writeAll()
00958 {
00959 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
00960
00961 OutPortMock* outport0 = new OutPortMock("out","TimedLong");
00962 OutPortMock* outport1 = new OutPortMock("out2","TimedLong");
00963 InPortMock* inport0 = new InPortMock("in","TimedLong");
00964
00965 rto->addOutPort("out",*outport0);
00966 rto->addOutPort("out2",*outport1);
00967 rto->addInPort("in", *inport0);
00968
00969
00970 CPPUNIT_ASSERT_EQUAL(true, rto->writeAll());
00971 CPPUNIT_ASSERT_EQUAL(1, outport0->get_counter());
00972 CPPUNIT_ASSERT_EQUAL(1, outport1->get_counter());
00973
00974
00975 rto->setWriteAll();
00976 rto->on_execute(0);
00977 CPPUNIT_ASSERT_EQUAL(2, outport0->get_counter());
00978 CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter());
00979
00980
00981 outport0->set_return(false);
00982 rto->setWriteAll(true,false);
00983 CPPUNIT_ASSERT_EQUAL(false, rto->writeAll());
00984 CPPUNIT_ASSERT_EQUAL(3, outport0->get_counter());
00985
00986
00987
00988 CPPUNIT_ASSERT_EQUAL(2, outport1->get_counter());
00989
00990 rto->setWriteAll(true,true);
00991 CPPUNIT_ASSERT_EQUAL(false, rto->writeAll());
00992 CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
00993
00994
00995
00996 CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
00997
00998 rto->setWriteAll(false,true);
00999 rto->on_execute(0);
01000
01001
01002 CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
01003 CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
01004
01005 rto->setWriteAll(false,false);
01006 rto->on_execute(0);
01007
01008
01009 CPPUNIT_ASSERT_EQUAL(4, outport0->get_counter());
01010 CPPUNIT_ASSERT_EQUAL(3, outport1->get_counter());
01011
01012 rto->removeOutPort(*outport0);
01013 rto->removeOutPort(*outport1);
01014 rto->removeInPort(*inport0);
01015
01016 delete outport0;
01017 delete outport1;
01018 delete inport0;
01019
01020 rto->shutdown();
01021 delete rto;
01022 }
01023
01024
01030 void test_get_ports()
01031 {
01032 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01033
01034
01035 PortMock* port0 = new PortMock();
01036 port0->setName("port0");
01037 rto->addPort(*port0);
01038
01039 PortMock* port1 = new PortMock();
01040 port1->setName("port1");
01041 rto->addPort(*port1);
01042
01043
01044 RTC::PortServiceList* portList = rto->get_ports();
01045 CPPUNIT_ASSERT(portList != NULL);
01046 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), portList->length());
01047 CPPUNIT_ASSERT(CORBA::Long(-1)
01048 != CORBA_SeqUtil::find(*portList, PortFinder(port0->_this())));
01049 CPPUNIT_ASSERT(CORBA::Long(-1)
01050 != CORBA_SeqUtil::find(*portList, PortFinder(port1->_this())));
01051
01052 CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port1));
01053 CPPUNIT_ASSERT_EQUAL(true, rto->removePort(*port0));
01054
01055 delete port1;
01056 delete port0;
01057
01058 rto->shutdown();
01059 delete rto;
01060
01061 }
01062
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097 void test_get_owned_organizations()
01098 {
01099
01100 }
01101
01108 void test_get_sdo_id()
01109 {
01110 RTObjectMock* rto1 = new RTObjectMock(m_pORB, m_pPOA);
01111 rto1->setInstanceName("INSTANCE_NAME 1");
01112 std::string str1(rto1->getInstanceName());
01113 CPPUNIT_ASSERT("INSTANCE_NAME 1" == str1);
01114 RTObjectMock* rto2 = new RTObjectMock(m_pORB, m_pPOA);
01115 rto2->setInstanceName("INSTANCE_NAME 2");
01116 std::string str2(rto2->getInstanceName());
01117 CPPUNIT_ASSERT("INSTANCE_NAME 2" == str2);
01118
01119
01120 char* id1 = rto1->get_sdo_id();
01121 CPPUNIT_ASSERT(id1 != NULL);
01122 char* id2 = rto2->get_sdo_id();
01123 CPPUNIT_ASSERT(id2 != NULL);
01124
01125
01126
01127
01128
01129 CPPUNIT_ASSERT(id1 != id2);
01130
01131 rto2->shutdown();
01132 delete rto2;
01133 rto1->shutdown();
01134 delete rto1;
01135 }
01136
01142 void test_get_sdo_type()
01143 {
01144 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01145
01146
01147 coil::Properties prop;
01148 prop.setProperty("type_name", "TYPE_NAME");
01149 rto->setProperties(prop);
01150
01151
01152 char* sdoType = rto->get_sdo_type();
01153 CPPUNIT_ASSERT(sdoType != NULL);
01154
01155 rto->shutdown();
01156 delete rto;
01157 }
01158
01164 void test_get_device_profile()
01165 {
01166
01167 }
01168
01174 void test_get_service_profile()
01175 {
01176
01177 }
01178
01185 void test_get_service_profile_with_illegal_arguments()
01186 {
01187 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01188
01189
01190 try
01191 {
01192 rto->get_service_profile(NULL);
01193 CPPUNIT_FAIL("Exception not thrown.");
01194 }
01195 catch (SDOPackage::InvalidParameter expected)
01196 {
01197
01198 }
01199 catch (...)
01200 {
01201
01202 CPPUNIT_FAIL("Unexpected exception caught.");
01203 }
01204
01205
01206 try
01207 {
01208 rto->get_service_profile("INEXIST ID");
01209 CPPUNIT_FAIL("Exception not thrown.");
01210 }
01211 catch (SDOPackage::InvalidParameter expected)
01212 {
01213
01214 }
01215 catch (...)
01216 {
01217
01218 CPPUNIT_FAIL("Unexpected exception caught.");
01219 }
01220 rto->shutdown();
01221 delete rto;
01222 }
01223
01229 void test_get_sdo_service()
01230 {
01231
01232 }
01233
01234 void test_get_sdo_service_with_illegal_arguments()
01235 {
01236 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01237
01238
01239 try
01240 {
01241 rto->get_sdo_service(NULL);
01242 CPPUNIT_FAIL("Exception not thrown.");
01243 }
01244 catch (SDOPackage::InvalidParameter expected)
01245 {
01246
01247 }
01248 catch (...)
01249 {
01250
01251 CPPUNIT_FAIL("Unexpected exception caught.");
01252 }
01253
01254
01255 try
01256 {
01257 rto->get_sdo_service("INEXIST ID");
01258 CPPUNIT_FAIL("Exception not thrown.");
01259 }
01260 catch (SDOPackage::InvalidParameter expected)
01261 {
01262
01263 }
01264 catch (...)
01265 {
01266
01267 CPPUNIT_FAIL("Unexpected exception caught.");
01268 }
01269
01270 rto->shutdown();
01271 delete rto;
01272 }
01273
01280 void test_get_configuration_and_set_device_profile_and_get_device_profile()
01281 {
01282 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01283
01284
01285 SDOPackage::DeviceProfile devProf;
01286 devProf.device_type = "DEVICE_TYPE";
01287 devProf.manufacturer = "MANUFACTURER";
01288 devProf.model = "MODEL";
01289 devProf.version = "VERSION";
01290 devProf.properties.length(1);
01291 devProf.properties[0].name = "PROPERTIES NAME";
01292 devProf.properties[0].value <<= "PROPERTIES VALUE";
01293
01294
01295 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01296 cfg->set_device_profile(devProf);
01297
01298 SDOPackage::DeviceProfile* devProfRet = rto->get_device_profile();
01299 CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"),
01300 std::string(devProfRet->device_type));
01301 CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"),
01302 std::string(devProfRet->manufacturer));
01303 CPPUNIT_ASSERT_EQUAL(std::string("MODEL"),
01304 std::string(devProfRet->model));
01305 CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
01306 std::string(devProfRet->version));
01307 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), devProfRet->properties.length());
01308 CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME"),
01309 std::string(devProfRet->properties[0].name));
01310 {
01311 const char* value; devProfRet->properties[0].value >>= value;
01312 CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES VALUE"), std::string(value));
01313 }
01314
01315 rto->shutdown();
01316 delete rto;
01317 }
01318
01325 void test_get_configuration_and_set_service_profile_and_get_service_profile()
01326 {
01327 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01328
01329
01330 SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01331 SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01332
01333
01334 SDOPackage::ServiceProfile svcProf1;
01335 svcProf1.id = "ID 1";
01336 svcProf1.interface_type = "INTERFACE_TYPE 1";
01337 svcProf1.properties.length(1);
01338 svcProf1.properties[0].name = "PROPERTIES NAME 1";
01339 svcProf1.properties[0].value <<= "3.14159";
01340 svcProf1.service = sdoSvc1->_this();
01341
01342 SDOPackage::ServiceProfile svcProf2;
01343 svcProf2.id = "ID 2";
01344 svcProf2.interface_type = "INTERFACE_TYPE 2";
01345 svcProf2.properties.length(1);
01346 svcProf2.properties[0].name = "PROPERTIES NAME 2";
01347 svcProf2.properties[0].value <<= "2.71828";
01348 svcProf2.service = sdoSvc2->_this();
01349
01350
01351 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01352 CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01353 cfg->add_service_profile(svcProf1);
01354 cfg->add_service_profile(svcProf2);
01355
01356
01357 SDOPackage::ServiceProfile* svcProfRet1 = rto->get_service_profile("ID 1");
01358 CPPUNIT_ASSERT(svcProfRet1 != NULL);
01359 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfRet1->id));
01360 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
01361 std::string(svcProfRet1->interface_type));
01362 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet1->properties.length());
01363 CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"),
01364 std::string(svcProfRet1->properties[0].name));
01365 {
01366 const char* value; svcProfRet1->properties[0].value >>= value;
01367 CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
01368 }
01369
01370 SDOPackage::ServiceProfile* svcProfRet2 = rto->get_service_profile("ID 2");
01371 CPPUNIT_ASSERT(svcProfRet2 != NULL);
01372 CPPUNIT_ASSERT_EQUAL(std::string("ID 2"), std::string(svcProfRet2->id));
01373 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"),
01374 std::string(svcProfRet2->interface_type));
01375 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfRet2->properties.length());
01376 CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"),
01377 std::string(svcProfRet2->properties[0].name));
01378 {
01379 const char* value; svcProfRet2->properties[0].value >>= value;
01380 CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
01381 }
01382
01383 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01384 delete sdoSvc2;
01385 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01386 delete sdoSvc1;
01387
01388 rto->shutdown();
01389 delete rto;
01390 }
01391
01397 void test_get_configuration_and_set_service_profile_and_get_service_profiles()
01398 {
01399 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01400
01401
01402 SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01403 SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01404
01405
01406 SDOPackage::ServiceProfile svcProf1;
01407 svcProf1.id = "ID 1";
01408 svcProf1.interface_type = "INTERFACE_TYPE 1";
01409 svcProf1.properties.length(1);
01410 svcProf1.properties[0].name = "PROPERTIES NAME 1";
01411 svcProf1.properties[0].value <<= "3.14159";
01412 svcProf1.service = sdoSvc1->_this();
01413
01414 SDOPackage::ServiceProfile svcProf2;
01415 svcProf2.id = "ID 2";
01416 svcProf2.interface_type = "INTERFACE_TYPE 2";
01417 svcProf2.properties.length(1);
01418 svcProf2.properties[0].name = "PROPERTIES NAME 2";
01419 svcProf2.properties[0].value <<= "2.71828";
01420 svcProf2.service = sdoSvc2->_this();
01421
01422
01423 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01424 CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01425 cfg->add_service_profile(svcProf1);
01426 cfg->add_service_profile(svcProf2);
01427
01428
01429 SDOPackage::ServiceProfileList* svcProfList = rto->get_service_profiles();
01430 CPPUNIT_ASSERT(svcProfList != NULL);
01431
01432 CORBA::Long svcProfIdx1 = CORBA_SeqUtil::find(
01433 *svcProfList, ServiceProfileFinder("ID 1"));
01434 CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx1);
01435 CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
01436 std::string((*svcProfList)[svcProfIdx1].id));
01437 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
01438 std::string((*svcProfList)[svcProfIdx1].interface_type));
01439 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1),
01440 (*svcProfList)[svcProfIdx1].properties.length());
01441 CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 1"),
01442 std::string((*svcProfList)[svcProfIdx1].properties[0].name));
01443 {
01444 const char* value; (*svcProfList)[svcProfIdx1].properties[0].value >>= value;
01445 CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
01446 }
01447
01448 CORBA::Long svcProfIdx2 = CORBA_SeqUtil::find(
01449 *svcProfList, ServiceProfileFinder("ID 2"));
01450 CPPUNIT_ASSERT(CORBA::Long(-1) != svcProfIdx2);
01451 CPPUNIT_ASSERT_EQUAL(std::string("ID 2"),
01452 std::string((*svcProfList)[svcProfIdx2].id));
01453 CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 2"),
01454 std::string((*svcProfList)[svcProfIdx2].interface_type));
01455 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1),
01456 (*svcProfList)[svcProfIdx2].properties.length());
01457 CPPUNIT_ASSERT_EQUAL(std::string("PROPERTIES NAME 2"),
01458 std::string((*svcProfList)[svcProfIdx2].properties[0].name));
01459 {
01460 const char* value; (*svcProfList)[svcProfIdx2].properties[0].value >>= value;
01461 CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
01462 }
01463
01464 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01465 delete sdoSvc2;
01466 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01467 delete sdoSvc1;
01468
01469 rto->shutdown();
01470 delete rto;
01471 }
01472
01479 void test_get_configuration_and_set_service_profile_and_get_sdo_service()
01480 {
01481 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01482
01483
01484 SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01485 SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01486
01487
01488 SDOPackage::ServiceProfile svcProf1;
01489 svcProf1.id = "ID 1";
01490 svcProf1.interface_type = "INTERFACE_TYPE 1";
01491 svcProf1.properties.length(1);
01492 svcProf1.properties[0].name = "PROPERTIES NAME 1";
01493 svcProf1.properties[0].value <<= "3.14159";
01494 svcProf1.service = sdoSvc1->_this();
01495
01496 SDOPackage::ServiceProfile svcProf2;
01497 svcProf2.id = "ID 2";
01498 svcProf2.interface_type = "INTERFACE_TYPE 2";
01499 svcProf2.properties.length(1);
01500 svcProf2.properties[0].name = "PROPERTIES NAME 2";
01501 svcProf2.properties[0].value <<= "2.71828";
01502 svcProf2.service = sdoSvc2->_this();
01503
01504
01505 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01506 CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01507 cfg->add_service_profile(svcProf1);
01508 cfg->add_service_profile(svcProf2);
01509
01510
01511 SDOPackage::SDOService_ptr sdoSvcRet1 = rto->get_sdo_service("ID 1");
01512 CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet1));
01513 CPPUNIT_ASSERT(sdoSvcRet1->_is_equivalent(sdoSvc1->_this()));
01514
01515 SDOPackage::SDOService_ptr sdoSvcRet2 = rto->get_sdo_service("ID 2");
01516 CPPUNIT_ASSERT(! CORBA::is_nil(sdoSvcRet2));
01517 CPPUNIT_ASSERT(sdoSvcRet2->_is_equivalent(sdoSvc2->_this()));
01518
01519 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01520 delete sdoSvc2;
01521 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01522 delete sdoSvc1;
01523
01524 rto->shutdown();
01525 delete rto;
01526
01527 }
01528
01534 void test_get_configuration_and_remove_service_profile()
01535 {
01536 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01537
01538
01539 SDOServiceMock* sdoSvc1 = new SDOServiceMock();
01540 SDOServiceMock* sdoSvc2 = new SDOServiceMock();
01541
01542
01543 SDOPackage::ServiceProfile svcProf1;
01544 svcProf1.id = "ID 1";
01545 svcProf1.interface_type = "INTERFACE_TYPE 1";
01546 svcProf1.properties.length(1);
01547 svcProf1.properties[0].name = "PROPERTIES NAME 1";
01548 svcProf1.properties[0].value <<= "3.14159";
01549 svcProf1.service = sdoSvc1->_this();
01550
01551 SDOPackage::ServiceProfile svcProf2;
01552 svcProf2.id = "ID 2";
01553 svcProf2.interface_type = "INTERFACE_TYPE 2";
01554 svcProf2.properties.length(1);
01555 svcProf2.properties[0].name = "PROPERTIES NAME 2";
01556 svcProf2.properties[0].value <<= "2.71828";
01557 svcProf2.service = sdoSvc2->_this();
01558
01559
01560 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01561 CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01562 cfg->add_service_profile(svcProf1);
01563 cfg->add_service_profile(svcProf2);
01564 CPPUNIT_ASSERT(rto->get_service_profile("ID 1") != NULL);
01565 CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL);
01566
01567
01568 CPPUNIT_ASSERT_EQUAL(true, cfg->remove_service_profile("ID 1"));
01569 try
01570 {
01571 rto->get_service_profile("ID 1");
01572 CPPUNIT_FAIL("Expected exception not thrown.");
01573 }
01574 catch (SDOPackage::InvalidParameter expected) {}
01575 CPPUNIT_ASSERT(rto->get_service_profile("ID 2") != NULL);
01576
01577 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc2));
01578 delete sdoSvc2;
01579 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(sdoSvc1));
01580 delete sdoSvc1;
01581
01582 rto->shutdown();
01583 delete rto;
01584 }
01585
01592 void test_get_configuration_and_add_organization_and_get_organizations()
01593 {
01594 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01595
01596
01597 OrganizationMock* org1 = new OrganizationMock("ORG 1");
01598 OrganizationMock* org2 = new OrganizationMock("ORG 2");
01599
01600
01601 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01602 CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01603 CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this()));
01604 CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this()));
01605
01606
01607 SDOPackage::OrganizationList* orgList = rto->get_organizations();
01608 CPPUNIT_ASSERT(orgList != NULL);
01609 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length());
01610
01611 CORBA::Long orgIdx1 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 1"));
01612 CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx1);
01613 CPPUNIT_ASSERT_EQUAL(std::string("ORG 1"),
01614 std::string((*orgList)[orgIdx1]->get_organization_id()));
01615
01616 CORBA::Long orgIdx2 = CORBA_SeqUtil::find(*orgList, OrganizationFinder("ORG 2"));
01617 CPPUNIT_ASSERT(CORBA::Long(-1) != orgIdx2);
01618 CPPUNIT_ASSERT_EQUAL(std::string("ORG 2"),
01619 std::string((*orgList)[orgIdx2]->get_organization_id()));
01620
01621 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2));
01622 delete org2;
01623 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1));
01624 delete org1;
01625
01626 rto->shutdown();
01627 delete rto;
01628 }
01629
01635 void test_get_configuration_and_remove_organization()
01636 {
01637 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01638
01639
01640 OrganizationMock* org1 = new OrganizationMock("ORG 1");
01641 OrganizationMock* org2 = new OrganizationMock("ORG 2");
01642
01643
01644 SDOPackage::Configuration_ptr cfg = rto->get_configuration();
01645 CPPUNIT_ASSERT(! CORBA::is_nil(cfg));
01646 CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org1->_this()));
01647 CPPUNIT_ASSERT_EQUAL(true, cfg->add_organization(org2->_this()));
01648
01649
01650 SDOPackage::OrganizationList* orgList = rto->get_organizations();
01651 CPPUNIT_ASSERT(orgList != NULL);
01652 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList->length());
01653
01654
01655 CPPUNIT_ASSERT_EQUAL(true, cfg->remove_organization("ORG 1"));
01656 orgList = rto->get_organizations();
01657 CPPUNIT_ASSERT(orgList != NULL);
01658 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), orgList->length());
01659
01660 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org2));
01661 delete org2;
01662 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(org1));
01663 delete org1;
01664
01665 rto->shutdown();
01666 delete rto;
01667 }
01668
01672 void test_get_monitoring()
01673 {
01674
01675 }
01676
01682 void test_get_status()
01683 {
01684 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01685
01686
01687 CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159);
01688 rto->set_status("STATUS 1", valueAny1);
01689
01690 CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828);
01691 rto->set_status("STATUS 2", valueAny2);
01692
01693
01694 CORBA::Any* valueAnyRet1 = rto->get_status("STATUS 1");
01695 CPPUNIT_ASSERT(valueAnyRet1 != NULL);
01696 {
01697 CORBA::Float value; *valueAnyRet1 >>= value;
01698 CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
01699 }
01700
01701 CORBA::Any* valueAnyRet2 = rto->get_status("STATUS 2");
01702 CPPUNIT_ASSERT(valueAnyRet2 != NULL);
01703 {
01704 CORBA::Float value; *valueAnyRet2 >>= value;
01705 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
01706 }
01707
01708 rto->shutdown();
01709 delete rto;
01710
01711 }
01712
01718 void test_get_status_list()
01719 {
01720 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01721
01722
01723 CORBA::Any valueAny1; valueAny1 <<= CORBA::Float(3.14159);
01724 rto->set_status("STATUS 1", valueAny1);
01725
01726 CORBA::Any valueAny2; valueAny2 <<= CORBA::Float(2.71828);
01727 rto->set_status("STATUS 2", valueAny2);
01728
01729
01730 SDOPackage::NVList* statusList = rto->get_status_list();
01731 CPPUNIT_ASSERT(statusList != NULL);
01732 CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), statusList->length());
01733
01734 const CORBA::Any& valueAnyRet1 = NVUtil::find(*statusList, "STATUS 1");
01735 {
01736 CORBA::Float value; valueAnyRet1 >>= value;
01737 CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
01738 }
01739
01740 const CORBA::Any& valueAnyRet2 = NVUtil::find(*statusList, "STATUS 2");
01741 {
01742 CORBA::Float value; valueAnyRet2 >>= value;
01743 CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
01744 }
01745
01746 rto->shutdown();
01747 delete rto;
01748 }
01749
01755 void test_finalizeContexts()
01756 {
01757 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01758 coil::Properties prop;
01759 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
01760 prop.setProperty("exec_cxt.periodic.rate","1000");
01761 rto->setProperties(prop);
01762
01763 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
01764 CPPUNIT_ASSERT_EQUAL(1, rto->get_eclist());
01765 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
01766 CPPUNIT_ASSERT_EQUAL(2, rto->get_eclist());
01767 CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, rto->initialize());
01768 CPPUNIT_ASSERT_EQUAL(3, rto->get_eclist());
01769
01770 RTC::ExecutionContext_ptr ec;
01771 ec = rto->get_context(0);
01772 CPPUNIT_ASSERT_EQUAL(true, rto->is_alive(ec));
01773 rto->finalizeContexts();
01774
01775
01776 CPPUNIT_ASSERT_EQUAL(0, rto->get_eclist());
01777 rto->exit();
01778 delete rto;
01779 }
01780
01786 void test_bindContext()
01787 {
01788 RTObjectMock* rto = new RTObjectMock(m_pORB, m_pPOA);
01789 coil::Properties prop;
01790 prop.setProperty("exec_cxt.periodic.type","PeriodicExecutionContext");
01791 prop.setProperty("exec_cxt.periodic.rate","1000");
01792 rto->setProperties(prop);
01793
01794 RTC::ExecutionContext_ptr ec;
01795
01796
01797 ec = RTC::ExecutionContext::_nil();
01798 int id = (int)(rto->bindContext(ec));
01799 CPPUNIT_ASSERT_EQUAL(-1, id);
01800
01801
01802 RTC::PeriodicExecutionContext* pec = new RTC::PeriodicExecutionContext();
01803 ec = pec->getObjRef();
01804 id = (int)(rto->bindContext(ec));
01805
01806
01807 CPPUNIT_ASSERT_EQUAL(0, id);
01808
01809
01810 CPPUNIT_ASSERT(rto->chk_ecMine(id,ec));
01811
01812
01813 rto->ecMine[0] = RTC::ExecutionContextService::_nil();
01814 rto->set_ecMine();
01815 RTC::PeriodicExecutionContext* pec2 = new RTC::PeriodicExecutionContext();
01816 ec = pec2->getObjRef();
01817 id = (int)(rto->bindContext(ec));
01818
01819
01820 CPPUNIT_ASSERT_EQUAL(0, id);
01821
01822
01823 CPPUNIT_ASSERT(rto->chk_ecMine(id,ec));
01824
01825 rto->exit();
01826
01827 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec));
01828 delete pec;
01829 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec2));
01830 delete pec2;
01831
01832 rto->shutdown();
01833 delete rto;
01834
01835 }
01836
01837 };
01838 };
01839
01840
01841
01842
01843 CPPUNIT_TEST_SUITE_REGISTRATION(RTObject::RTObjectTests);
01844
01845 #ifdef LOCAL_MAIN
01846 int main(int argc, char* argv[])
01847 {
01848
01849 FORMAT format = TEXT_OUT;
01850 int target = 0;
01851 std::string xsl;
01852 std::string ns;
01853 std::string fname;
01854 std::ofstream ofs;
01855
01856 int i(1);
01857 while (i < argc)
01858 {
01859 std::string arg(argv[i]);
01860 std::string next_arg;
01861 if (i + 1 < argc) next_arg = argv[i + 1];
01862 else next_arg = "";
01863
01864 if (arg == "--text") { format = TEXT_OUT; break; }
01865 if (arg == "--xml")
01866 {
01867 if (next_arg == "")
01868 {
01869 fname = argv[0];
01870 fname += ".xml";
01871 }
01872 else
01873 {
01874 fname = next_arg;
01875 }
01876 format = XML_OUT;
01877 ofs.open(fname.c_str());
01878 }
01879 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
01880 if ( arg == "--cerr" ) { target = 1; break; }
01881 if ( arg == "--xsl" )
01882 {
01883 if (next_arg == "") xsl = "default.xsl";
01884 else xsl = next_arg;
01885 }
01886 if ( arg == "--namespace" )
01887 {
01888 if (next_arg == "")
01889 {
01890 std::cerr << "no namespace specified" << std::endl;
01891 exit(1);
01892 }
01893 else
01894 {
01895 xsl = next_arg;
01896 }
01897 }
01898 ++i;
01899 }
01900 CppUnit::TextUi::TestRunner runner;
01901 if ( ns.empty() )
01902 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01903 else
01904 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01905 CppUnit::Outputter* outputter = 0;
01906 std::ostream* stream = target ? &std::cerr : &std::cout;
01907 switch ( format )
01908 {
01909 case TEXT_OUT :
01910 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01911 break;
01912 case XML_OUT :
01913 std::cout << "XML_OUT" << std::endl;
01914 outputter = new CppUnit::XmlOutputter(&runner.result(),
01915 ofs, "shift_jis");
01916 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01917 break;
01918 case COMPILER_OUT :
01919 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01920 break;
01921 }
01922 runner.setOutputter(outputter);
01923 runner.run();
01924 return 0;
01925 }
01926 #endif // MAIN
01927 #endif // RTObject_cpp