PeriodicECSharedCompositeTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log: PeriodicECSharedCompositeTests.cpp,v $
00014  *
00015  */
00016 
00017 #ifndef PeriodicECSharedComposite_cpp
00018 #define PeriodicECSharedComposite_cpp
00019 
00020 #include <cppunit/ui/text/TestRunner.h>
00021 #include <cppunit/TextOutputter.h>
00022 #include <cppunit/extensions/TestFactoryRegistry.h>
00023 #include <cppunit/extensions/HelperMacros.h>
00024 #include <cppunit/TestAssert.h>
00025 
00026 #include <rtm/idl/RTCSkel.h>
00027 #include <rtm/idl/OpenRTMSkel.h>
00028 #include <rtm/RTC.h>
00029 #include <rtm/RTObject.h>
00030 #include <rtm/PeriodicExecutionContext.h>
00031 #include <rtm/PeriodicECSharedComposite.h>
00032 #include <rtm/Manager.h>
00033 #include <rtm/SdoOrganization.h>
00034 
00039 namespace PeriodicECSharedComposite
00040 {
00041   using namespace SDOPackage;
00042 
00043   class PeriodicECSharedCompositeTests
00044     : public CppUnit::TestFixture
00045   {
00046     CPPUNIT_TEST_SUITE(PeriodicECSharedCompositeTests);
00047 
00048     CPPUNIT_TEST(test_PeriodicECOrganization);
00049     CPPUNIT_TEST(test_PeriodicECSharedComposite);
00050 
00051     CPPUNIT_TEST_SUITE_END();
00052         
00053   private:
00054     CORBA::ORB_ptr m_pORB;
00055     PortableServer::POA_ptr m_pPOA;
00056         
00057   public:
00058 
00062     PeriodicECSharedCompositeTests()
00063     {
00064       int argc(0);
00065       char** argv(NULL);
00066       m_pORB = CORBA::ORB_init(argc, argv);
00067       m_pPOA = PortableServer::POA::_narrow(
00068                     m_pORB->resolve_initial_references("RootPOA"));
00069       m_pPOA->the_POAManager()->activate();
00070     }
00071                     
00075     virtual ~PeriodicECSharedCompositeTests()
00076     {
00077     }
00078                   
00082     virtual void setUp()
00083     {
00084     }
00085     
00089     virtual void tearDown()
00090     { 
00091     }
00092                 
00097     void test_PeriodicECOrganization()
00098     {
00099       CORBA::Boolean bret;
00100       SDOPackage::SDO_var sdo;
00101       SDOPackage::SDOList slist;
00102 
00103       RTC::Manager& mgr(RTC::Manager::instance());
00104       RTC::RTObject_impl* rto = new RTC::RTObject_impl(&mgr);
00105       SDOPackage::PeriodicECOrganization* peco = new SDOPackage::PeriodicECOrganization(rto);
00106 
00107       short sflg = -1;
00108       try {
00109         // set_members()
00110         sdo = SDOPackage::SDO::_duplicate(rto->getObjRef());
00111         rto->setInstanceName("obj1");
00112         CORBA_SeqUtil::push_back(slist, sdo);
00113         bret = peco->set_members(slist);
00114         CPPUNIT_ASSERT(bret);
00115         sflg = 0;
00116       }
00117       catch (InvalidParameter ip) {
00118         //std::cout << "InvalidParameter exception." << std::endl;
00119         sflg = 1;
00120       }
00121       catch (NotAvailable na) {
00122         //std::cout << "NotAvailable exception." << std::endl;
00123         sflg = 2;
00124       }
00125       catch (InternalError ie) {
00126         //std::cout << "InternalError exception." << std::endl;
00127         sflg = 3;
00128       }
00129       catch (...) {
00130         //std::cout << "othrer exception." << std::endl;
00131         sflg = 9;
00132       }
00133       CPPUNIT_ASSERT(sflg == 0);
00134 
00135       sflg = -1;
00136       try {
00137         // remove_member()
00138         bret = peco->remove_member("obj1");
00139         CPPUNIT_ASSERT(bret);
00140         sflg = 0;
00141       }
00142       catch (InvalidParameter ip) {
00143         //std::cout << "InvalidParameter exception." << std::endl;
00144         sflg = 1;
00145       }
00146       catch (NotAvailable na) {
00147         //std::cout << "NotAvailable exception." << std::endl;
00148         sflg = 2;
00149       }
00150       catch (InternalError ie) {
00151         //std::cout << "InternalError exception." << std::endl;
00152         sflg = 3;
00153       }
00154       catch (...) {
00155         //std::cout << "othrer exception." << std::endl;
00156         sflg = 9;
00157       }
00158       CPPUNIT_ASSERT(sflg == 0);
00159 
00160       // updateDelegatedPorts()
00161       peco->updateDelegatedPorts();
00162 
00163       // 削除後の例外チェック
00164       sflg = -1;
00165       try {
00166         // remove_member()
00167         bret = peco->remove_member("obj1");
00168         sflg = 0;
00169       }
00170       catch (InvalidParameter ip) {
00171         //std::cout << "InvalidParameter exception." << std::endl;
00172         sflg = 1;
00173       }
00174       catch (NotAvailable na) {
00175         //std::cout << "NotAvailable exception." << std::endl;
00176         sflg = 2;
00177       }
00178       catch (InternalError ie) {
00179         //std::cout << "InternalError exception." << std::endl;
00180         sflg = 3;
00181       }
00182       catch (...) {
00183         //std::cout << "othrer exception." << std::endl;
00184         sflg = 9;
00185       }
00186       CPPUNIT_ASSERT(sflg == 1);
00187 
00188       sflg = -1;
00189       try {
00190         // add_members()
00191         sdo = SDOPackage::SDO::_duplicate(rto->getObjRef());
00192         rto->setInstanceName("obj2");
00193         CORBA_SeqUtil::push_back(slist, sdo);
00194         bret = peco->add_members(slist);
00195         CPPUNIT_ASSERT(bret);
00196         sflg = 0;
00197       }
00198       catch (InvalidParameter ip) {
00199         //std::cout << "InvalidParameter exception." << std::endl;
00200         sflg = 1;
00201       }
00202       catch (NotAvailable na) {
00203         //std::cout << "NotAvailable exception." << std::endl;
00204         sflg = 2;
00205       }
00206       catch (InternalError ie) {
00207         //std::cout << "InternalError exception." << std::endl;
00208         sflg = 3;
00209       }
00210       catch (...) {
00211         //std::cout << "othrer exception." << std::endl;
00212         sflg = 9;
00213       }
00214       CPPUNIT_ASSERT(sflg == 0);
00215 
00216       sflg = -1;
00217       try {
00218         // removeAllMembers()
00219         peco->removeAllMembers();
00220         sflg = 0;
00221       }
00222       catch (InvalidParameter ip) {
00223         //std::cout << "InvalidParameter exception." << std::endl;
00224         sflg = 1;
00225       }
00226       catch (NotAvailable na) {
00227         //std::cout << "NotAvailable exception." << std::endl;
00228         sflg = 2;
00229       }
00230       catch (InternalError ie) {
00231         //std::cout << "InternalError exception." << std::endl;
00232         sflg = 3;
00233       }
00234       catch (...) {
00235         //std::cout << "othrer exception." << std::endl;
00236         sflg = 9;
00237       }
00238       CPPUNIT_ASSERT(sflg == 0);
00239 
00240       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(peco));
00241       delete peco;
00242       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(rto));
00243       delete rto;
00244     }
00245 
00250     void test_PeriodicECSharedComposite()
00251     {
00252       RTC::ReturnCode_t ret;
00253       RTC::Manager& mgr(RTC::Manager::instance());
00254       RTC::PeriodicECSharedComposite* pec = new RTC::PeriodicECSharedComposite(&mgr);
00255       RTC::UniqueId id = 0;
00256 
00257       // onInitialize()
00258       ret = pec->onInitialize();
00259       CPPUNIT_ASSERT(ret == RTC::RTC_OK);
00260       coil::usleep(100000);
00261 
00262       // onActivated()
00263       ret = pec->onActivated(id);
00264       CPPUNIT_ASSERT(ret == RTC::RTC_OK);
00265       coil::usleep(100000);
00266 
00267       // onDeactivated()
00268       ret = pec->onDeactivated(id);
00269       CPPUNIT_ASSERT(ret == RTC::RTC_OK);
00270       coil::usleep(100000);
00271 
00272       // onReset()
00273       ret = pec->onReset(id);
00274       CPPUNIT_ASSERT(ret == RTC::RTC_OK);
00275       coil::usleep(100000);
00276 
00277       // onFinalize()
00278       ret = pec->onFinalize();
00279       CPPUNIT_ASSERT(ret == RTC::RTC_OK);
00280       coil::usleep(10000);
00281 
00282       m_pPOA->deactivate_object(*m_pPOA->servant_to_id(pec));
00283       delete pec;
00284     }
00285 
00286   };
00287 
00288 }; // namespace PeriodicECSharedComposite
00289 
00290 /*
00291  * Register test suite
00292  */
00293 CPPUNIT_TEST_SUITE_REGISTRATION(PeriodicECSharedComposite::PeriodicECSharedCompositeTests);
00294 
00295 #ifdef LOCAL_MAIN
00296 int main(int argc, char* argv[])
00297 {
00298 
00299   FORMAT format = TEXT_OUT;
00300   int target = 0;
00301   std::string xsl;
00302   std::string ns;
00303   std::string fname;
00304   std::ofstream ofs;
00305 
00306   int i(1);
00307   while (i < argc)
00308     {
00309       std::string arg(argv[i]);
00310       std::string next_arg;
00311       if (i + 1 < argc) next_arg = argv[i + 1];
00312       else              next_arg = "";
00313 
00314       if (arg == "--text") { format = TEXT_OUT; break; }
00315       if (arg == "--xml")
00316         {
00317           if (next_arg == "")
00318             {
00319               fname = argv[0];
00320               fname += ".xml";
00321             }
00322           else
00323             {
00324               fname = next_arg;
00325             }
00326           format = XML_OUT;
00327           ofs.open(fname.c_str());
00328         }
00329       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00330       if ( arg == "--cerr"      ) { target = 1; break; }
00331       if ( arg == "--xsl"       )
00332         {
00333           if (next_arg == "") xsl = "default.xsl"; 
00334           else                xsl = next_arg;
00335         }
00336       if ( arg == "--namespace" )
00337         {
00338           if (next_arg == "")
00339             {
00340               std::cerr << "no namespace specified" << std::endl;
00341               exit(1); 
00342             }
00343           else
00344             {
00345               xsl = next_arg;
00346             }
00347         }
00348       ++i;
00349     }
00350   CppUnit::TextUi::TestRunner runner;
00351   if ( ns.empty() )
00352     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00353   else
00354     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00355   CppUnit::Outputter* outputter = 0;
00356   std::ostream* stream = target ? &std::cerr : &std::cout;
00357   switch ( format )
00358     {
00359     case TEXT_OUT :
00360       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00361       break;
00362     case XML_OUT :
00363       std::cout << "XML_OUT" << std::endl;
00364       outputter = new CppUnit::XmlOutputter(&runner.result(),
00365                                             ofs, "shift_jis");
00366       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00367       break;
00368     case COMPILER_OUT :
00369       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00370       break;
00371     }
00372   runner.setOutputter(outputter);
00373   runner.run();
00374   return 0; // runner.run() ? 0 : 1;
00375 }
00376 #endif // MAIN
00377 #endif // PeriodicECSharedComposite_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:16