PortServiceProxyTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log$
00014  *
00015  */
00016 
00017 #ifndef PortServiceProxy_cpp
00018 #define PortServiceProxy_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 #include <string>
00026 #include <sstream>
00027 #include <iostream>
00028 #include <idl/RTCSkel.h>
00029 #include <PortServiceProxy.h>
00030 #include <PortServiceServant.h>
00031 #include <IPortService.h>
00032 #include <doil/corba/CORBAManager.h>
00033 
00038 namespace PortServiceProxy
00039 {
00045   class Logger
00046   {
00047   public:
00048     void log(const std::string& msg)
00049     {
00050       m_log.push_back(msg);
00051     }
00052 
00053     int countLog(const std::string& msg)
00054     {
00055       int count = 0;
00056       for (int i = 0; i < (int) m_log.size(); ++i)
00057         {
00058           if (m_log[i] == msg) ++count;
00059         }
00060      return count;
00061     }
00062                 
00063   private:
00064     std::vector<std::string> m_log;
00065   };
00066 
00072   class PortServiceServantMock 
00073    : public virtual ::POA_RTC::PortService,
00074      public virtual ::doil::CORBA::CORBAServantBase
00075   {
00076   public:
00077     PortServiceServantMock(doil::ImplBase* impl)
00078     : ::doil::CORBA::CORBAServantBase(impl), m_impl(NULL)
00079     {
00080       m_impl = dynamic_cast< ::RTC::Local::IPortService* >(impl);
00081     }
00082     virtual ~PortServiceServantMock(){}
00083 
00084     virtual ::RTC::PortProfile* get_port_profile()
00085     {
00086         ::RTC::PortProfile* corba_ret = new ::RTC::PortProfile ();
00087         return corba_ret;
00088     }
00089     virtual ::RTC::ConnectorProfileList* get_connector_profiles()
00090     {
00091         ::RTC::ConnectorProfileList* corba_ret 
00092                             = new ::RTC::ConnectorProfileList ();
00093         return corba_ret;
00094     }
00095     virtual ::RTC::ConnectorProfile* get_connector_profile(
00096                              const char* connector_id)
00097     {
00098         ::RTC::ConnectorProfile* corba_ret = new ::RTC::ConnectorProfile ();
00099         return corba_ret;
00100     }
00101     virtual ::RTC::ReturnCode_t connect(
00102                              ::RTC::ConnectorProfile& connector_profile)
00103     {
00104         return ::RTC::RTC_OK;
00105     }
00106     virtual ::RTC::ReturnCode_t disconnect(const char* connector_id)
00107     {
00108         return ::RTC::RTC_OK;
00109     }
00110     virtual ::RTC::ReturnCode_t disconnect_all()
00111     {
00112         return ::RTC::RTC_OK;
00113     }
00114     virtual ::RTC::ReturnCode_t notify_connect(
00115                              ::RTC::ConnectorProfile& connector_profile)
00116     {
00117         return ::RTC::RTC_OK;
00118     }
00119     virtual ::RTC::ReturnCode_t notify_disconnect(const char* connector_id)
00120     {
00121         return ::RTC::RTC_OK;
00122     }
00123 
00124   private:
00125     ::RTC::Local::IPortService* m_impl;
00126   };
00132   class IPortServiceMock
00133     : public virtual ::RTC::Local::IPortService
00134   {
00135   public:
00136     IPortServiceMock()
00137       : m_refcount(0)
00138     {}
00139     virtual ~IPortServiceMock(){}
00140     const char* id() {return "IPortServiceMock";}
00141     const char* name() {return "IPortServiceMock";}
00142     void incRef()
00143     {
00144       ++m_refcount;
00145     }
00146     void decRef()
00147     {
00148       --m_refcount;
00149       if (m_refcount == 0)
00150         delete this;
00151     }
00152     virtual ::RTC::Local::PortProfile get_port_profile()
00153       throw ()
00154     {
00155         ::RTC::Local::PortProfile corba_ret;
00156         return corba_ret;
00157     }
00158     virtual ::RTC::Local::ConnectorProfileList get_connector_profiles()
00159       throw ()
00160     {
00161         ::RTC::Local::ConnectorProfileList corba_ret; 
00162         return corba_ret;
00163     }
00164     virtual ::RTC::Local::ConnectorProfile get_connector_profile(
00165                                         const ::std::string& connector_id)
00166       throw ()
00167     {
00168         ::RTC::Local::ConnectorProfile corba_ret;
00169         return corba_ret;
00170     }
00171 
00172 
00173     virtual ::RTC::Local::ReturnCode_t connect(
00174                         ::RTC::Local::ConnectorProfile& connector_profile)
00175       throw ()
00176     {
00177         return ::RTC::Local::RTC_OK;
00178     }
00179 
00180     virtual ::RTC::Local::ReturnCode_t disconnect(
00181                                       const ::std::string& connector_id)
00182       throw ()
00183     {
00184         return ::RTC::Local::RTC_OK;
00185     }
00186 
00187     virtual ::RTC::Local::ReturnCode_t disconnect_all()
00188       throw ()
00189     {
00190         return ::RTC::Local::RTC_OK;
00191     }
00192 
00193     virtual ::RTC::Local::ReturnCode_t notify_connect(
00194                        ::RTC::Local::ConnectorProfile& connector_profile)
00195       throw ()
00196     {
00197         return ::RTC::Local::RTC_OK;
00198     }
00199 
00200     virtual ::RTC::Local::ReturnCode_t notify_disconnect(
00201                                     const ::std::string& connector_id)
00202       throw()
00203     {
00204         return ::RTC::Local::RTC_OK;
00205     }
00206 
00207   private:
00208     std::string m_name;
00209     int m_refcount;
00210   };
00216   class PortServiceRtmMock
00217     : public virtual ::POA_RTC::PortService  {
00218   protected:
00219       std::vector<std::string> m_log;
00220       ::RTC::PortProfile m_profile;
00221   public :
00222       PortServiceRtmMock(){}
00223       virtual ~PortServiceRtmMock(){}
00224 
00225       void setLogger(Logger* logger)
00226       {
00227         m_logger = logger;
00228       }
00232     ::RTC::PortProfile* get_port_profile()
00233       throw (CORBA::SystemException)
00234     {
00235         if (m_logger != NULL)
00236         {
00237             m_logger->log("get_port_profile");
00238         }
00239         ::RTC::PortProfile_var prof;
00240         m_profile.name = "name of port";
00241         m_profile.interfaces.length(1);
00242         m_profile.interfaces[0].instance_name = "MyService (provided)";
00243         m_profile.interfaces[0].type_name = "Generic (provided)";
00244         m_profile.interfaces[0].polarity = ::RTC::PROVIDED;
00245         prof = new ::RTC::PortProfile(m_profile);
00246         return prof._retn();
00247     }
00251     ::RTC::ConnectorProfileList* get_connector_profiles()
00252       throw (CORBA::SystemException)
00253     {
00254         if (m_logger != NULL)
00255         {
00256             m_logger->log("get_connector_profiles");
00257         }
00258         m_profile.connector_profiles.length(1);
00259         m_profile.connector_profiles[0].name = "ConnectorProfile-name";
00260         m_profile.connector_profiles[0].connector_id = "connect_id0";
00261         m_profile.connector_profiles[0].properties.length(1);
00262         m_profile.connector_profiles[0].properties[0].name 
00263                                   = "ConnectorProfile-properties0-name";
00264         m_profile.connector_profiles[0].properties[0].value  
00265                                   <<= (::CORBA::Float)1.1;
00266         m_profile.connector_profiles[0].ports.length(1);  
00267 //        PortServiceRtmMock* obj = new PortServiceRtmMock();
00268 //        m_profile.connector_profiles[0].ports[0] = obj->_this();
00269 
00270         ::RTC::ConnectorProfileList_var conn_prof;
00271         conn_prof 
00272           = new ::RTC::ConnectorProfileList(m_profile.connector_profiles);
00273         return conn_prof._retn();
00274     }
00278     ::RTC::ConnectorProfile* get_connector_profile(const char* connector_id)
00279       throw (CORBA::SystemException)
00280     {
00281         if (m_logger != NULL)
00282         {
00283             m_logger->log("get_connector_profile");
00284             m_logger->log(connector_id);
00285         }
00286         m_profile.connector_profiles.length(1);
00287         m_profile.connector_profiles[0].name = "ConnectorProfile-name";
00288         m_profile.connector_profiles[0].connector_id = "connect_id0";
00289         m_profile.connector_profiles[0].properties.length(1);
00290         m_profile.connector_profiles[0].properties[0].name 
00291                                   = "ConnectorProfile-properties0-name";
00292         m_profile.connector_profiles[0].properties[0].value  
00293                                   <<= (::CORBA::Float)1.1;
00294         m_profile.connector_profiles[0].ports.length(1);  
00295         ::RTC::ConnectorProfile_var conn_prof;
00296 //        PortServiceRtmMock* obj = new PortServiceRtmMock();
00297 //        m_profile.connector_profiles[0].ports[0] = obj->_this();
00298         conn_prof = new ::RTC::ConnectorProfile(
00299                                      m_profile.connector_profiles[0]);
00300         return conn_prof._retn();
00301     }
00305     ::RTC::ReturnCode_t connect(::RTC::ConnectorProfile& connector_profile)
00306       throw (CORBA::SystemException)
00307     {
00308         if (m_logger != NULL)
00309         {
00310 
00311             m_logger->log("connect");
00312             m_logger->log(::std::string(connector_profile.name));
00313             m_logger->log(::std::string(connector_profile.connector_id));
00314             m_logger->log(
00315                    ::std::string(connector_profile.properties[0].name));
00316             const char* ch;
00317             ::CORBA::ULong ul = 3;
00318             ::CORBA::Any::to_string to_str(ch, ul);
00319             connector_profile.properties[0].value >>= to_str;
00320             m_logger->log(to_str.val);
00321         }
00322         connector_profile.name = "ConnectorProfile-name";
00323         connector_profile.connector_id = "connect_id0";
00324         connector_profile.properties.length(1);
00325         connector_profile.properties[0].name 
00326                                   = "ConnectorProfile-properties0-name";
00327         connector_profile.properties[0].value  
00328                                   <<= (::CORBA::Float)1.1;
00329         connector_profile.ports.length(1);  
00330 //        PortServiceRtmMock* obj = new PortServiceRtmMock();
00331 //        m_profile.connector_profiles[0].ports[0] = obj->_this();
00332         return RTC::RTC_OK;
00333     }
00337     ::RTC::ReturnCode_t notify_connect(::RTC::ConnectorProfile& connector_profile)
00338       throw (CORBA::SystemException)
00339     {
00340         if (m_logger != NULL)
00341         {
00342             m_logger->log("notify_connect");
00343             m_logger->log(::std::string(connector_profile.name));
00344             m_logger->log(::std::string(connector_profile.connector_id));
00345             m_logger->log(
00346                    ::std::string(connector_profile.properties[0].name));
00347             const char* ch;
00348             ::CORBA::ULong ul = 3;
00349             ::CORBA::Any::to_string to_str(ch, ul);
00350             connector_profile.properties[0].value >>= to_str;
00351             m_logger->log(to_str.val);
00352         }
00353         connector_profile.name = "ConnectorProfile-name";
00354         connector_profile.connector_id = "connect_id0";
00355         connector_profile.properties.length(1);
00356         connector_profile.properties[0].name 
00357                                   = "ConnectorProfile-properties0-name";
00358         connector_profile.properties[0].value  
00359                                   <<= (::CORBA::Float)1.1;
00360         connector_profile.ports.length(1);  
00361 //        PortServiceRtmMock* obj = new PortServiceRtmMock();
00362 //        m_profile.connector_profiles[0].ports[0] = obj->_this();
00363         return RTC::RTC_OK;
00364     }
00368     ::RTC::ReturnCode_t disconnect(const char* connector_id)
00369       throw (CORBA::SystemException)
00370     {
00371         if (m_logger != NULL)
00372         {
00373             m_logger->log("disconnect");
00374             m_logger->log(connector_id);
00375         }
00376         return RTC::RTC_OK;
00377     }
00381     ::RTC::ReturnCode_t notify_disconnect(const char* connector_id)
00382       throw (CORBA::SystemException)
00383     {
00384         if (m_logger != NULL)
00385         {
00386             m_logger->log("notify_disconnect");
00387             m_logger->log(connector_id);
00388         }
00389         return RTC::RTC_OK;
00390     }
00394     ::RTC::ReturnCode_t disconnect_all()
00395       throw (CORBA::SystemException)
00396     {
00397         if (m_logger != NULL) 
00398         {
00399             m_logger->log("disconnect_all");
00400         }
00401         return RTC::RTC_OK;
00402     }
00403   
00404   private:
00405     Logger* m_logger;
00406 
00407   };
00408 
00409   class PortServiceProxyTests
00410    : public CppUnit::TestFixture
00411   {
00412     CPPUNIT_TEST_SUITE(PortServiceProxyTests);
00413     CPPUNIT_TEST(test_get_port_profile);
00414     CPPUNIT_TEST(test_get_connector_profiles);
00415     CPPUNIT_TEST(test_get_connector_profile);
00416     CPPUNIT_TEST(test_connect);
00417     CPPUNIT_TEST(test_disconnect);
00418     CPPUNIT_TEST(test_disconnect_all);
00419     CPPUNIT_TEST(test_notify_connect);
00420     CPPUNIT_TEST(test_notify_disconnect);
00421     CPPUNIT_TEST_SUITE_END();
00422   
00423   private:
00424     CORBA::ORB_ptr m_pORB;
00425     PortableServer::POA_ptr m_pPOA;
00426   
00427   public:
00428   
00432     PortServiceProxyTests()
00433     {
00434       int argc = 0;
00435       char** argv = NULL;
00436       m_pORB = CORBA::ORB_init(argc, argv);
00437       m_pPOA = PortableServer::POA::_narrow(
00438                        m_pORB->resolve_initial_references("RootPOA"));
00439       m_pPOA->the_POAManager()->activate();
00440     }
00441     
00445     ~PortServiceProxyTests()
00446     {
00447     }
00448   
00452     virtual void setUp()
00453     {
00454     }
00455     
00459     virtual void tearDown()
00460     { 
00461     }
00462   
00468     void test_get_port_profile()
00469     {
00470       PortServiceRtmMock* obj = new PortServiceRtmMock();
00471       ::CORBA::Object_ptr ref = obj->_this();
00472       if(::CORBA::is_nil(ref))
00473       {
00474          std::cout<<"ref is nil.Abort test."<<std::endl;
00475          return;
00476       }
00477       ::RTC::CORBA::PortServiceProxy* ap 
00478                  = new ::RTC::CORBA::PortServiceProxy(ref);
00479 
00480       Logger logger;
00481       obj->setLogger(&logger);
00482 
00483       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("get_port_profile"));
00484       ::RTC::Local::PortProfile prof;
00485       prof = ap->get_port_profile();
00486       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("get_port_profile"));
00487       CPPUNIT_ASSERT_EQUAL(::std::string("name of port"), 
00488                            prof.name);
00489       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00490                            prof.interfaces.size());
00491       CPPUNIT_ASSERT_EQUAL(::std::string("MyService (provided)"), 
00492                            prof.interfaces[0].instance_name);
00493       CPPUNIT_ASSERT_EQUAL(::RTC::Local::PROVIDED, 
00494                            prof.interfaces[0].polarity);
00495 
00496       delete ap;
00497       CORBA::release(ref);
00498 
00499 
00500     }
00506     void test_get_connector_profiles()
00507     {
00508       PortServiceRtmMock* obj = new PortServiceRtmMock();
00509       ::CORBA::Object_ptr ref = obj->_this();
00510       if(::CORBA::is_nil(ref))
00511       {
00512          std::cout<<"ref is nil.Abort test."<<std::endl;
00513          return;
00514       }
00515       ::RTC::CORBA::PortServiceProxy* ap 
00516                  = new ::RTC::CORBA::PortServiceProxy(ref);
00517 
00518       Logger logger;
00519       obj->setLogger(&logger);
00520 
00521       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("get_connector_profiles"));
00522       ::RTC::Local::ConnectorProfileList proflist;
00523       proflist = ap->get_connector_profiles();
00524       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("get_connector_profiles"));
00525 
00526       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00527                            proflist.size());
00528 
00529       CPPUNIT_ASSERT_EQUAL(::std::string("ConnectorProfile-name"),
00530                            proflist[0].name);
00531                         
00532       CPPUNIT_ASSERT_EQUAL(::std::string("connect_id0"),
00533                            proflist[0].connector_id);
00534 
00535 ::std::cout<<proflist[0].properties.size()<<::std::endl;
00536       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00537                            proflist[0].properties.size());
00538       CPPUNIT_ASSERT_EQUAL(::std::string(
00539                                     "ConnectorProfile-properties0-name"),
00540                            proflist[0].properties[0].name);
00541       CPPUNIT_ASSERT_EQUAL(::std::string("1.1"),
00542                            proflist[0].properties[0].value);
00543       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00544                            proflist[0].ports.size());
00545 
00546       delete ap;
00547       CORBA::release(ref);
00548 
00549 
00550     }
00556     void test_get_connector_profile()
00557     {
00558       PortServiceRtmMock* obj = new PortServiceRtmMock();
00559       ::CORBA::Object_ptr ref = obj->_this();
00560       if(::CORBA::is_nil(ref))
00561       {
00562          std::cout<<"ref is nil.Abort test."<<std::endl;
00563          return;
00564       }
00565       ::RTC::CORBA::PortServiceProxy* ap 
00566                  = new ::RTC::CORBA::PortServiceProxy(ref);
00567 
00568       Logger logger;
00569       obj->setLogger(&logger);
00570 
00571       ::std::string str = "test_get_connector_profile";
00572       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("get_connector_profile"));
00573       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str));
00574       ::RTC::Local::ConnectorProfile prof;
00575       prof = ap->get_connector_profile(str);
00576       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("get_connector_profile"));
00577       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str));
00578 
00579       CPPUNIT_ASSERT_EQUAL(::std::string("ConnectorProfile-name"),
00580                            prof.name);
00581                         
00582       CPPUNIT_ASSERT_EQUAL(::std::string("connect_id0"),
00583                            prof.connector_id);
00584 
00585       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00586                            prof.properties.size());
00587       CPPUNIT_ASSERT_EQUAL(::std::string(
00588                                     "ConnectorProfile-properties0-name"),
00589                            prof.properties[0].name);
00590       CPPUNIT_ASSERT_EQUAL(::std::string("1.1"),
00591                            prof.properties[0].value);
00592       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00593                            prof.ports.size());
00594       
00595 
00596       delete ap;
00597       CORBA::release(ref);
00598 
00599 
00600     }
00606     void test_connect()
00607     {
00608       doil::CORBA::CORBAManager& 
00609                             mgr(doil::CORBA::CORBAManager::instance());
00610       std::cout <<"Manager Name==>"<< mgr.name() << std::endl;
00611 
00612       PortServiceRtmMock* obj = new PortServiceRtmMock();
00613       ::CORBA::Object_ptr ref = obj->_this();
00614       if(::CORBA::is_nil(ref))
00615       {
00616          std::cout<<"ref is nil.Abort test."<<std::endl;
00617          return;
00618       }
00619       ::RTC::CORBA::PortServiceProxy* ap 
00620                  = new ::RTC::CORBA::PortServiceProxy(ref);
00621 
00622       Logger logger;
00623       obj->setLogger(&logger);
00624 
00625       ::RTC::Local::ConnectorProfile prof;
00626       ::std::string str1 = "in_ConnectorProfile-name";
00627       ::std::string str2 = "in_connect_id0";
00628       ::std::string str3 = "in_ConnectorProfile-properties0-name";
00629       ::std::string str4 = "2.2";
00630       prof.name = str1;
00631       prof.connector_id = str2;
00632       ::SDOPackage::Local::NameValue nv; 
00633       nv.name  = str3;
00634       nv.value = str4;
00635       prof.properties.push_back(nv);
00636       IPortServiceMock portservice;
00637 
00638       mgr.registerFactory(portservice.id(), 
00639                           doil::New<PortServiceServantMock>,
00640                           doil::Delete<PortServiceServantMock>);
00641       mgr.activateObject(&portservice);
00642       prof.ports.push_back(&portservice);
00643 
00644 
00645       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("connect"));
00646       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str1));
00647       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str2));
00648       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str3));
00649       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str4));
00650       ::RTC::Local::ReturnCode_t ret;
00651       ret = ap->connect(prof);
00652       mgr.deactivateObject(&portservice);
00653       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("connect"));
00654       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str1));
00655       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str2));
00656       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str3));
00657       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str4));
00658       CPPUNIT_ASSERT_EQUAL(::RTC::Local::RTC_OK, ret);
00659       CPPUNIT_ASSERT_EQUAL(::std::string("ConnectorProfile-name"),
00660                            prof.name);
00661                         
00662       CPPUNIT_ASSERT_EQUAL(::std::string("connect_id0"),
00663                            prof.connector_id);
00664 
00665       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00666                            prof.properties.size());
00667       CPPUNIT_ASSERT_EQUAL(::std::string(
00668                                     "ConnectorProfile-properties0-name"),
00669                            prof.properties[0].name);
00670       CPPUNIT_ASSERT_EQUAL(::std::string("1.1"),
00671                            prof.properties[0].value);
00672       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00673                            prof.ports.size());
00674       
00675 
00676       delete ap;
00677       CORBA::release(ref);
00678 
00679 
00680     }
00686     void test_disconnect()
00687     {
00688       PortServiceRtmMock* obj = new PortServiceRtmMock();
00689       ::CORBA::Object_ptr ref = obj->_this();
00690       if(::CORBA::is_nil(ref))
00691       {
00692          std::cout<<"ref is nil.Abort test."<<std::endl;
00693          return;
00694       }
00695       ::RTC::CORBA::PortServiceProxy* ap 
00696                  = new ::RTC::CORBA::PortServiceProxy(ref);
00697 
00698       Logger logger;
00699       obj->setLogger(&logger);
00700 
00701       ::std::string str = "test_disconnect";
00702       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("disconnect"));
00703       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str));
00704       ::RTC::Local::ReturnCode_t ret;
00705       ret = ap->disconnect(str);
00706       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("disconnect"));
00707       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str));
00708       CPPUNIT_ASSERT_EQUAL(::RTC::Local::RTC_OK, ret);
00709 
00710       delete ap;
00711       CORBA::release(ref);
00712 
00713 
00714     }
00720     void test_disconnect_all()
00721     {
00722       PortServiceRtmMock* obj = new PortServiceRtmMock();
00723       ::CORBA::Object_ptr ref = obj->_this();
00724       if(::CORBA::is_nil(ref))
00725       {
00726          std::cout<<"ref is nil.Abort test."<<std::endl;
00727          return;
00728       }
00729       ::RTC::CORBA::PortServiceProxy* ap 
00730                  = new ::RTC::CORBA::PortServiceProxy(ref);
00731 
00732       Logger logger;
00733       obj->setLogger(&logger);
00734 
00735       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("disconnect_all"));
00736       ::RTC::Local::ReturnCode_t ret;
00737       ret = ap->disconnect_all();
00738       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("disconnect_all"));
00739       CPPUNIT_ASSERT_EQUAL(::RTC::Local::RTC_OK, ret);
00740       
00741 
00742       delete ap;
00743       CORBA::release(ref);
00744 
00745 
00746     }
00752     void test_notify_connect()
00753     {
00754       doil::CORBA::CORBAManager& 
00755                             mgr(doil::CORBA::CORBAManager::instance());
00756       std::cout <<"Manager Name==>"<< mgr.name() << std::endl;
00757       PortServiceRtmMock* obj = new PortServiceRtmMock();
00758       ::CORBA::Object_ptr ref = obj->_this();
00759       if(::CORBA::is_nil(ref))
00760       {
00761          std::cout<<"ref is nil.Abort test."<<std::endl;
00762          return;
00763       }
00764       ::RTC::CORBA::PortServiceProxy* ap 
00765                  = new ::RTC::CORBA::PortServiceProxy(ref);
00766 
00767       Logger logger;
00768       obj->setLogger(&logger);
00769 
00770       ::RTC::Local::ConnectorProfile prof;
00771       ::std::string str1 = "in_ConnectorProfile-name";
00772       ::std::string str2 = "in_connect_id0";
00773       ::std::string str3 = "in_ConnectorProfile-properties0-name";
00774       ::std::string str4 = "2.2";
00775       prof.name = str1;
00776       prof.connector_id = str2;
00777       ::SDOPackage::Local::NameValue nv; 
00778       nv.name  = str3;
00779       nv.value = str4;
00780       prof.properties.push_back(nv);
00781       IPortServiceMock portservice;
00782 
00783       mgr.registerFactory(portservice.id(), 
00784                           doil::New<PortServiceServantMock>,
00785                           doil::Delete<PortServiceServantMock>);
00786       mgr.activateObject(&portservice);
00787       prof.ports.push_back(&portservice);
00788       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("notify_connect"));
00789       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str1));
00790       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str2));
00791       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str3));
00792       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str4));
00793       ::RTC::Local::ReturnCode_t ret;
00794       ret = ap->notify_connect(prof);
00795       mgr.deactivateObject(&portservice);
00796       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("notify_connect"));
00797       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str1));
00798       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str2));
00799       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str3));
00800       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str4));
00801       CPPUNIT_ASSERT_EQUAL(::RTC::Local::RTC_OK, ret);
00802       CPPUNIT_ASSERT_EQUAL(::std::string("ConnectorProfile-name"),
00803                            prof.name);
00804                         
00805       CPPUNIT_ASSERT_EQUAL(::std::string("connect_id0"),
00806                            prof.connector_id);
00807 
00808       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00809                            prof.properties.size());
00810       CPPUNIT_ASSERT_EQUAL(::std::string(
00811                                     "ConnectorProfile-properties0-name"),
00812                            prof.properties[0].name);
00813       CPPUNIT_ASSERT_EQUAL(::std::string("1.1"),
00814                            prof.properties[0].value);
00815       CPPUNIT_ASSERT_EQUAL((::std::string::size_type)1, 
00816                            prof.ports.size());
00817 
00818       
00819 
00820 
00821       delete ap;
00822       CORBA::release(ref);
00823 
00824 
00825     }
00831     void test_notify_disconnect()
00832     {
00833       PortServiceRtmMock* obj = new PortServiceRtmMock();
00834       ::CORBA::Object_ptr ref = obj->_this();
00835       if(::CORBA::is_nil(ref))
00836       {
00837          std::cout<<"ref is nil.Abort test."<<std::endl;
00838          return;
00839       }
00840       ::RTC::CORBA::PortServiceProxy* ap 
00841                  = new ::RTC::CORBA::PortServiceProxy(ref);
00842 
00843       Logger logger;
00844       obj->setLogger(&logger);
00845 
00846       ::std::string str = "test_notify_disconnect";
00847       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("notify_disconnect"));
00848       CPPUNIT_ASSERT_EQUAL(0, logger.countLog(str));
00849       ::RTC::Local::ReturnCode_t ret;
00850       ret = ap->notify_disconnect(str);
00851       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("notify_disconnect"));
00852       CPPUNIT_ASSERT_EQUAL(1, logger.countLog(str));
00853       CPPUNIT_ASSERT_EQUAL(::RTC::Local::RTC_OK, ret);
00854 
00855       
00856 
00857       delete ap;
00858       CORBA::release(ref);
00859 
00860 
00861     }
00862     /* test case */
00863     void test_case0()
00864     {
00865     }
00866   };
00867 }; // namespace PortServiceProxy
00868 
00869 /*
00870  * Register test suite
00871  */
00872 CPPUNIT_TEST_SUITE_REGISTRATION(PortServiceProxy::PortServiceProxyTests);
00873 
00874 #ifdef LOCAL_MAIN
00875 int main(int argc, char* argv[])
00876 {
00877     CppUnit::TextUi::TestRunner runner;
00878     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00879     CppUnit::Outputter* outputter = 
00880       new CppUnit::TextOutputter(&runner.result(), std::cout);
00881     runner.setOutputter(outputter);
00882     bool retcode = runner.run();
00883     return !retcode;
00884 }
00885 #endif // MAIN
00886 #endif // PortServiceProxy_cpp


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