RTCUtilTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00011 /*
00012  * $Log: RTCUtilTests.cpp,v $
00013  * Revision 1.1  2008/05/02 11:29:13  arafune
00014  * The first commitment.
00015  *
00016  *
00017  */
00018 
00019 #ifndef RTCUtil_cpp
00020 #define RTCUtil_cpp
00021 
00022 #include <cppunit/ui/text/TestRunner.h>
00023 #include <cppunit/TextOutputter.h>
00024 #include <cppunit/extensions/TestFactoryRegistry.h>
00025 #include <cppunit/extensions/HelperMacros.h>
00026 #include <cppunit/TestAssert.h>
00027 
00028 #include <idl/SDOPackageSkel.h>
00029 #include <idl/RTCSkel.h>
00030 #include <idl/OpenRTMSkel.h>
00031 #include <rtm/RTCUtil.h>
00032 
00037 namespace Tests
00038 {
00039   class DataFlowComponentMock
00040     : public virtual POA_OpenRTM::DataFlowComponent,
00041       public virtual PortableServer::RefCountServantBase
00042   {
00043   public:
00044     DataFlowComponentMock() {}
00045     virtual ~DataFlowComponentMock() {}
00046     // _impl_SDOSystemElement
00047     virtual SDOPackage::OrganizationList* get_owned_organizations() { return NULL; }
00048     
00049     // SDOPackage::_impl_SDO
00050     virtual char* get_sdo_id() { return NULL; }
00051     virtual char* get_sdo_type() { return NULL; }
00052     virtual SDOPackage::DeviceProfile* get_device_profile() { return NULL; }
00053     virtual SDOPackage::ServiceProfileList* get_service_profiles() { return NULL; }
00054     virtual SDOPackage::ServiceProfile* get_service_profile(const char*) { return NULL; }
00055     virtual SDOPackage::_objref_SDOService* get_sdo_service(const char*) { return NULL; }
00056     virtual SDOPackage::_objref_Configuration* get_configuration() { return NULL; }
00057     virtual SDOPackage::_objref_Monitoring* get_monitoring() { return NULL; }
00058     virtual SDOPackage::OrganizationList* get_organizations() { return NULL; }
00059     virtual SDOPackage::NVList* get_status_list() { return NULL; }
00060     virtual CORBA::Any* get_status(const char*) { return NULL; }
00061                 
00062     // RTC::_impl_DataFlowComponentAction
00063     virtual RTC::ReturnCode_t on_execute(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00064     virtual RTC::ReturnCode_t on_state_update(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00065     virtual RTC::ReturnCode_t on_rate_changed(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00066     virtual RTC::ExecutionContextHandle_t attach_context(RTC::_objref_ExecutionContext*) { return RTC::ExecutionContextHandle_t(0); }
00067     virtual RTC::ReturnCode_t detach_context(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00068     virtual RTC::ReturnCode_t on_initialize() { return RTC::RTC_OK; }
00069     virtual RTC::ReturnCode_t on_finalize() { return RTC::RTC_OK; }
00070     virtual RTC::ReturnCode_t on_startup(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00071     virtual RTC::ReturnCode_t on_shutdown(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00072     virtual RTC::ReturnCode_t on_activated(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00073     virtual RTC::ReturnCode_t on_deactivated(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00074     virtual RTC::ReturnCode_t on_aborting(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00075     virtual RTC::ReturnCode_t on_error(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00076     virtual RTC::ReturnCode_t on_reset(RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00077     virtual RTC::ExecutionContextList* get_owned_contexts()
00078     {
00079         return 0;
00080     }
00081     virtual RTC::ExecutionContextList* get_participating_contexts()
00082     {
00083         return 0;
00084     }
00085     virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext*)    
00086     {
00087         return 0;
00088     }
00089     virtual RTC::ReturnCode_t send_stimulus(const char*, RTC::ExecutionContextHandle_t)
00090     {
00091         return RTC::RTC_OK;
00092     }
00093     // RTC::_impl_LightweightRTObjec:t
00094     virtual RTC::ReturnCode_t initialize() { return RTC::RTC_OK; }
00095     virtual RTC::ReturnCode_t finalize() { return RTC::RTC_OK; }
00096     virtual RTC::ReturnCode_t exit() { return RTC::RTC_OK; }
00097     virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext*) { return true; }
00098     virtual RTC::_objref_ExecutionContext* get_context(RTC::ExecutionContextHandle_t) { return NULL; }
00099                 
00100     // RTC::_impl_RTObject
00101     virtual RTC::ComponentProfile* get_component_profile() { return NULL; }
00102     virtual RTC::PortServiceList* get_ports() { return NULL; }
00103   };
00104 
00105   class FsmObjectMock
00106     : public virtual POA_RTC::FsmObject
00107   {
00108     // RTC::_impl_FsmObject
00109     virtual RTC::ReturnCode_t stimulate(const char*, RTC::ExecutionContextHandle_t) { return RTC::RTC_OK; }
00110     virtual RTC::ReturnCode_t send_stimulus(const char*, RTC::ExecutionContextHandle_t)
00111     {
00112         return RTC::RTC_OK;
00113     }
00114   };
00115         
00116   class MultiModeObjectMock
00117     : public virtual POA_RTC::MultiModeObject
00118   {
00119     // RTC::_impl_ModeCapable
00120     virtual RTC::_objref_Mode* get_default_mode() { return NULL; }
00121     virtual RTC::_objref_Mode* get_current_mode() { return NULL; }
00122     virtual RTC::_objref_Mode* get_current_mode_in_context(RTC::_objref_ExecutionContext*) { return NULL; } 
00123     virtual RTC::_objref_Mode* get_pending_mode() { return NULL; }
00124     virtual RTC::_objref_Mode* get_pending_mode_in_context(RTC::_objref_ExecutionContext*) { return NULL; }
00125     virtual RTC::ReturnCode_t set_mode(RTC::_objref_Mode*, CORBA::Boolean) { return RTC::RTC_OK; }
00126 
00127     // RTC::_impl_MultiModeComponentAction
00128     virtual RTC::ReturnCode_t on_mode_changed(RTC::ExecutionContextHandle_t)
00129     {
00130       return RTC::RTC_OK;
00131     }
00132 
00133     virtual RTC::ReturnCode_t send_stimulus(const char*, RTC::ExecutionContextHandle_t)
00134     {
00135         return RTC::RTC_OK;
00136     }
00137     virtual RTC::ReturnCode_t on_initialize()
00138     {
00139         return RTC::RTC_OK;
00140     }
00141     virtual RTC::ReturnCode_t on_startup(RTC::ExecutionContextHandle_t)
00142     {
00143         return RTC::RTC_OK;
00144     }
00145     virtual RTC::ReturnCode_t on_shutdown(RTC::ExecutionContextHandle_t)
00146     {
00147         return RTC::RTC_OK;
00148     }
00149     virtual RTC::ReturnCode_t on_activated(RTC::ExecutionContextHandle_t)
00150     {
00151         return RTC::RTC_OK;
00152     }
00153     virtual RTC::ReturnCode_t on_deactivated(RTC::ExecutionContextHandle_t)
00154     {
00155         return RTC::RTC_OK;
00156     }
00157     virtual RTC::ReturnCode_t on_aborting(RTC::ExecutionContextHandle_t)
00158     {
00159         return RTC::RTC_OK;
00160     }
00161     virtual RTC::ReturnCode_t on_error(RTC::ExecutionContextHandle_t)
00162     {
00163         return RTC::RTC_OK;
00164     }
00165     virtual RTC::ReturnCode_t on_reset(RTC::ExecutionContextHandle_t)
00166     {
00167         return RTC::RTC_OK;
00168     }
00169     virtual RTC::ReturnCode_t on_finalize()
00170     {
00171         return RTC::RTC_OK;
00172     }
00173     virtual RTC::ReturnCode_t initialize()
00174     {
00175         return RTC::RTC_OK;
00176     }
00177     virtual RTC::ReturnCode_t finalize()
00178     {
00179         return RTC::RTC_OK;
00180     }
00181     virtual CORBA::Boolean is_alive(RTC::_objref_ExecutionContext*)
00182     {
00183         return 0;
00184     }
00185     virtual RTC::ReturnCode_t exit()
00186     {
00187         return RTC::RTC_OK;
00188     }
00189     virtual RTC::ExecutionContextHandle_t attach_context(RTC::_objref_ExecutionContext*) 
00190     { 
00191       return RTC::ExecutionContextHandle_t(0); 
00192     }
00193     virtual RTC::ReturnCode_t detach_context(RTC::ExecutionContextHandle_t) 
00194     { 
00195       return RTC::RTC_OK; 
00196     }
00197     virtual RTC::_objref_ExecutionContext* get_context(RTC::ExecutionContextHandle_t)
00198     {
00199       return 0;
00200     }
00201     virtual RTC::ExecutionContextList* get_owned_contexts()
00202     {
00203       return NULL;
00204     }
00205     virtual RTC::ExecutionContextList* get_participating_contexts()
00206     {
00207       return NULL;
00208     }
00209     virtual RTC::ExecutionContextHandle_t get_context_handle(RTC::_objref_ExecutionContext*)
00210     {
00211       return 0;
00212     }
00213 
00214   };
00215         
00216   class RTCUtilTests
00217     : public CppUnit::TestFixture
00218   {
00219     CPPUNIT_TEST_SUITE(RTCUtilTests);
00220                 
00221     CPPUNIT_TEST(test_isDataFlowComponent_DataFlowComponent);
00222     CPPUNIT_TEST(test_isDataFlowComponent_FsmObject);
00223     CPPUNIT_TEST(test_isDataFlowComponent_MultiModeObject);
00224 
00225     CPPUNIT_TEST(test_isFsmParticipant_DataFlowComponent);
00226     CPPUNIT_TEST(test_isFsmParticipant_FsmObject);
00227     CPPUNIT_TEST(test_isFsmParticipant_MultiModeObject);
00228 
00229     CPPUNIT_TEST(test_isFsmObject_DataFlowComponent);
00230     CPPUNIT_TEST(test_isFsmObject_FsmObject);
00231     CPPUNIT_TEST(test_isFsmObject_MultiModeObject);
00232                 
00233     CPPUNIT_TEST(test_isMultiModeObject_DataFlowComponent);
00234     CPPUNIT_TEST(test_isMultiModeObject_FsmObject);
00235     CPPUNIT_TEST(test_isMultiModeObject_MultiModeObject);
00236                 
00237     CPPUNIT_TEST_SUITE_END();
00238         
00239   private:
00240     CORBA::ORB_ptr m_pORB;
00241     PortableServer::POA_ptr m_pPOA;
00242         
00243   public:
00247     RTCUtilTests()
00248     {
00249       int argc = 0;
00250       char** argv = NULL;
00251       m_pORB = CORBA::ORB_init(argc, argv);
00252       m_pPOA = PortableServer::POA::_narrow(
00253                                             m_pORB->resolve_initial_references("RootPOA"));
00254       m_pPOA->the_POAManager()->activate();
00255     }
00256                     
00260     virtual ~RTCUtilTests()
00261     {
00262     }
00263                   
00267     virtual void setUp()
00268     {
00269     }
00270     
00274     virtual void tearDown()
00275     { 
00276     }
00277                 
00278     void test_isDataFlowComponent_DataFlowComponent()
00279     {
00280       DataFlowComponentMock* obj = new DataFlowComponentMock();
00281       CORBA::Object_ptr ref = obj->_this();
00282       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00283                         
00284       CPPUNIT_ASSERT(RTC_Utils::isDataFlowComponent(ref));
00285       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00286       delete obj;
00287     }
00288                 
00289     void test_isDataFlowComponent_FsmObject()
00290     {
00291       FsmObjectMock* obj = new FsmObjectMock();
00292       CORBA::Object_ptr ref = obj->_this();
00293       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00294                         
00295       CPPUNIT_ASSERT(! RTC_Utils::isDataFlowComponent(ref));
00296       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00297       delete obj;
00298     }
00299                 
00300     void test_isDataFlowComponent_MultiModeObject()
00301     {
00302       MultiModeObjectMock* obj = new MultiModeObjectMock();
00303                         
00304       CORBA::Object_ptr ref = obj->_this();
00305       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00306                         
00307       CPPUNIT_ASSERT(! RTC_Utils::isDataFlowComponent(ref));
00308       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00309       delete obj;
00310     }
00311                 
00312     void test_isFsmParticipant_DataFlowComponent()
00313     {
00314       DataFlowComponentMock* obj = new DataFlowComponentMock();
00315       CORBA::Object_ptr ref = obj->_this();
00316       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00317                         
00318       CPPUNIT_ASSERT(! RTC_Utils::isFsmParticipant(ref));
00319       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00320       delete obj;
00321     }
00322                 
00323     void test_isFsmParticipant_FsmObject()
00324     {
00325       FsmObjectMock* obj = new FsmObjectMock();
00326       CORBA::Object_ptr ref = obj->_this();
00327       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00328                         
00329       CPPUNIT_ASSERT(! RTC_Utils::isFsmParticipant(ref));
00330       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00331       delete obj;
00332     }
00333                 
00334     void test_isFsmParticipant_MultiModeObject()
00335     {
00336       MultiModeObjectMock* obj = new MultiModeObjectMock();
00337                         
00338       CORBA::Object_ptr ref = obj->_this();
00339       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00340                         
00341       CPPUNIT_ASSERT(! RTC_Utils::isFsmParticipant(ref));
00342       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00343       delete obj;
00344     }
00345                 
00346     void test_isFsmObject_DataFlowComponent()
00347     {
00348       DataFlowComponentMock* obj = new DataFlowComponentMock();
00349       CORBA::Object_ptr ref = obj->_this();
00350       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00351                         
00352       CPPUNIT_ASSERT(! RTC_Utils::isFsmObject(ref));
00353       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00354       delete obj;
00355     }
00356                 
00357     void test_isFsmObject_FsmObject()
00358     {
00359       FsmObjectMock* obj = new FsmObjectMock();
00360       CORBA::Object_ptr ref = obj->_this();
00361       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00362                         
00363       CPPUNIT_ASSERT(RTC_Utils::isFsmObject(ref));
00364       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00365       delete obj;
00366     }
00367 
00368     void test_isFsmObject_MultiModeObject()
00369     {
00370       MultiModeObjectMock* obj = new MultiModeObjectMock();
00371                         
00372       CORBA::Object_ptr ref = obj->_this();
00373       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00374                         
00375       CPPUNIT_ASSERT(! RTC_Utils::isFsmObject(ref));
00376       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00377       delete obj;
00378     }
00379                 
00380     void test_isMultiModeObject_DataFlowComponent()
00381     {
00382       DataFlowComponentMock* obj = new DataFlowComponentMock();
00383       CORBA::Object_ptr ref = obj->_this();
00384       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00385                         
00386       CPPUNIT_ASSERT(! RTC_Utils::isMultiModeObject(ref));
00387       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00388       delete obj;
00389     }
00390 
00391     void test_isMultiModeObject_FsmObject()
00392     {
00393       FsmObjectMock* obj = new FsmObjectMock();
00394       CORBA::Object_ptr ref = obj->_this();
00395       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00396                         
00397       CPPUNIT_ASSERT(! RTC_Utils::isMultiModeObject(ref));
00398       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00399       delete obj;
00400     }
00401 
00402     void test_isMultiModeObject_MultiModeObject()
00403     {
00404       MultiModeObjectMock* obj = new MultiModeObjectMock();
00405                         
00406       CORBA::Object_ptr ref = obj->_this();
00407       CPPUNIT_ASSERT(! CORBA::is_nil(ref));
00408                         
00409       CPPUNIT_ASSERT(RTC_Utils::isMultiModeObject(ref));
00410       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(obj));
00411       delete obj;
00412     }
00413                 
00414   };
00415 }; // namespace RTCUtil
00416 
00417 /*
00418  * Register test suite
00419  */
00420 CPPUNIT_TEST_SUITE_REGISTRATION(Tests::RTCUtilTests);
00421 
00422 #ifdef LOCAL_MAIN
00423 int main(int argc, char* argv[])
00424 {
00425 
00426   FORMAT format = TEXT_OUT;
00427   int target = 0;
00428   std::string xsl;
00429   std::string ns;
00430   std::string fname;
00431   std::ofstream ofs;
00432 
00433   int i(1);
00434   while (i < argc)
00435     {
00436       std::string arg(argv[i]);
00437       std::string next_arg;
00438       if (i + 1 < argc) next_arg = argv[i + 1];
00439       else              next_arg = "";
00440 
00441       if (arg == "--text") { format = TEXT_OUT; break; }
00442       if (arg == "--xml")
00443         {
00444           if (next_arg == "")
00445             {
00446               fname = argv[0];
00447               fname += ".xml";
00448             }
00449           else
00450             {
00451               fname = next_arg;
00452             }
00453           format = XML_OUT;
00454           ofs.open(fname.c_str());
00455         }
00456       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00457       if ( arg == "--cerr"      ) { target = 1; break; }
00458       if ( arg == "--xsl"       )
00459         {
00460           if (next_arg == "") xsl = "default.xsl"; 
00461           else                xsl = next_arg;
00462         }
00463       if ( arg == "--namespace" )
00464         {
00465           if (next_arg == "")
00466             {
00467               std::cerr << "no namespace specified" << std::endl;
00468               exit(1); 
00469             }
00470           else
00471             {
00472               xsl = next_arg;
00473             }
00474         }
00475       ++i;
00476     }
00477   CppUnit::TextUi::TestRunner runner;
00478   if ( ns.empty() )
00479     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00480   else
00481     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00482   CppUnit::Outputter* outputter = 0;
00483   std::ostream* stream = target ? &std::cerr : &std::cout;
00484   switch ( format )
00485     {
00486     case TEXT_OUT :
00487       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00488       break;
00489     case XML_OUT :
00490       std::cout << "XML_OUT" << std::endl;
00491       outputter = new CppUnit::XmlOutputter(&runner.result(),
00492                                             ofs, "shift_jis");
00493       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00494       break;
00495     case COMPILER_OUT :
00496       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00497       break;
00498     }
00499   runner.setOutputter(outputter);
00500   runner.run();
00501   return 0; // runner.run() ? 0 : 1;
00502 }
00503 
00504 #endif // MAIN
00505 #endif // RTCUtil_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:06