PublisherPeriodicTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log: PublisherPeriodicTests.cpp,v $
00014  * Revision 1.2  2008/01/28 13:52:19  arafune
00015  * Some tests were added.
00016  *
00017  * Revision 1.1  2007/12/20 07:50:17  arafune
00018  * *** empty log message ***
00019  *
00020  * Revision 1.2  2007/01/12 14:54:45  n-ando
00021  * The constructor's signature was changed.
00022  * InPortConsumer base class is now abstruct class. It needs concrete class.
00023  *
00024  * Revision 1.1  2006/12/18 06:51:55  n-ando
00025  * The first commitment.
00026  *
00027  *
00028  */
00029 
00030 #ifndef PublisherPeriodic_cpp
00031 #define PublisherPeriodic_cpp
00032 
00033 #include <cppunit/ui/text/TestRunner.h>
00034 #include <cppunit/TextOutputter.h>
00035 #include <cppunit/extensions/TestFactoryRegistry.h>
00036 #include <cppunit/extensions/HelperMacros.h>
00037 #include <cppunit/TestAssert.h>
00038 
00039 #include <iostream>
00040 #include <coil/Properties.h>
00041 #include <coil/Time.h>
00042 #include <rtm/InPortConsumer.h>
00043 #include <rtm/InPortCorbaCdrConsumer.h>
00044 #include <rtm/PublisherPeriodic.h>
00045 #include <rtm/CdrRingBuffer.h>
00046 #include <rtm/idl/ManagerSkel.h>
00047 
00048 #include <rtm/idl/BasicDataTypeSkel.h>
00049 #include <rtm/ConnectorListener.h>
00050 
00055 namespace PublisherPeriodic
00056 {
00057   int m_OnCheck = 0;
00058 
00062   class DataListener
00063     : public RTC::ConnectorDataListenerT<RTC::TimedLong>
00064   {
00065   public:
00066     DataListener(const char* name) : m_name(name) {}
00067     virtual ~DataListener()
00068     {
00069     }
00070 
00071     virtual void operator()(const RTC::ConnectorInfo& info,
00072                             const RTC::TimedLong& data)
00073     {
00074       std::cout << "------------------------------" << std::endl;
00075       std::cout << "Listener: " << m_name << std::endl;
00076       std::cout << "    Data: " << data.data << std::endl;
00077       std::cout << "------------------------------" << std::endl;
00078     };
00079     std::string m_name;
00080   };
00081 
00086   class PublisherPeriodicMock
00087     : public RTC::PublisherPeriodic
00088   {
00089   public:
00090     PublisherPeriodicMock(void)
00091     {
00092         ;
00093     }
00094     virtual ~PublisherPeriodicMock(void)
00095     {
00096         ;
00097     }
00098   };
00103   class InPortCorbaCdrConsumerMock
00104     : public RTC::InPortCorbaCdrConsumer
00105   {
00106   public:
00111       InPortCorbaCdrConsumerMock(void)
00112       {
00113           m_buffer = new RTC::CdrRingBuffer();
00114           m_test_mode = 0;
00115       }
00120       virtual ~InPortCorbaCdrConsumerMock()
00121       {
00122           delete m_buffer;
00123       }
00128       virtual ReturnCode put(const cdrMemoryStream& data)
00129       {
00130           if(m_test_mode == 0)
00131           {
00132               if (m_buffer->full())
00133               {
00134                    return RTC::PublisherPeriodic::SEND_FULL;
00135               }
00136 
00137               RTC::BufferStatus::Enum ret = m_buffer->write(data);
00138 
00139               //Listener check
00140               if(m_OnCheck == 0) {
00141                   switch(ret)
00142                   {
00143                        case RTC::BufferStatus::BUFFER_OK:
00144                            return RTC::PublisherPeriodic::PORT_OK;
00145                            break;
00146                        case RTC::BufferStatus::BUFFER_ERROR:
00147                            return RTC::PublisherPeriodic::PORT_ERROR;
00148                            break;
00149                        case RTC::BufferStatus::BUFFER_FULL:
00150                            return RTC::PublisherPeriodic::SEND_FULL;
00151                            break;
00152                        case RTC::BufferStatus::BUFFER_EMPTY:
00153                            return RTC::PublisherPeriodic::BUFFER_EMPTY;
00154                            break;
00155                        case RTC::BufferStatus::TIMEOUT:
00156                            return RTC::PublisherPeriodic::SEND_TIMEOUT;
00157                            break;
00158                        default:
00159                            return RTC::PublisherPeriodic::UNKNOWN_ERROR;
00160                    }
00161                    return RTC::PublisherPeriodic::UNKNOWN_ERROR;
00162                   }
00163               else if(m_OnCheck == 1) {
00164                    return RTC::PublisherPeriodic::PORT_OK;
00165               }
00166               else if(m_OnCheck == 2) {
00167                    return RTC::PublisherPeriodic::PORT_ERROR;
00168               }
00169               else if(m_OnCheck == 3) {
00170                    return RTC::PublisherPeriodic::SEND_FULL;
00171               }
00172               else if(m_OnCheck == 4) {
00173                    return RTC::PublisherPeriodic::SEND_TIMEOUT;
00174               }
00175               else if(m_OnCheck == 5) {
00176                    return RTC::PublisherPeriodic::UNKNOWN_ERROR;
00177               }
00178               else if(m_OnCheck == 6) {
00179                    return RTC::PublisherPeriodic::CONNECTION_LOST;
00180               }
00181           }
00182           else if(m_test_mode == 1)
00183           {
00184                std::string str("test");
00185                throw str;
00186           }
00187           else
00188           {
00189           }
00190       }
00195       cdrMemoryStream get_m_put_data(void)
00196       {
00197           cdrMemoryStream cdr;
00198           m_buffer->read(cdr);
00199 
00200           return cdr;
00201       }
00206       int get_m_put_data_len(void)
00207       {
00208           int ic;
00209           ic = (int)m_buffer->readable();
00210 
00211           return ic;
00212       }
00213 
00218       void set_m_mode(int mode)
00219       {
00220           m_test_mode = mode;
00221       }
00222   private:
00223        RTC::CdrBufferBase* m_buffer;
00224        ::OpenRTM::CdrData  m_put_data;
00225        int m_test_mode;
00226   };
00227   class MockConsumer : public RTC::InPortConsumer
00228   {
00229   public:
00230         
00231     MockConsumer() : RTC::InPortConsumer()
00232     {
00233       clearLastTime();
00234     }
00235                 
00236     virtual ~MockConsumer() {}
00237                 
00238     virtual void push()
00239     {
00240       timeval now;
00241       coil::gettimeofday(&now, NULL);
00242                         
00243       if (! isLastTimeCleared())
00244         {
00245           long interval =
00246             (now.tv_sec - _lastTime.tv_sec) * 1000000
00247             + (now.tv_usec - _lastTime.tv_usec);
00248                                 
00249           _intervalTicks.push_back(interval);
00250         }
00251                         
00252       _lastTime = now;
00253     }
00254                 
00255     virtual RTC::InPortConsumer* clone() const
00256     {
00257       MockConsumer* clone = new MockConsumer();
00258       copy(_intervalTicks.begin(), _intervalTicks.end(), clone->_intervalTicks.begin());
00259       clone->_lastTime = _lastTime;
00260                         
00261       return clone;
00262     }
00263 
00264     virtual bool subscribeInterface(const SDOPackage::NVList&)
00265     {
00266       return true;
00267     }
00268                 
00269     virtual void unsubscribeInterface(const SDOPackage::NVList&)
00270     {
00271       return;
00272     }
00273         
00274     virtual const std::vector<long>& getIntervalTicks() const
00275     {
00276       return _intervalTicks;
00277     }
00278                 
00279     virtual int getCount() const
00280     {
00281       return static_cast<int>(_intervalTicks.size());
00282     }
00283                 
00284     virtual void init(coil::Properties& prop)
00285     {
00286     }
00287     virtual InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00288     {
00289         return (InPortConsumer::ReturnCode)0 ;
00290     }
00291     virtual void publishInterfaceProfile(SDOPackage::NVList& properties)
00292     {
00293     }
00294   private:
00295         
00296     std::vector<long> _intervalTicks;
00297     timeval _lastTime;
00298                 
00299   private:
00300         
00301     void clearLastTime()
00302     {
00303       _lastTime.tv_sec = 0;
00304       _lastTime.tv_usec = 0;
00305     }
00306                 
00307     bool isLastTimeCleared()
00308     {
00309       return (_lastTime.tv_sec == 0) && (_lastTime.tv_usec == 0);
00310     }
00311   };
00312         
00313   class CounterConsumer : public RTC::InPortConsumer
00314   {
00315   public:
00316         
00317     CounterConsumer(CounterConsumer* component = NULL)
00318       : RTC::InPortConsumer(), _count(0), _component(component) {}
00319                 
00320     virtual ~CounterConsumer() {}
00321                 
00322     virtual void push()
00323     {
00324       _count++;
00325                         
00326       if (_component != NULL)
00327         {
00328           _component->push();
00329         }
00330     }
00331                 
00332     virtual RTC::InPortConsumer* clone() const
00333     {
00334       CounterConsumer* clone = new CounterConsumer();
00335       clone->_count = _count;
00336       clone->_component = _component;
00337       return clone;
00338     }
00339 
00340     virtual bool subscribeInterface(const SDOPackage::NVList&)
00341     {
00342       return true;
00343     }
00344                 
00345     virtual void unsubscribeInterface(const SDOPackage::NVList&)
00346     {
00347       return;
00348     }
00349 
00350     virtual int getCount() const
00351     {
00352       return _count;
00353     }
00354         
00355     virtual void init(coil::Properties& prop)
00356     {
00357     }
00358     virtual InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
00359     {
00360         return (InPortConsumer::ReturnCode)0 ;
00361     }
00362     virtual void publishInterfaceProfile(SDOPackage::NVList& properties)
00363     {
00364     }
00365   private:
00366         
00367     int _count;
00368     CounterConsumer* _component;
00369   };
00370 
00371   class PublisherPeriodicTests
00372     : public CppUnit::TestFixture
00373   {
00374     CPPUNIT_TEST_SUITE(PublisherPeriodicTests);
00375                 
00376     //CPPUNIT_TEST(test_init);  // OK
00377     CPPUNIT_TEST(test_setConsumer);
00378     CPPUNIT_TEST(test_setBuffer);
00379     //CPPUNIT_TEST(test_activate_deactivate_isActive);  // OK
00380     CPPUNIT_TEST(test_pushAll);
00381     CPPUNIT_TEST(test_pushAll_2);
00382     CPPUNIT_TEST(test_pushFifo);
00383     CPPUNIT_TEST(test_pushFifo_2);
00384     CPPUNIT_TEST(test_pushSkip);
00385     CPPUNIT_TEST(test_pushSkip_2);
00386     CPPUNIT_TEST(test_pushNew);
00387     CPPUNIT_TEST(test_write);
00388                 
00389     CPPUNIT_TEST_SUITE_END();
00390                 
00391   public:
00392     RTC::ConnectorListeners m_listeners;
00393         
00397     PublisherPeriodicTests()
00398     {
00399     }
00400                 
00404     ~PublisherPeriodicTests()
00405     {
00406     }
00407                 
00411     virtual void setUp()
00412     {
00413 //      coil::usleep(1000000);
00414     }
00415     
00419     virtual void tearDown()
00420     { 
00421     }
00422                 
00427     void test_init(void)
00428     {
00429 
00430         PublisherPeriodicMock publisher;
00431         RTC::PublisherBase::ReturnCode retcode;
00432         coil::Properties prop;
00433 
00434         //Propertiesが空の状態ではエラーになることを確認する
00435         retcode = publisher.init(prop);
00436         //coil::usleep(10000);
00437         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode);
00438 
00439         prop.setProperty("publisher.push_policy","new");
00440         prop.setProperty("thread_type","bar");
00441         prop.setProperty("measurement.exec_time","default");
00442         prop.setProperty("measurement.period_count","1");
00443         prop.setProperty("publisher.push_rate","10.0");
00444 
00445         //thread_type が不正の場合 INVALID_ARGS を返すことを確認する。
00446         retcode = publisher.init(prop);
00447         //coil::usleep(10000);
00448         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
00449 
00450         //以下のpropertiesの設定で動作することを確認する。
00451         prop.setProperty("publisher.push_policy","all");
00452         prop.setProperty("publisher.skip_count","0");
00453         prop.setProperty("thread_type","default");
00454         prop.setProperty("measurement.exec_time","enable");
00455         prop.setProperty("measurement.exec_count","0");
00456         prop.setProperty("measurement.period_time","enable");
00457         prop.setProperty("measurement.period_count","0");
00458         prop.setProperty("publisher.push_rate","10");
00459         retcode = publisher.init(prop);
00460         //coil::usleep(10000);
00461         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
00462 
00463         prop.setProperty("publisher.push_policy","fifo");
00464         prop.setProperty("publisher.skip_count","1");
00465         prop.setProperty("thread_type","default");
00466         prop.setProperty("measurement.exec_time","disable");
00467         prop.setProperty("measurement.exec_count","1");
00468         prop.setProperty("measurement.period_time","disable");
00469         prop.setProperty("measurement.period_count","1");
00470         prop.setProperty("publisher.push_rate","20");
00471         retcode = publisher.init(prop);
00472         //coil::usleep(10000);
00473         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
00474 
00475         prop.setProperty("publisher.push_policy","skip");
00476         prop.setProperty("publisher.skip_count","-1");
00477         prop.setProperty("thread_type","default");
00478         prop.setProperty("measurement.exec_time","bar");
00479         prop.setProperty("measurement.exec_count","-1");
00480         prop.setProperty("measurement.period_time","bar");
00481         prop.setProperty("measurement.period_count","-1");
00482         prop.setProperty("publisher.push_rate","10");
00483         retcode = publisher.init(prop);
00484         //coil::usleep(10000);
00485         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
00486 
00487         prop.setProperty("publisher.push_policy","new");
00488         prop.setProperty("publisher.skip_count","foo");
00489         prop.setProperty("thread_type","default");
00490         prop.setProperty("measurement.exec_time","enable");
00491         prop.setProperty("measurement.exec_count","foo");
00492         prop.setProperty("measurement.period_time","enable");
00493         prop.setProperty("measurement.period_count","foo");
00494         prop.setProperty("publisher.push_rate","10");
00495         retcode = publisher.init(prop);
00496         //coil::usleep(10000);
00497         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
00498 
00499         prop.setProperty("publisher.push_policy","bar");
00500         prop.setProperty("publisher.skip_count","0");
00501         prop.setProperty("thread_type","default");
00502         prop.setProperty("measurement.exec_time","enable");
00503         prop.setProperty("measurement.exec_count","0");
00504         prop.setProperty("measurement.period_time","enable");
00505         prop.setProperty("measurement.period_count","0");
00506         prop.setProperty("publisher.push_rate","10");
00507         retcode = publisher.init(prop);
00508         //coil::usleep(10000);
00509         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
00510 
00511         prop.setProperty("publisher.push_policy","all");
00512         prop.setProperty("publisher.skip_count","0");
00513         prop.setProperty("thread_type","default");
00514         prop.setProperty("measurement.exec_time","enable");
00515         prop.setProperty("measurement.exec_count","0");
00516         prop.setProperty("measurement.period_time","enable");
00517         prop.setProperty("measurement.period_count","0");
00518         prop.setProperty("publisher.push_rate","0");
00519         retcode = publisher.init(prop);
00520         //coil::usleep(10000);
00521         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode);
00522 
00523         prop.setProperty("publisher.push_policy","all");
00524         prop.setProperty("publisher.skip_count","0");
00525         prop.setProperty("thread_type","default");
00526         prop.setProperty("measurement.exec_time","enable");
00527         prop.setProperty("measurement.exec_count","0");
00528         prop.setProperty("measurement.period_time","enable");
00529         prop.setProperty("measurement.period_count","0");
00530         prop.setProperty("publisher.push_rate","-1");
00531         retcode = publisher.init(prop);
00532         //coil::usleep(10000);
00533         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode);
00534 
00535     }
00540     void test_setConsumer(void)
00541     {
00542         RTC::InPortCorbaCdrConsumer* consumer0 
00543                                     = new RTC::InPortCorbaCdrConsumer();
00544         RTC::InPortCorbaCdrConsumer* consumer1 
00545                                     = new RTC::InPortCorbaCdrConsumer();
00546         RTC::PublisherPeriodic publisher;
00547 
00548         //NULLを渡した場合INVALID_ARGSとなることを確認する。
00549         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, 
00550                              publisher.setConsumer(NULL));
00551 
00552         //
00553         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00554                              publisher.setConsumer(consumer0));
00555 
00556         //
00557         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00558                              publisher.setConsumer(consumer1));
00559 
00560         delete consumer1;
00561         delete consumer0;
00562     }
00567     void test_setBuffer(void)
00568     {
00569         RTC::CdrBufferBase* buffer0 = new RTC::CdrRingBuffer();
00570         RTC::CdrBufferBase* buffer1 = new RTC::CdrRingBuffer();
00571         RTC::PublisherPeriodic publisher;
00572 
00573         //NULLを渡した場合INVALID_ARGSとなることを確認する。
00574         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, 
00575                              publisher.setBuffer(NULL));
00576 
00577         //
00578         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00579                              publisher.setBuffer(buffer0));
00580 
00581         //
00582         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00583                              publisher.setBuffer(buffer1));
00584 
00585         delete buffer1;
00586         delete buffer0;
00587     }
00592     void test_activate_deactivate_isActive(void)
00593     {
00594         RTC::InPortCorbaCdrConsumer* consumer 
00595                                     = new RTC::InPortCorbaCdrConsumer();
00596         RTC::PublisherPeriodic publisher;
00597         publisher.setConsumer(consumer);
00598 
00599         //init() せずに activate() をコールした場合をi
00600         //PRECONDITION_NOT_MET 返すことを確認する。
00601         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, 
00602                              publisher.activate());
00603 
00604         //init() せずに deactivate() をコールした場合をi
00605         //PRECONDITION_NOT_MET 返すことを確認する。
00606         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, 
00607                              publisher.deactivate());
00608 
00609         //init()
00610         coil::Properties prop;
00611         prop.setProperty("publisher.push_policy","all");
00612         prop.setProperty("publisher.skip_count","0");
00613         prop.setProperty("thread_type","default");
00614         prop.setProperty("measurement.exec_time","enable");
00615         prop.setProperty("measurement.exec_count","0");
00616         prop.setProperty("measurement.period_time","enable");
00617         prop.setProperty("measurement.period_count","0");
00618         prop.setProperty("publisher.push_rate","20");
00619         publisher.init(prop);
00620         coil::usleep(10000);
00621 
00622         
00623         //setBuffer() せずに activate() をコールした場合をi
00624         //PRECONDITION_NOT_MET 返すことを確認する。
00625         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, 
00626                              publisher.activate());
00627 
00628         //setBuffer()
00629         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
00630         publisher.setBuffer(buffer);
00631 
00632 
00633         CPPUNIT_ASSERT_EQUAL(false, 
00634                              publisher.isActive());
00635         
00636         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00637                              publisher.activate());
00638 
00639         CPPUNIT_ASSERT_EQUAL(true, 
00640                              publisher.isActive());
00641 
00642         //既に activate されている場合は 
00643         //activateすると
00644         //PORT_OK を返すことを確認する。
00645         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00646                              publisher.activate());
00647 
00648         CPPUNIT_ASSERT_EQUAL(true, 
00649                              publisher.isActive());
00650         
00651         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00652                              publisher.deactivate());
00653 
00654         CPPUNIT_ASSERT_EQUAL(false, 
00655                              publisher.isActive());
00656         
00657         //activate されていない状態で、
00658         //deactivateすると
00659         //PORT_OK を返すことを確認する。
00660         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, 
00661                              publisher.deactivate());
00662         
00663         CPPUNIT_ASSERT_EQUAL(false, 
00664                              publisher.isActive());
00665         
00666         delete buffer;
00667         delete consumer;
00668     }
00674     void test_pushAll(void)
00675     {
00676         InPortCorbaCdrConsumerMock* consumer 
00677                                     = new InPortCorbaCdrConsumerMock();
00678         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
00679         PublisherPeriodicMock publisher;
00680 
00681         coil::Properties prop;
00682         prop.setProperty("publisher.push_policy","all");
00683         prop.setProperty("publisher.skip_count","0");
00684         prop.setProperty("thread_type","default");
00685         prop.setProperty("measurement.exec_time","enable");
00686         prop.setProperty("measurement.exec_count","0");
00687         prop.setProperty("measurement.period_time","enable");
00688         prop.setProperty("measurement.period_count","0");
00689         prop.setProperty("publisher.push_rate","10");
00690         publisher.init(prop);
00691         coil::usleep(10000);
00692 
00693         //ConnectorInfo
00694         coil::vstring ports;
00695         RTC::ConnectorInfo info("name", "id", ports, prop);
00696 
00697         //ConnectorListeners
00698         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
00699                                    new DataListener("ON_BUFFER_WRITE"), true);
00700         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
00701                                    new DataListener("ON_BUFFER_FULL"), true);
00702         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
00703                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
00704         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
00705                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
00706         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
00707                                    new DataListener("ON_BUFFER_READ"), true);
00708         m_listeners.connectorData_[RTC::ON_SEND].addListener(
00709                                    new DataListener("ON_SEND"), true);
00710         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
00711                                    new DataListener("ON_RECEIVED"), true);
00712         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
00713                                    new DataListener("ON_RECEIVER_FULL"), true);
00714         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
00715                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
00716         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
00717                                    new DataListener("ON_RECEIVER_ERROR"), true);
00718 
00719         // setListener
00720         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
00721                              publisher.setListener(info, 0));
00722         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
00723                              publisher.setListener(info, &m_listeners));
00724 
00725         publisher.setConsumer(consumer);
00726         publisher.setBuffer(buffer);
00727         publisher.activate();
00728 
00729         for(int icc(0);icc<8;++icc)
00730         {
00731             cdrMemoryStream cdr;
00732             RTC::TimedLong td;
00733             td.data = icc;
00734             td >>= cdr;
00735 
00736             CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
00737                                  publisher.write(cdr,0,0));
00738 
00739         }
00740 
00741         coil::usleep(150000);
00742         //provider 側のバッファ full の状態でコール(full)
00743         {
00744         cdrMemoryStream cdr;
00745         RTC::TimedLong td;
00746         td.data = 8;
00747         td >>= cdr;
00748         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
00749                                  publisher.write(cdr,0,0));
00750         coil::usleep(150000);
00751         }
00752         {
00753         cdrMemoryStream cdr;
00754         RTC::TimedLong td;
00755         td.data = 9;
00756         td >>= cdr;
00757         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
00758                                  publisher.write(cdr,0,0));
00759         coil::usleep(150000);
00760         }
00761 
00762         //provider 側のバッファから 4 件取得
00763         //(full ではない状態にする )
00764         for(int icc(0);icc<4;++icc)
00765         {
00766             cdrMemoryStream data;
00767             data = consumer->get_m_put_data();
00768             CORBA::ULong inlen = data.bufSize();
00769             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
00770 
00771             RTC::TimedLong rtd;
00772             rtd <<= data;
00773             CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
00774         }
00775 
00776         coil::usleep(150000);
00777         //provider 側のバッファ full ではない状態でコール
00778         {
00779         cdrMemoryStream cdr;
00780         RTC::TimedLong td;
00781         td.data = 10;
00782         td >>= cdr;
00783         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
00784                                  publisher.write(cdr,0,0));
00785         coil::usleep(150000);
00786         }
00787         {
00788         cdrMemoryStream cdr;
00789         RTC::TimedLong td;
00790         td.data = 11;
00791         td >>= cdr;
00792         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
00793                                  publisher.write(cdr,0,0));
00794         coil::usleep(150000);
00795         }
00796 
00797         //データ抜けががないことを確認する。
00798         for(int icc(0);icc<8;++icc)
00799         {
00800             cdrMemoryStream data;
00801             data = consumer->get_m_put_data();
00802             CORBA::ULong inlen = data.bufSize();
00803             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
00804 
00805             RTC::TimedLong rtd;
00806             rtd <<= data;
00807             CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data);
00808         }
00809         publisher.deactivate();
00810         
00811         delete buffer;
00812         delete consumer;
00813         
00814     }
00820     void test_pushAll_2(void)
00821     {
00822         InPortCorbaCdrConsumerMock* consumer 
00823                                     = new InPortCorbaCdrConsumerMock();
00824         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
00825         PublisherPeriodicMock publisher;
00826 
00827         coil::Properties prop;
00828         prop.setProperty("publisher.push_policy","all");
00829         prop.setProperty("publisher.skip_count","0");
00830         prop.setProperty("thread_type","default");
00831         prop.setProperty("measurement.exec_time","enable");
00832         prop.setProperty("measurement.exec_count","0");
00833         prop.setProperty("measurement.period_time","enable");
00834         prop.setProperty("measurement.period_count","0");
00835         prop.setProperty("publisher.push_rate","10");
00836         publisher.init(prop);
00837         coil::usleep(10000);
00838 
00839         //ConnectorInfo
00840         coil::vstring ports;
00841         RTC::ConnectorInfo info("name", "id", ports, prop);
00842 
00843         //ConnectorListeners
00844         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
00845                                    new DataListener("ON_BUFFER_WRITE"), true);
00846         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
00847                                    new DataListener("ON_BUFFER_FULL"), true);
00848         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
00849                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
00850         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
00851                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
00852         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
00853                                    new DataListener("ON_BUFFER_READ"), true);
00854         m_listeners.connectorData_[RTC::ON_SEND].addListener(
00855                                    new DataListener("ON_SEND"), true);
00856         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
00857                                    new DataListener("ON_RECEIVED"), true);
00858         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
00859                                    new DataListener("ON_RECEIVER_FULL"), true);
00860         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
00861                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
00862         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
00863                                    new DataListener("ON_RECEIVER_ERROR"), true);
00864 
00865         // setListener
00866         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
00867                              publisher.setListener(info, 0));
00868         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
00869                              publisher.setListener(info, &m_listeners));
00870 
00871         publisher.setConsumer(consumer);
00872         publisher.setBuffer(buffer);
00873         publisher.activate();
00874 
00875         for(int icc(0);icc<16;++icc)
00876         {
00877             cdrMemoryStream cdr;
00878             RTC::TimedLong td;
00879             td.data = icc;
00880             td >>= cdr;
00881 
00882             RTC::PublisherBase::ReturnCode ret;
00883             ret = publisher.write(cdr,0,0);
00884             if(icc<9)
00885             {
00886                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
00887                                      ret);
00888             }
00889             else
00890             {
00891                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
00892                                      ret);
00893             }
00894             coil::usleep(150000);
00895 
00896         }
00897 
00898         //consumer と provider 両方の buffer が full 状態のため、
00899         // この write データは抜ける。
00900         {
00901         cdrMemoryStream cdr;
00902         RTC::TimedLong td;
00903         td.data = 16;
00904         td >>= cdr;
00905         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
00906                                  publisher.write(cdr,0,0));
00907         coil::usleep(150000);
00908         }
00909 
00910         //データを確認する。
00911         for(int icc(0);icc<8;++icc)
00912         {
00913             cdrMemoryStream data;
00914             data = consumer->get_m_put_data();
00915             CORBA::ULong inlen = data.bufSize();
00916             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
00917 
00918             RTC::TimedLong rtd;
00919             rtd <<= data;
00920             CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
00921         }
00922 
00923         coil::usleep(300000);
00924         //データを確認する。
00925         for(int icc(0);icc<8;++icc)
00926         {
00927             cdrMemoryStream data;
00928             data = consumer->get_m_put_data();
00929             CORBA::ULong inlen = data.bufSize();
00930             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
00931 
00932             RTC::TimedLong rtd;
00933             rtd <<= data;
00934             CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data);
00935         }
00936         {
00937         cdrMemoryStream cdr;
00938         RTC::TimedLong td;
00939         td.data = 17;
00940         td >>= cdr;
00941         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
00942                                  publisher.write(cdr,0,0));
00943         coil::usleep(150000);
00944         }
00945         //データを確認する。
00946         {
00947         cdrMemoryStream data;
00948         data = consumer->get_m_put_data();
00949         CORBA::ULong inlen = data.bufSize();
00950         CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
00951 
00952         RTC::TimedLong rtd;
00953         rtd <<= data;
00954         CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data);
00955         }
00956 
00957         coil::usleep(150000);
00958         publisher.deactivate();
00959         
00960         delete buffer;
00961         delete consumer;
00962         
00963     }
00968     void test_pushFifo(void)
00969     {
00970         InPortCorbaCdrConsumerMock* consumer 
00971                                     = new InPortCorbaCdrConsumerMock();
00972         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
00973         PublisherPeriodicMock publisher;
00974 
00975         coil::Properties prop;
00976         prop.setProperty("publisher.push_policy","fifo");
00977         prop.setProperty("publisher.skip_count","0");
00978         prop.setProperty("thread_type","default");
00979         prop.setProperty("measurement.exec_time","enable");
00980         prop.setProperty("measurement.exec_count","0");
00981         prop.setProperty("measurement.period_time","enable");
00982         prop.setProperty("measurement.period_count","0");
00983         prop.setProperty("publisher.push_rate","10");
00984         publisher.init(prop);
00985         coil::usleep(10000);
00986 
00987         //ConnectorInfo
00988         coil::vstring ports;
00989         RTC::ConnectorInfo info("name", "id", ports, prop);
00990 
00991         //ConnectorListeners
00992         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
00993                                    new DataListener("ON_BUFFER_WRITE"), true);
00994         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
00995                                    new DataListener("ON_BUFFER_FULL"), true);
00996         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
00997                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
00998         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
00999                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
01000         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
01001                                    new DataListener("ON_BUFFER_READ"), true);
01002         m_listeners.connectorData_[RTC::ON_SEND].addListener(
01003                                    new DataListener("ON_SEND"), true);
01004         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
01005                                    new DataListener("ON_RECEIVED"), true);
01006         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
01007                                    new DataListener("ON_RECEIVER_FULL"), true);
01008         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
01009                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
01010         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
01011                                    new DataListener("ON_RECEIVER_ERROR"), true);
01012 
01013         // setListener
01014         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
01015                              publisher.setListener(info, 0));
01016         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
01017                              publisher.setListener(info, &m_listeners));
01018 
01019         publisher.setConsumer(consumer);
01020         publisher.setBuffer(buffer);
01021         publisher.activate();
01022 
01023         for(int icc(0);icc<8;++icc)
01024         {
01025             cdrMemoryStream cdr;
01026             RTC::TimedLong td;
01027             td.data = icc;
01028             td >>= cdr;
01029 
01030             CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01031                                  publisher.write(cdr,0,0));
01032 
01033         coil::usleep(150000);
01034         }
01035 
01036         //provider 側のバッファ full の状態でコール(full)
01037         {
01038         cdrMemoryStream cdr;
01039         RTC::TimedLong td;
01040         td.data = 8;
01041         td >>= cdr;
01042         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01043                                  publisher.write(cdr,0,0));
01044         coil::usleep(150000);
01045         }
01046         {
01047         cdrMemoryStream cdr;
01048         RTC::TimedLong td;
01049         td.data = 9;
01050         td >>= cdr;
01051         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01052                                  publisher.write(cdr,0,0));
01053         coil::usleep(150000);
01054         }
01055 
01056         //provider 側のバッファから 4 件取得
01057         //(full ではない状態にする )
01058         for(int icc(0);icc<4;++icc)
01059         {
01060             cdrMemoryStream data;
01061             data = consumer->get_m_put_data();
01062             CORBA::ULong inlen = data.bufSize();
01063             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01064 
01065             RTC::TimedLong rtd;
01066             rtd <<= data;
01067             CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
01068         }
01069         coil::usleep(220000); //Waits to complete writing 8 and 9. 
01070 
01071         //provider 側のバッファ full ではない状態でコール
01072         {
01073         cdrMemoryStream cdr;
01074         RTC::TimedLong td;
01075         td.data = 10;
01076         td >>= cdr;
01077         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01078                                  publisher.write(cdr,0,0));
01079         coil::usleep(150000);
01080         }
01081         {
01082         cdrMemoryStream cdr;
01083         RTC::TimedLong td;
01084         td.data = 11;
01085         td >>= cdr;
01086         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01087                                  publisher.write(cdr,0,0));
01088         coil::usleep(150000);
01089         }
01090         {
01091         cdrMemoryStream cdr;
01092         RTC::TimedLong td;
01093         td.data = 12;
01094         td >>= cdr;
01095         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01096                                  publisher.write(cdr,0,0));
01097         coil::usleep(150000);
01098         }
01099         {
01100         cdrMemoryStream cdr;
01101         RTC::TimedLong td;
01102         td.data = 13;
01103         td >>= cdr;
01104         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01105                                  publisher.write(cdr,0,0));
01106         coil::usleep(150000);
01107         }
01108 
01109         //データ抜けががないことを確認する。
01110         for(int icc(0);icc<8;++icc)
01111         {
01112             cdrMemoryStream data;
01113             data = consumer->get_m_put_data();
01114             CORBA::ULong inlen = data.bufSize();
01115             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01116 
01117             RTC::TimedLong rtd;
01118             rtd <<= data;
01119             CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data);
01120         }
01121         coil::usleep(400000);  //Meanwhile, 12 and 13 are forwarded. 
01122         for(int icc(0);icc<2;++icc)
01123         {
01124             cdrMemoryStream data;
01125             data = consumer->get_m_put_data();
01126             CORBA::ULong inlen = data.bufSize();
01127             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01128 
01129             RTC::TimedLong rtd;
01130             rtd <<= data;
01131             CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data);
01132         }
01133 
01134 
01135         coil::usleep(10000);
01136         publisher.deactivate();
01137         delete buffer;
01138         delete consumer;
01139         
01140     }
01146     void test_pushFifo_2(void)
01147     {
01148         InPortCorbaCdrConsumerMock* consumer 
01149                                     = new InPortCorbaCdrConsumerMock();
01150         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
01151         PublisherPeriodicMock publisher;
01152 
01153         coil::Properties prop;
01154         prop.setProperty("publisher.push_policy","fifo");
01155         prop.setProperty("publisher.skip_count","0");
01156         prop.setProperty("thread_type","default");
01157         prop.setProperty("measurement.exec_time","enable");
01158         prop.setProperty("measurement.exec_count","0");
01159         prop.setProperty("measurement.period_time","enable");
01160         prop.setProperty("measurement.period_count","0");
01161         prop.setProperty("publisher.push_rate","10");
01162         publisher.init(prop);
01163         coil::usleep(10000);
01164 
01165         //ConnectorInfo
01166         coil::vstring ports;
01167         RTC::ConnectorInfo info("name", "id", ports, prop);
01168 
01169         //ConnectorListeners
01170         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
01171                                    new DataListener("ON_BUFFER_WRITE"), true);
01172         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
01173                                    new DataListener("ON_BUFFER_FULL"), true);
01174         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
01175                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
01176         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
01177                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
01178         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
01179                                    new DataListener("ON_BUFFER_READ"), true);
01180         m_listeners.connectorData_[RTC::ON_SEND].addListener(
01181                                    new DataListener("ON_SEND"), true);
01182         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
01183                                    new DataListener("ON_RECEIVED"), true);
01184         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
01185                                    new DataListener("ON_RECEIVER_FULL"), true);
01186         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
01187                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
01188         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
01189                                    new DataListener("ON_RECEIVER_ERROR"), true);
01190 
01191         // setListener
01192         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
01193                              publisher.setListener(info, 0));
01194         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
01195                              publisher.setListener(info, &m_listeners));
01196 
01197         publisher.setConsumer(consumer);
01198         publisher.setBuffer(buffer);
01199         publisher.activate();
01200 
01201         //consumer と provider 両方の buffer を full 状態にする
01202         for(int icc(0);icc<16;++icc)
01203         {
01204             cdrMemoryStream cdr;
01205             RTC::TimedLong td;
01206             td.data = icc;
01207             td >>= cdr;
01208 
01209             RTC::PublisherBase::ReturnCode ret;
01210             ret = publisher.write(cdr,0,0);
01211             if(icc<9)
01212             {
01213                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01214                                      ret);
01215             }
01216             else
01217             {
01218                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01219                                      ret);
01220             }
01221             coil::usleep(150000);
01222 
01223         }
01224 
01225         //consumer と provider 両方の buffer が full 状態のため、
01226         // この write データは抜ける。
01227         {
01228         cdrMemoryStream cdr;
01229         RTC::TimedLong td;
01230         td.data = 16;
01231         td >>= cdr;
01232         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01233                                  publisher.write(cdr,0,0));
01234         coil::usleep(100000);
01235         }
01236 
01237         //データを確認する。
01238         for(int icc(0);icc<8;++icc)
01239         {
01240             cdrMemoryStream data;
01241             data = consumer->get_m_put_data();
01242             CORBA::ULong inlen = data.bufSize();
01243             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01244 
01245             RTC::TimedLong rtd;
01246             rtd <<= data;
01247             CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
01248         }
01249 
01250         coil::usleep(800000);
01251         // この write データは転送される。
01252         for(int icc(0);icc<8;++icc)
01253         {
01254             cdrMemoryStream cdr;
01255             RTC::TimedLong td;
01256             td.data = 17+icc;
01257             td >>= cdr;
01258             RTC::PublisherBase::ReturnCode ret;
01259             ret = publisher.write(cdr,0,0);
01260             if(icc<1)
01261             {
01262                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01263                                      ret);
01264             }
01265             //else
01266             //{
01267             //    CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01268             //                         ret);
01269             //}
01270             coil::usleep(100000);
01271         }
01272         coil::usleep(80000);
01273         //データを確認する。
01274         for(int icc(0);icc<8;++icc)
01275         {
01276             cdrMemoryStream data;
01277             data = consumer->get_m_put_data();
01278             CORBA::ULong inlen = data.bufSize();
01279             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01280 
01281             RTC::TimedLong rtd;
01282             rtd <<= data;
01283             CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data);
01284         }
01285         coil::usleep(100000);
01286         {
01287         cdrMemoryStream cdr;
01288         RTC::TimedLong td;
01289         td.data = 25;
01290         td >>= cdr;
01291         //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01292         //                         publisher.write(cdr,0,0));
01293         coil::usleep(100000);
01294         }
01295         coil::usleep(800000);
01296         //データを確認する。
01297         for(int icc(0);icc<8;++icc)
01298         {
01299             cdrMemoryStream data;
01300             data = consumer->get_m_put_data();
01301             CORBA::ULong inlen = data.bufSize();
01302             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01303 
01304             RTC::TimedLong rtd;
01305             rtd <<= data;
01306             CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data);
01307         }
01308 
01309 
01310         coil::usleep(100000);
01311         publisher.deactivate();
01312         
01313         delete buffer;
01314         delete consumer;
01315         
01316     }
01321     void test_pushSkip(void)
01322     {
01323         InPortCorbaCdrConsumerMock* consumer 
01324                                     = new InPortCorbaCdrConsumerMock();
01325         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
01326         PublisherPeriodicMock publisher;
01327 
01328         coil::Properties prop;
01329         prop.setProperty("publisher.push_policy","skip");
01330         prop.setProperty("publisher.skip_count","1");
01331         prop.setProperty("thread_type","default");
01332         prop.setProperty("measurement.exec_time","enable");
01333         prop.setProperty("measurement.exec_count","0");
01334         prop.setProperty("measurement.period_time","enable");
01335         prop.setProperty("measurement.period_count","0");
01336         prop.setProperty("publisher.push_rate","10.0");
01337         publisher.init(prop);
01338         coil::usleep(10000);
01339 
01340         //ConnectorInfo
01341         coil::vstring ports;
01342         RTC::ConnectorInfo info("name", "id", ports, prop);
01343 
01344         //ConnectorListeners
01345         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
01346                                    new DataListener("ON_BUFFER_WRITE"), true);
01347         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
01348                                    new DataListener("ON_BUFFER_FULL"), true);
01349         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
01350                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
01351         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
01352                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
01353         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
01354                                    new DataListener("ON_BUFFER_READ"), true);
01355         m_listeners.connectorData_[RTC::ON_SEND].addListener(
01356                                    new DataListener("ON_SEND"), true);
01357         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
01358                                    new DataListener("ON_RECEIVED"), true);
01359         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
01360                                    new DataListener("ON_RECEIVER_FULL"), true);
01361         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
01362                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
01363         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
01364                                    new DataListener("ON_RECEIVER_ERROR"), true);
01365 
01366         // setListener
01367         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
01368                              publisher.setListener(info, 0));
01369         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
01370                              publisher.setListener(info, &m_listeners));
01371 
01372         publisher.setConsumer(consumer);
01373         publisher.setBuffer(buffer);
01374         publisher.activate();
01375 
01376         for(int icc(0);icc<16;++icc)
01377         {
01378             cdrMemoryStream cdr;
01379             RTC::TimedLong td;
01380             td.data = icc;
01381             td >>= cdr;
01382 
01383             CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01384                                  publisher.write(cdr,0,0));
01385 
01386             coil::usleep(150000);
01387         }
01388 
01389         //provider 側のバッファ full の状態でコール(full)
01390         {
01391         cdrMemoryStream cdr;
01392         RTC::TimedLong td;
01393         td.data = 16;
01394         td >>= cdr;
01395         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01396                                  publisher.write(cdr,0,0));
01397         coil::usleep(150000);
01398         }
01399         {
01400         cdrMemoryStream cdr;
01401         RTC::TimedLong td;
01402         td.data = 17;
01403         td >>= cdr;
01404         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01405                                  publisher.write(cdr,0,0));
01406         coil::usleep(150000);
01407         }
01408 
01409         //provider 側のバッファから 4 件取得
01410         //(full ではない状態にする )
01411         for(int icc(0);icc<4;++icc)
01412         {
01413             cdrMemoryStream data;
01414             data = consumer->get_m_put_data();
01415             CORBA::ULong inlen = data.bufSize();
01416             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01417 
01418             RTC::TimedLong rtd;
01419             rtd <<= data;
01420             CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data);
01421         }
01422 
01423         coil::usleep(450000);
01424         //provider 側のバッファ full ではない状態でコール
01425         {
01426         cdrMemoryStream cdr;
01427         RTC::TimedLong td;
01428         td.data = 18;
01429         td >>= cdr;
01430         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01431                                  publisher.write(cdr,0,0));
01432         coil::usleep(150000);
01433         }
01434         {
01435         cdrMemoryStream cdr;
01436         RTC::TimedLong td;
01437         td.data = 19;
01438         td >>= cdr;
01439         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01440                                  publisher.write(cdr,0,0));
01441         coil::usleep(150000);
01442         }
01443 
01444         //データ抜けががないことを確認する。
01445         CPPUNIT_ASSERT_EQUAL(6,
01446                               consumer->get_m_put_data_len());
01447         for(int icc(0);icc<6;++icc)
01448         {
01449             cdrMemoryStream data;
01450             data = consumer->get_m_put_data();
01451             CORBA::ULong inlen = data.bufSize();
01452             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01453 
01454             RTC::TimedLong rtd;
01455             rtd <<= data;
01456             CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data);
01457         }
01458        
01459         coil::usleep(100000);
01460         publisher.deactivate();
01461         delete buffer;
01462         delete consumer;
01463     }
01469     void test_pushSkip_2(void)
01470     {
01471         InPortCorbaCdrConsumerMock* consumer 
01472                                     = new InPortCorbaCdrConsumerMock();
01473         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
01474         PublisherPeriodicMock publisher;
01475 
01476         coil::Properties prop;
01477         prop.setProperty("publisher.push_policy","skip");
01478         prop.setProperty("publisher.skip_count","1");
01479         prop.setProperty("thread_type","default");
01480         prop.setProperty("measurement.exec_time","enable");
01481         prop.setProperty("measurement.exec_count","0");
01482         prop.setProperty("measurement.period_time","enable");
01483         prop.setProperty("measurement.period_count","0");
01484         prop.setProperty("publisher.push_rate","10.0");
01485         publisher.init(prop);
01486         coil::usleep(10000);
01487 
01488         //ConnectorInfo
01489         coil::vstring ports;
01490         RTC::ConnectorInfo info("name", "id", ports, prop);
01491 
01492         //ConnectorListeners
01493         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
01494                                    new DataListener("ON_BUFFER_WRITE"), true);
01495         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
01496                                    new DataListener("ON_BUFFER_FULL"), true);
01497         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
01498                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
01499         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
01500                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
01501         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
01502                                    new DataListener("ON_BUFFER_READ"), true);
01503         m_listeners.connectorData_[RTC::ON_SEND].addListener(
01504                                    new DataListener("ON_SEND"), true);
01505         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
01506                                    new DataListener("ON_RECEIVED"), true);
01507         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
01508                                    new DataListener("ON_RECEIVER_FULL"), true);
01509         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
01510                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
01511         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
01512                                    new DataListener("ON_RECEIVER_ERROR"), true);
01513 
01514         // setListener
01515         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
01516                              publisher.setListener(info, 0));
01517         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
01518                              publisher.setListener(info, &m_listeners));
01519 
01520         publisher.setConsumer(consumer);
01521         publisher.setBuffer(buffer);
01522         publisher.activate();
01523 
01524         //consumer と provider 両方の buffer を full 状態にする
01525         for(int icc(0);icc<25;++icc)
01526         {
01527             cdrMemoryStream cdr;
01528             RTC::TimedLong td;
01529             td.data = icc;
01530             td >>= cdr;
01531 
01532             RTC::PublisherBase::ReturnCode ret;
01533             ret = publisher.write(cdr,0,0);
01534             if(icc<18)
01535             {
01536                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01537                                      ret);
01538             }
01539             else
01540             {
01541                 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01542                                      ret);
01543             }
01544             coil::usleep(150000);
01545 
01546         }
01547 
01548         //consumer と provider 両方の buffer が full 状態のため、
01549         // この write データは抜ける。
01550         {
01551         cdrMemoryStream cdr;
01552         RTC::TimedLong td;
01553         td.data = 25;
01554         td >>= cdr;
01555         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
01556                                  publisher.write(cdr,0,0));
01557         coil::usleep(150000);
01558         }
01559 
01560         //データを確認する。
01561         for(int icc(0);icc<8;++icc)
01562         {
01563             cdrMemoryStream data;
01564             data = consumer->get_m_put_data();
01565             CORBA::ULong inlen = data.bufSize();
01566             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01567 
01568             RTC::TimedLong rtd;
01569             rtd <<= data;
01570             CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data);
01571         }
01572 
01573         coil::usleep(150000);
01574         //データを確認する。
01575         int len =consumer->get_m_put_data_len();
01576         CPPUNIT_ASSERT_EQUAL(4,len);
01577         for(int icc(0);icc<len;++icc)
01578         {
01579             cdrMemoryStream data;
01580             data = consumer->get_m_put_data();
01581             CORBA::ULong inlen = data.bufSize();
01582             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01583 
01584             RTC::TimedLong rtd;
01585             rtd <<= data;
01586             CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data);
01587         }
01588         coil::usleep(150000);
01589         {
01590         cdrMemoryStream cdr;
01591         RTC::TimedLong td;
01592         td.data = 26;
01593         td >>= cdr;
01594         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01595                                  publisher.write(cdr,0,0));
01596         coil::usleep(150000);
01597         }
01598         {
01599         cdrMemoryStream cdr;
01600         RTC::TimedLong td;
01601         td.data = 27;
01602         td >>= cdr;
01603         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01604                                  publisher.write(cdr,0,0));
01605         coil::usleep(150000);
01606         }
01607         //データを確認する。
01608         {
01609 
01610         cdrMemoryStream data;
01611         data = consumer->get_m_put_data();
01612         CORBA::ULong inlen = data.bufSize();
01613         CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01614 
01615         RTC::TimedLong rtd;
01616         rtd <<= data;
01617         CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data);
01618         }
01619 
01620         coil::usleep(100000);
01621         publisher.deactivate();
01622         
01623         delete buffer;
01624         delete consumer;
01625         
01626     }
01631     void test_pushNew(void)
01632     {
01633         InPortCorbaCdrConsumerMock* consumer 
01634                                     = new InPortCorbaCdrConsumerMock();
01635         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
01636         PublisherPeriodicMock publisher;
01637 
01638         coil::Properties prop;
01639         prop.setProperty("publisher.push_policy","new");
01640         prop.setProperty("publisher.skip_count","0");
01641         prop.setProperty("thread_type","default");
01642         prop.setProperty("measurement.exec_time","enable");
01643         prop.setProperty("measurement.exec_count","0");
01644         prop.setProperty("measurement.period_time","enable");
01645         prop.setProperty("measurement.period_count","0");
01646         prop.setProperty("publisher.push_rate","10");
01647         publisher.init(prop);
01648         coil::usleep(10000);
01649 
01650         //ConnectorInfo
01651         coil::vstring ports;
01652         RTC::ConnectorInfo info("name", "id", ports, prop);
01653 
01654         //ConnectorListeners
01655         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
01656                                    new DataListener("ON_BUFFER_WRITE"), true);
01657         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
01658                                    new DataListener("ON_BUFFER_FULL"), true);
01659         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
01660                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
01661         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
01662                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
01663         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
01664                                    new DataListener("ON_BUFFER_READ"), true);
01665         m_listeners.connectorData_[RTC::ON_SEND].addListener(
01666                                    new DataListener("ON_SEND"), true);
01667         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
01668                                    new DataListener("ON_RECEIVED"), true);
01669         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
01670                                    new DataListener("ON_RECEIVER_FULL"), true);
01671         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
01672                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
01673         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
01674                                    new DataListener("ON_RECEIVER_ERROR"), true);
01675 
01676         // setListener
01677         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
01678                              publisher.setListener(info, 0));
01679         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
01680                              publisher.setListener(info, &m_listeners));
01681 
01682         publisher.setConsumer(consumer);
01683         publisher.setBuffer(buffer);
01684         publisher.activate();
01685 
01686         //8件のデータは転送されない
01687         //最新データの7は転送される。
01688         for(int icc(0);icc<8;++icc)
01689         {
01690             cdrMemoryStream cdr;
01691             RTC::TimedLong td;
01692             td.data = icc;
01693             td >>= cdr;
01694 
01695             CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01696                                  publisher.write(cdr,0,0));
01697 
01698         }
01699 
01700   
01701         coil::usleep(150000);
01702         //provider 側のバッファから取得
01703         //
01704         int len = consumer->get_m_put_data_len() -1;
01705         for(int icc(0);icc<len;++icc)
01706         {
01707             cdrMemoryStream data;
01708             data = consumer->get_m_put_data();
01709             CORBA::ULong inlen = data.bufSize();
01710             CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01711         }
01712         coil::usleep(150000);
01713         //最新データが転送されていることを確認する。
01714         {
01715         cdrMemoryStream data;
01716         data = consumer->get_m_put_data();
01717         CORBA::ULong inlen = data.bufSize();
01718         CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
01719 
01720         RTC::TimedLong rtd;
01721         rtd <<= data;
01722         CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data);
01723         }
01724 
01725         coil::usleep(100000);
01726         publisher.deactivate();
01727         delete buffer;
01728         delete consumer;
01729     }
01735     void test_write(void)
01736     {
01737         InPortCorbaCdrConsumerMock* consumer 
01738                                     = new InPortCorbaCdrConsumerMock();
01739         RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
01740         PublisherPeriodicMock publisher;
01741 
01742         coil::Properties prop;
01743         prop.setProperty("publisher.push_policy","all");
01744         prop.setProperty("publisher.skip_count","0");
01745         prop.setProperty("thread_type","default");
01746         prop.setProperty("measurement.exec_time","enable");
01747         prop.setProperty("measurement.exec_count","0");
01748         prop.setProperty("measurement.period_time","enable");
01749         prop.setProperty("measurement.period_count","0");
01750         prop.setProperty("publisher.push_rate","10");
01751         publisher.init(prop);
01752         coil::usleep(10000);
01753 
01754         //ConnectorInfo
01755         coil::vstring ports;
01756         RTC::ConnectorInfo info("name", "id", ports, prop);
01757 
01758         //ConnectorListeners
01759         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener(
01760                                    new DataListener("ON_BUFFER_WRITE"), true);
01761         m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener(
01762                                    new DataListener("ON_BUFFER_FULL"), true);
01763         m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener(
01764                                    new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
01765         m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener(
01766                                    new DataListener("ON_BUFFER_OVERWRITE"), true);
01767         m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener(
01768                                    new DataListener("ON_BUFFER_READ"), true);
01769         m_listeners.connectorData_[RTC::ON_SEND].addListener(
01770                                    new DataListener("ON_SEND"), true);
01771         m_listeners.connectorData_[RTC::ON_RECEIVED].addListener(
01772                                    new DataListener("ON_RECEIVED"), true);
01773         m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener(
01774                                    new DataListener("ON_RECEIVER_FULL"), true);
01775         m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener(
01776                                    new DataListener("ON_RECEIVER_TIMEOUT"), true);
01777         m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener(
01778                                    new DataListener("ON_RECEIVER_ERROR"), true);
01779 
01780         // setListener
01781         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, 
01782                              publisher.setListener(info, 0));
01783         CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, 
01784                              publisher.setListener(info, &m_listeners));
01785 
01786         //
01787         {
01788         cdrMemoryStream cdr;
01789         RTC::TimedLong td;
01790         td.data = 123;
01791         td >>= cdr;
01792         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
01793                                  publisher.write(cdr,0,0));
01794         coil::usleep(100000);
01795         }
01796 
01797         //
01798         publisher.setBuffer(buffer);
01799         {
01800         cdrMemoryStream cdr;
01801         RTC::TimedLong td;
01802         td.data = 123;
01803         td >>= cdr;
01804         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
01805                                  publisher.write(cdr,0,0));
01806         coil::usleep(100000);
01807         }
01808 
01809         //
01810         publisher.setConsumer(consumer);
01811         {
01812         cdrMemoryStream cdr;
01813         RTC::TimedLong td;
01814         td.data = 123;
01815         td >>= cdr;
01816         CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
01817                                  publisher.write(cdr,0,0));
01818         coil::usleep(100000);
01819         }
01820 
01821         //Listener callback check
01822         cdrMemoryStream cdr;
01823         RTC::TimedLong td;
01824         td.data = 777;
01825         td >>= cdr;
01826         //m_OnCheck = 1;  // PORT_OK:onReceived()
01827         //publisher.write(cdr,0,0);
01828         //coil::usleep(10000);
01829         m_OnCheck = 2;  // PORT_ERROR:onReceiverError()
01830         publisher.write(cdr,0,0);
01831         coil::usleep(10000);
01832         m_OnCheck = 3;  // SEND_FULL:onReceiverFull()
01833         publisher.write(cdr,0,0);
01834         coil::usleep(100000);
01835         m_OnCheck = 4;  // SEND_TIMEOUT:onReceiverTimeout()
01836         publisher.write(cdr,0,0);
01837         coil::usleep(100000);
01838         m_OnCheck = 5;  // UNKNOWN_ERROR:onReceiverError()
01839         publisher.write(cdr,0,0);
01840         coil::usleep(100000);
01841         m_OnCheck = 6;  // CONNECTION_LOST:onReceiverError()
01842         publisher.write(cdr,0,0);
01843         coil::usleep(100000);
01844 
01845         delete buffer;
01846         delete consumer;
01847     }
01853 /*
01854     void test_destructor()
01855     {
01856       CounterConsumer* consumer1 = new CounterConsumer();
01857 
01858       { // Publisherのインスタンススコープ開始
01859         CounterConsumer* consumer2 = new CounterConsumer(consumer1);
01860         coil::Properties prop;
01861         prop.setProperty("dataport.push_rate", "10"); // 10 [Hz]
01862         RTC::PublisherPeriodic publisher(consumer2, prop);
01863         // 5 [sec]だけ動作させる
01864         coil::usleep(5000000);
01865                                 
01866       } // デストラクタを呼び出す(スコープを終了させる)
01867                         
01868       coil::usleep(1000000); // 完全停止するまで待つ
01869                         
01870       // この時点での呼出回数を記録する
01871       int countReleased = consumer1->getCount();
01872                         
01873       // さらにConsumerがコールバックされ得る時間を与える
01874       coil::usleep(5000000); // 5 [sec]
01875                         
01876       // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない
01877       // (つまり、Publisherの動作が停止している)ことを確認する
01878       int countSleeped = consumer1->getCount();
01879       CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped);
01880     }
01881 */
01882                 
01888 /*
01889     void test_release()
01890     {
01891       CounterConsumer* consumer = new CounterConsumer();
01892       coil::Properties prop;
01893       prop.setProperty("dataport.push_rate", "10"); // 10 [Hz]
01894       RTC::PublisherPeriodic publisher(consumer, prop);
01895                         
01896       // 5 [sec]だけ動作させる
01897       coil::usleep(5000000);
01898                         
01899       // Publisherの動作を停止させる
01900       publisher.release();
01901       coil::usleep(1000000); // 完全停止するまで待つ
01902                         
01903       // この時点での呼出回数を記録する
01904       int countReleased = consumer->getCount();
01905                         
01906       // さらにConsumerがコールバックされ得る時間を与える
01907       coil::usleep(5000000); // 5 [sec]
01908                         
01909       // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない
01910       // (つまり、Publisherの動作が停止している)ことを確認する
01911       int countSleeped = consumer->getCount();
01912       CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped);
01913     }
01914 */
01915                 
01921 /*
01922     void test_interval_accuracy()
01923     {
01924       MockConsumer* consumer = new MockConsumer();
01925       coil::Properties prop;
01926       prop.setProperty("dataport.push_rate", "10"); // 10 [Hz]
01927       RTC::PublisherPeriodic publisher(consumer, prop);
01928                         
01929       // 5 [sec]だけ動作させる
01930       coil::usleep(5000000);
01931                         
01932       // Publisherの動作を停止させる
01933       publisher.release();
01934       coil::usleep(1000000); // 完全停止するまで待つ
01935                         
01936       // 指定した時間間隔で正しくConsumerがコールバックされているか?
01937       long permissibleTickMin = static_cast<long>(100000 * 0.9);
01938       long permissibleTickMax = static_cast<long>(100000 * 1.1);
01939       const std::vector<long> intervalTicks = consumer->getIntervalTicks();
01940       CPPUNIT_ASSERT(intervalTicks.size() > 0);
01941 
01942       for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++)
01943         {
01944           long tick = intervalTicks[i];
01945           CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax));
01946         }
01947     }
01948 */
01949   };
01950 }; // namespace PublisherPeriodic
01951 
01952 /*
01953  * Register test suite
01954  */
01955 CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests);
01956 
01957 #ifdef LOCAL_MAIN
01958 int main(int argc, char* argv[])
01959 {
01960 
01961   FORMAT format = TEXT_OUT;
01962   int target = 0;
01963   std::string xsl;
01964   std::string ns;
01965   std::string fname;
01966   std::ofstream ofs;
01967 
01968   int i(1);
01969   while (i < argc)
01970     {
01971       std::string arg(argv[i]);
01972       std::string next_arg;
01973       if (i + 1 < argc) next_arg = argv[i + 1];
01974       else              next_arg = "";
01975 
01976       if (arg == "--text") { format = TEXT_OUT; break; }
01977       if (arg == "--xml")
01978         {
01979           if (next_arg == "")
01980             {
01981               fname = argv[0];
01982               fname += ".xml";
01983             }
01984           else
01985             {
01986               fname = next_arg;
01987             }
01988           format = XML_OUT;
01989           ofs.open(fname.c_str());
01990         }
01991       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
01992       if ( arg == "--cerr"      ) { target = 1; break; }
01993       if ( arg == "--xsl"       )
01994         {
01995           if (next_arg == "") xsl = "default.xsl"; 
01996           else                xsl = next_arg;
01997         }
01998       if ( arg == "--namespace" )
01999         {
02000           if (next_arg == "")
02001             {
02002               std::cerr << "no namespace specified" << std::endl;
02003               exit(1); 
02004             }
02005           else
02006             {
02007               xsl = next_arg;
02008             }
02009         }
02010       ++i;
02011     }
02012   CppUnit::TextUi::TestRunner runner;
02013   if ( ns.empty() )
02014     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
02015   else
02016     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
02017   CppUnit::Outputter* outputter = 0;
02018   std::ostream* stream = target ? &std::cerr : &std::cout;
02019   switch ( format )
02020     {
02021     case TEXT_OUT :
02022       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
02023       break;
02024     case XML_OUT :
02025       std::cout << "XML_OUT" << std::endl;
02026       outputter = new CppUnit::XmlOutputter(&runner.result(),
02027                                             ofs, "shift_jis");
02028       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
02029       break;
02030     case COMPILER_OUT :
02031       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
02032       break;
02033     }
02034   runner.setOutputter(outputter);
02035   runner.run();
02036   return 0; // runner.run() ? 0 : 1;
02037 }
02038 #endif // MAIN
02039 #endif // PublisherPeriodic_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:38