PublisherPeriodicTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: PublisherPeriodicTests.cpp,v $
14  * Revision 1.2 2008/01/28 13:52:19 arafune
15  * Some tests were added.
16  *
17  * Revision 1.1 2007/12/20 07:50:17 arafune
18  * *** empty log message ***
19  *
20  * Revision 1.2 2007/01/12 14:54:45 n-ando
21  * The constructor's signature was changed.
22  * InPortConsumer base class is now abstruct class. It needs concrete class.
23  *
24  * Revision 1.1 2006/12/18 06:51:55 n-ando
25  * The first commitment.
26  *
27  *
28  */
29 
30 #ifndef PublisherPeriodic_cpp
31 #define PublisherPeriodic_cpp
32 
33 #include <cppunit/ui/text/TestRunner.h>
34 #include <cppunit/TextOutputter.h>
35 #include <cppunit/extensions/TestFactoryRegistry.h>
36 #include <cppunit/extensions/HelperMacros.h>
37 #include <cppunit/TestAssert.h>
38 
39 #include <iostream>
40 #include <coil/Properties.h>
41 #include <coil/Time.h>
42 #include <rtm/InPortConsumer.h>
44 #include <rtm/PublisherPeriodic.h>
45 #include <rtm/CdrRingBuffer.h>
46 #include <rtm/idl/ManagerSkel.h>
47 
48 #include <rtm/idl/BasicDataTypeSkel.h>
49 #include <rtm/ConnectorListener.h>
50 
56 {
57  int m_OnCheck = 0;
58 
63  : public RTC::ConnectorDataListenerT<RTC::TimedLong>
64  {
65  public:
66  DataListener(const char* name) : m_name(name) {}
67  virtual ~DataListener()
68  {
69  }
70 
71  virtual void operator()(const RTC::ConnectorInfo& info,
72  const RTC::TimedLong& data)
73  {
74  std::cout << "------------------------------" << std::endl;
75  std::cout << "Listener: " << m_name << std::endl;
76  std::cout << " Data: " << data.data << std::endl;
77  std::cout << "------------------------------" << std::endl;
78  };
79  std::string m_name;
80  };
81 
87  : public RTC::PublisherPeriodic
88  {
89  public:
91  {
92  ;
93  }
94  virtual ~PublisherPeriodicMock(void)
95  {
96  ;
97  }
98  };
105  {
106  public:
112  {
113  m_buffer = new RTC::CdrRingBuffer();
114  m_test_mode = 0;
115  }
121  {
122  delete m_buffer;
123  }
128  virtual ReturnCode put(const cdrMemoryStream& data)
129  {
130  if(m_test_mode == 0)
131  {
132  if (m_buffer->full())
133  {
135  }
136 
137  RTC::BufferStatus::Enum ret = m_buffer->write(data);
138 
139  //Listener check
140  if(m_OnCheck == 0) {
141  switch(ret)
142  {
145  break;
148  break;
151  break;
154  break;
157  break;
158  default:
160  }
162  }
163  else if(m_OnCheck == 1) {
165  }
166  else if(m_OnCheck == 2) {
168  }
169  else if(m_OnCheck == 3) {
171  }
172  else if(m_OnCheck == 4) {
174  }
175  else if(m_OnCheck == 5) {
177  }
178  else if(m_OnCheck == 6) {
180  }
181  }
182  else if(m_test_mode == 1)
183  {
184  std::string str("test");
185  throw str;
186  }
187  else
188  {
189  }
190  }
195  cdrMemoryStream get_m_put_data(void)
196  {
197  cdrMemoryStream cdr;
198  m_buffer->read(cdr);
199 
200  return cdr;
201  }
207  {
208  int ic;
209  ic = (int)m_buffer->readable();
210 
211  return ic;
212  }
213 
218  void set_m_mode(int mode)
219  {
220  m_test_mode = mode;
221  }
222  private:
224  ::OpenRTM::CdrData m_put_data;
226  };
228  {
229  public:
230 
231  MockConsumer() : RTC::InPortConsumer()
232  {
233  clearLastTime();
234  }
235 
236  virtual ~MockConsumer() {}
237 
238  virtual void push()
239  {
240  timeval now;
241  coil::gettimeofday(&now, NULL);
242 
243  if (! isLastTimeCleared())
244  {
245  long interval =
246  (now.tv_sec - _lastTime.tv_sec) * 1000000
247  + (now.tv_usec - _lastTime.tv_usec);
248 
249  _intervalTicks.push_back(interval);
250  }
251 
252  _lastTime = now;
253  }
254 
255  virtual RTC::InPortConsumer* clone() const
256  {
257  MockConsumer* clone = new MockConsumer();
258  copy(_intervalTicks.begin(), _intervalTicks.end(), clone->_intervalTicks.begin());
259  clone->_lastTime = _lastTime;
260 
261  return clone;
262  }
263 
265  {
266  return true;
267  }
268 
270  {
271  return;
272  }
273 
274  virtual const std::vector<long>& getIntervalTicks() const
275  {
276  return _intervalTicks;
277  }
278 
279  virtual int getCount() const
280  {
281  return static_cast<int>(_intervalTicks.size());
282  }
283 
284  virtual void init(coil::Properties& prop)
285  {
286  }
287  virtual InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
288  {
289  return (InPortConsumer::ReturnCode)0 ;
290  }
291  virtual void publishInterfaceProfile(SDOPackage::NVList& properties)
292  {
293  }
294  private:
295 
296  std::vector<long> _intervalTicks;
297  timeval _lastTime;
298 
299  private:
300 
302  {
303  _lastTime.tv_sec = 0;
304  _lastTime.tv_usec = 0;
305  }
306 
308  {
309  return (_lastTime.tv_sec == 0) && (_lastTime.tv_usec == 0);
310  }
311  };
312 
314  {
315  public:
316 
317  CounterConsumer(CounterConsumer* component = NULL)
318  : RTC::InPortConsumer(), _count(0), _component(component) {}
319 
320  virtual ~CounterConsumer() {}
321 
322  virtual void push()
323  {
324  _count++;
325 
326  if (_component != NULL)
327  {
328  _component->push();
329  }
330  }
331 
332  virtual RTC::InPortConsumer* clone() const
333  {
334  CounterConsumer* clone = new CounterConsumer();
335  clone->_count = _count;
336  clone->_component = _component;
337  return clone;
338  }
339 
341  {
342  return true;
343  }
344 
346  {
347  return;
348  }
349 
350  virtual int getCount() const
351  {
352  return _count;
353  }
354 
355  virtual void init(coil::Properties& prop)
356  {
357  }
358  virtual InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
359  {
360  return (InPortConsumer::ReturnCode)0 ;
361  }
362  virtual void publishInterfaceProfile(SDOPackage::NVList& properties)
363  {
364  }
365  private:
366 
367  int _count;
369  };
370 
372  : public CppUnit::TestFixture
373  {
374  CPPUNIT_TEST_SUITE(PublisherPeriodicTests);
375 
376  //CPPUNIT_TEST(test_init); // OK
377  CPPUNIT_TEST(test_setConsumer);
378  CPPUNIT_TEST(test_setBuffer);
379  //CPPUNIT_TEST(test_activate_deactivate_isActive); // OK
380  CPPUNIT_TEST(test_pushAll);
381  CPPUNIT_TEST(test_pushAll_2);
382  CPPUNIT_TEST(test_pushFifo);
383  CPPUNIT_TEST(test_pushFifo_2);
384  CPPUNIT_TEST(test_pushSkip);
385  CPPUNIT_TEST(test_pushSkip_2);
386  CPPUNIT_TEST(test_pushNew);
387  CPPUNIT_TEST(test_write);
388 
389  CPPUNIT_TEST_SUITE_END();
390 
391  public:
393 
398  {
399  }
400 
405  {
406  }
407 
411  virtual void setUp()
412  {
413 // coil::usleep(1000000);
414  }
415 
419  virtual void tearDown()
420  {
421  }
422 
427  void test_init(void)
428  {
429 
430  PublisherPeriodicMock publisher;
433 
434  //Propertiesが空の状態ではエラーになることを確認する retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode); prop.setProperty("publisher.push_policy","new"); prop.setProperty("thread_type","bar"); prop.setProperty("measurement.exec_time","default"); prop.setProperty("measurement.period_count","1"); prop.setProperty("publisher.push_rate","10.0"); //thread_type が不正の場合 INVALID_ARGS を返すことを確認する。 retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode); //以下のpropertiesの設定で動作することを確認する。 prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode); prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","disable"); prop.setProperty("measurement.exec_count","1"); prop.setProperty("measurement.period_time","disable"); prop.setProperty("measurement.period_count","1"); prop.setProperty("publisher.push_rate","20"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode); prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","-1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","bar"); prop.setProperty("measurement.exec_count","-1"); prop.setProperty("measurement.period_time","bar"); prop.setProperty("measurement.period_count","-1"); prop.setProperty("publisher.push_rate","10"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode); prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","foo"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","foo"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","foo"); prop.setProperty("publisher.push_rate","10"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode); prop.setProperty("publisher.push_policy","bar"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode); prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","0"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode); prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","-1"); retcode = publisher.init(prop); //coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode); } /*! * @brief setConsumer()メソッドのテスト * */ void test_setConsumer(void) { RTC::InPortCorbaCdrConsumer* consumer0 = new RTC::InPortCorbaCdrConsumer(); RTC::InPortCorbaCdrConsumer* consumer1 = new RTC::InPortCorbaCdrConsumer(); RTC::PublisherPeriodic publisher; //NULLを渡した場合INVALID_ARGSとなることを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, publisher.setConsumer(NULL)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.setConsumer(consumer0)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.setConsumer(consumer1)); delete consumer1; delete consumer0; } /*! * @brief setBuffer()メソッドのテスト * */ void test_setBuffer(void) { RTC::CdrBufferBase* buffer0 = new RTC::CdrRingBuffer(); RTC::CdrBufferBase* buffer1 = new RTC::CdrRingBuffer(); RTC::PublisherPeriodic publisher; //NULLを渡した場合INVALID_ARGSとなることを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, publisher.setBuffer(NULL)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.setBuffer(buffer0)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.setBuffer(buffer1)); delete buffer1; delete buffer0; } /*! * @brief activate(),deactivate(),isActiveメソッドのテスト * */ void test_activate_deactivate_isActive(void) { RTC::InPortCorbaCdrConsumer* consumer = new RTC::InPortCorbaCdrConsumer(); RTC::PublisherPeriodic publisher; publisher.setConsumer(consumer); //init() せずに activate() をコールした場合をi //PRECONDITION_NOT_MET 返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.activate()); //init() せずに deactivate() をコールした場合をi //PRECONDITION_NOT_MET 返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.deactivate()); //init() coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","20"); publisher.init(prop); coil::usleep(10000); //setBuffer() せずに activate() をコールした場合をi //PRECONDITION_NOT_MET 返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.activate()); //setBuffer() RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); publisher.setBuffer(buffer); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.activate()); CPPUNIT_ASSERT_EQUAL(true, publisher.isActive()); //既に activate されている場合は //activateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.activate()); CPPUNIT_ASSERT_EQUAL(true, publisher.isActive()); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); //activate されていない状態で、 //deactivateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * -provider 側のバッファ full 状態でもデータ抜けががないことを確認する。 */ void test_pushAll(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(150000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(300000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data); } coil::usleep(150000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(220000); //Waits to complete writing 8 and 9. //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
435  retcode = publisher.init(prop);
436  //coil::usleep(10000);
437  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode);
438 
439  prop.setProperty("publisher.push_policy","new");
440  prop.setProperty("thread_type","bar");
441  prop.setProperty("measurement.exec_time","default");
442  prop.setProperty("measurement.period_count","1");
443  prop.setProperty("publisher.push_rate","10.0");
444 
445  //thread_type が不正の場合 INVALID_ARGS を返すことを確認する。
446  retcode = publisher.init(prop);
447  //coil::usleep(10000);
448  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
449 
450  //以下のpropertiesの設定で動作することを確認する。
451  prop.setProperty("publisher.push_policy","all");
452  prop.setProperty("publisher.skip_count","0");
453  prop.setProperty("thread_type","default");
454  prop.setProperty("measurement.exec_time","enable");
455  prop.setProperty("measurement.exec_count","0");
456  prop.setProperty("measurement.period_time","enable");
457  prop.setProperty("measurement.period_count","0");
458  prop.setProperty("publisher.push_rate","10");
459  retcode = publisher.init(prop);
460  //coil::usleep(10000);
461  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
462 
463  prop.setProperty("publisher.push_policy","fifo");
464  prop.setProperty("publisher.skip_count","1");
465  prop.setProperty("thread_type","default");
466  prop.setProperty("measurement.exec_time","disable");
467  prop.setProperty("measurement.exec_count","1");
468  prop.setProperty("measurement.period_time","disable");
469  prop.setProperty("measurement.period_count","1");
470  prop.setProperty("publisher.push_rate","20");
471  retcode = publisher.init(prop);
472  //coil::usleep(10000);
473  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
474 
475  prop.setProperty("publisher.push_policy","skip");
476  prop.setProperty("publisher.skip_count","-1");
477  prop.setProperty("thread_type","default");
478  prop.setProperty("measurement.exec_time","bar");
479  prop.setProperty("measurement.exec_count","-1");
480  prop.setProperty("measurement.period_time","bar");
481  prop.setProperty("measurement.period_count","-1");
482  prop.setProperty("publisher.push_rate","10");
483  retcode = publisher.init(prop);
484  //coil::usleep(10000);
485  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
486 
487  prop.setProperty("publisher.push_policy","new");
488  prop.setProperty("publisher.skip_count","foo");
489  prop.setProperty("thread_type","default");
490  prop.setProperty("measurement.exec_time","enable");
491  prop.setProperty("measurement.exec_count","foo");
492  prop.setProperty("measurement.period_time","enable");
493  prop.setProperty("measurement.period_count","foo");
494  prop.setProperty("publisher.push_rate","10");
495  retcode = publisher.init(prop);
496  //coil::usleep(10000);
497  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
498 
499  prop.setProperty("publisher.push_policy","bar");
500  prop.setProperty("publisher.skip_count","0");
501  prop.setProperty("thread_type","default");
502  prop.setProperty("measurement.exec_time","enable");
503  prop.setProperty("measurement.exec_count","0");
504  prop.setProperty("measurement.period_time","enable");
505  prop.setProperty("measurement.period_count","0");
506  prop.setProperty("publisher.push_rate","10");
507  retcode = publisher.init(prop);
508  //coil::usleep(10000);
509  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, retcode);
510 
511  prop.setProperty("publisher.push_policy","all");
512  prop.setProperty("publisher.skip_count","0");
513  prop.setProperty("thread_type","default");
514  prop.setProperty("measurement.exec_time","enable");
515  prop.setProperty("measurement.exec_count","0");
516  prop.setProperty("measurement.period_time","enable");
517  prop.setProperty("measurement.period_count","0");
518  prop.setProperty("publisher.push_rate","0");
519  retcode = publisher.init(prop);
520  //coil::usleep(10000);
521  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode);
522 
523  prop.setProperty("publisher.push_policy","all");
524  prop.setProperty("publisher.skip_count","0");
525  prop.setProperty("thread_type","default");
526  prop.setProperty("measurement.exec_time","enable");
527  prop.setProperty("measurement.exec_count","0");
528  prop.setProperty("measurement.period_time","enable");
529  prop.setProperty("measurement.period_count","0");
530  prop.setProperty("publisher.push_rate","-1");
531  retcode = publisher.init(prop);
532  //coil::usleep(10000);
533  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS, retcode);
534 
535  }
540  void test_setConsumer(void)
541  {
542  RTC::InPortCorbaCdrConsumer* consumer0
544  RTC::InPortCorbaCdrConsumer* consumer1
546  RTC::PublisherPeriodic publisher;
547 
548  //NULLを渡した場合INVALID_ARGSとなることを確認する。
549  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS,
550  publisher.setConsumer(NULL));
551 
552  //
553  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
554  publisher.setConsumer(consumer0));
555 
556  //
557  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
558  publisher.setConsumer(consumer1));
559 
560  delete consumer1;
561  delete consumer0;
562  }
567  void test_setBuffer(void)
568  {
569  RTC::CdrBufferBase* buffer0 = new RTC::CdrRingBuffer();
570  RTC::CdrBufferBase* buffer1 = new RTC::CdrRingBuffer();
571  RTC::PublisherPeriodic publisher;
572 
573  //NULLを渡した場合INVALID_ARGSとなることを確認する。
574  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::INVALID_ARGS,
575  publisher.setBuffer(NULL));
576 
577  //
578  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
579  publisher.setBuffer(buffer0));
580 
581  //
582  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
583  publisher.setBuffer(buffer1));
584 
585  delete buffer1;
586  delete buffer0;
587  }
593  {
594  RTC::InPortCorbaCdrConsumer* consumer
596  RTC::PublisherPeriodic publisher;
597  publisher.setConsumer(consumer);
598 
599  //init() せずに activate() をコールした場合をi
600  //PRECONDITION_NOT_MET 返すことを確認する。
601  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
602  publisher.activate());
603 
604  //init() せずに deactivate() をコールした場合をi
605  //PRECONDITION_NOT_MET 返すことを確認する。
606  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
607  publisher.deactivate());
608 
609  //init()
611  prop.setProperty("publisher.push_policy","all");
612  prop.setProperty("publisher.skip_count","0");
613  prop.setProperty("thread_type","default");
614  prop.setProperty("measurement.exec_time","enable");
615  prop.setProperty("measurement.exec_count","0");
616  prop.setProperty("measurement.period_time","enable");
617  prop.setProperty("measurement.period_count","0");
618  prop.setProperty("publisher.push_rate","20");
619  publisher.init(prop);
620  coil::usleep(10000);
621 
622 
623  //setBuffer() せずに activate() をコールした場合をi
624  //PRECONDITION_NOT_MET 返すことを確認する。
625  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
626  publisher.activate());
627 
628  //setBuffer()
629  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
630  publisher.setBuffer(buffer);
631 
632 
633  CPPUNIT_ASSERT_EQUAL(false,
634  publisher.isActive());
635 
636  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
637  publisher.activate());
638 
639  CPPUNIT_ASSERT_EQUAL(true,
640  publisher.isActive());
641 
642  //既に activate されている場合は
643  //activateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.activate()); CPPUNIT_ASSERT_EQUAL(true, publisher.isActive()); CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); //activate されていない状態で、 //deactivateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * -provider 側のバッファ full 状態でもデータ抜けががないことを確認する。 */ void test_pushAll(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(150000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(300000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data); } coil::usleep(150000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(220000); //Waits to complete writing 8 and 9. //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
644  //PORT_OK を返すことを確認する。
645  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
646  publisher.activate());
647 
648  CPPUNIT_ASSERT_EQUAL(true,
649  publisher.isActive());
650 
651  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
652  publisher.deactivate());
653 
654  CPPUNIT_ASSERT_EQUAL(false,
655  publisher.isActive());
656 
657  //activate されていない状態で、
658  //deactivateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * -provider 側のバッファ full 状態でもデータ抜けががないことを確認する。 */ void test_pushAll(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(150000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(300000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data); } coil::usleep(150000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(220000); //Waits to complete writing 8 and 9. //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
659  //PORT_OK を返すことを確認する。
660  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
661  publisher.deactivate());
662 
663  CPPUNIT_ASSERT_EQUAL(false,
664  publisher.isActive());
665 
666  delete buffer;
667  delete consumer;
668  }
674  void test_pushAll(void)
675  {
676  InPortCorbaCdrConsumerMock* consumer
678  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
679  PublisherPeriodicMock publisher;
680 
682  prop.setProperty("publisher.push_policy","all");
683  prop.setProperty("publisher.skip_count","0");
684  prop.setProperty("thread_type","default");
685  prop.setProperty("measurement.exec_time","enable");
686  prop.setProperty("measurement.exec_count","0");
687  prop.setProperty("measurement.period_time","enable");
688  prop.setProperty("measurement.period_count","0");
689  prop.setProperty("publisher.push_rate","10");
690  publisher.init(prop);
691  coil::usleep(10000);
692 
693  //ConnectorInfo
694  coil::vstring ports;
695  RTC::ConnectorInfo info("name", "id", ports, prop);
696 
697  //ConnectorListeners
699  new DataListener("ON_BUFFER_WRITE"), true);
701  new DataListener("ON_BUFFER_FULL"), true);
703  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
705  new DataListener("ON_BUFFER_OVERWRITE"), true);
707  new DataListener("ON_BUFFER_READ"), true);
709  new DataListener("ON_SEND"), true);
711  new DataListener("ON_RECEIVED"), true);
713  new DataListener("ON_RECEIVER_FULL"), true);
715  new DataListener("ON_RECEIVER_TIMEOUT"), true);
717  new DataListener("ON_RECEIVER_ERROR"), true);
718 
719  // setListener
720  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
721  publisher.setListener(info, 0));
722  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
723  publisher.setListener(info, &m_listeners));
724 
725  publisher.setConsumer(consumer);
726  publisher.setBuffer(buffer);
727  publisher.activate();
728 
729  for(int icc(0);icc<8;++icc)
730  {
731  cdrMemoryStream cdr;
732  RTC::TimedLong td;
733  td.data = icc;
734  td >>= cdr;
735 
736  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
737  publisher.write(cdr,0,0));
738 
739  }
740 
741  coil::usleep(150000);
742  //provider 側のバッファ full の状態でコール(full)
743  {
744  cdrMemoryStream cdr;
745  RTC::TimedLong td;
746  td.data = 8;
747  td >>= cdr;
748  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
749  publisher.write(cdr,0,0));
750  coil::usleep(150000);
751  }
752  {
753  cdrMemoryStream cdr;
754  RTC::TimedLong td;
755  td.data = 9;
756  td >>= cdr;
757  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
758  publisher.write(cdr,0,0));
759  coil::usleep(150000);
760  }
761 
762  //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(150000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(300000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data); } coil::usleep(150000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(220000); //Waits to complete writing 8 and 9. //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
763  //(full ではない状態にする )
764  for(int icc(0);icc<4;++icc)
765  {
766  cdrMemoryStream data;
767  data = consumer->get_m_put_data();
768  CORBA::ULong inlen = data.bufSize();
769  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
770 
771  RTC::TimedLong rtd;
772  rtd <<= data;
773  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
774  }
775 
776  coil::usleep(150000);
777  //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(300000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data); } coil::usleep(150000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(220000); //Waits to complete writing 8 and 9. //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
778  {
779  cdrMemoryStream cdr;
780  RTC::TimedLong td;
781  td.data = 10;
782  td >>= cdr;
783  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
784  publisher.write(cdr,0,0));
785  coil::usleep(150000);
786  }
787  {
788  cdrMemoryStream cdr;
789  RTC::TimedLong td;
790  td.data = 11;
791  td >>= cdr;
792  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
793  publisher.write(cdr,0,0));
794  coil::usleep(150000);
795  }
796 
797  //データ抜けががないことを確認する。
798  for(int icc(0);icc<8;++icc)
799  {
800  cdrMemoryStream data;
801  data = consumer->get_m_put_data();
802  CORBA::ULong inlen = data.bufSize();
803  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
804 
805  RTC::TimedLong rtd;
806  rtd <<= data;
807  CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data);
808  }
809  publisher.deactivate();
810 
811  delete buffer;
812  delete consumer;
813 
814  }
820  void test_pushAll_2(void)
821  {
822  InPortCorbaCdrConsumerMock* consumer
824  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
825  PublisherPeriodicMock publisher;
826 
828  prop.setProperty("publisher.push_policy","all");
829  prop.setProperty("publisher.skip_count","0");
830  prop.setProperty("thread_type","default");
831  prop.setProperty("measurement.exec_time","enable");
832  prop.setProperty("measurement.exec_count","0");
833  prop.setProperty("measurement.period_time","enable");
834  prop.setProperty("measurement.period_count","0");
835  prop.setProperty("publisher.push_rate","10");
836  publisher.init(prop);
837  coil::usleep(10000);
838 
839  //ConnectorInfo
840  coil::vstring ports;
841  RTC::ConnectorInfo info("name", "id", ports, prop);
842 
843  //ConnectorListeners
845  new DataListener("ON_BUFFER_WRITE"), true);
847  new DataListener("ON_BUFFER_FULL"), true);
849  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
851  new DataListener("ON_BUFFER_OVERWRITE"), true);
853  new DataListener("ON_BUFFER_READ"), true);
855  new DataListener("ON_SEND"), true);
857  new DataListener("ON_RECEIVED"), true);
859  new DataListener("ON_RECEIVER_FULL"), true);
861  new DataListener("ON_RECEIVER_TIMEOUT"), true);
863  new DataListener("ON_RECEIVER_ERROR"), true);
864 
865  // setListener
866  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
867  publisher.setListener(info, 0));
868  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
869  publisher.setListener(info, &m_listeners));
870 
871  publisher.setConsumer(consumer);
872  publisher.setBuffer(buffer);
873  publisher.activate();
874 
875  for(int icc(0);icc<16;++icc)
876  {
877  cdrMemoryStream cdr;
878  RTC::TimedLong td;
879  td.data = icc;
880  td >>= cdr;
881 
883  ret = publisher.write(cdr,0,0);
884  if(icc<9)
885  {
886  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
887  ret);
888  }
889  else
890  {
891  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
892  ret);
893  }
894  coil::usleep(150000);
895 
896  }
897 
898  //consumer と provider 両方の buffer が full 状態のため、
899  // この write データは抜ける。
900  {
901  cdrMemoryStream cdr;
902  RTC::TimedLong td;
903  td.data = 16;
904  td >>= cdr;
905  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
906  publisher.write(cdr,0,0));
907  coil::usleep(150000);
908  }
909 
910  //データを確認する。
911  for(int icc(0);icc<8;++icc)
912  {
913  cdrMemoryStream data;
914  data = consumer->get_m_put_data();
915  CORBA::ULong inlen = data.bufSize();
916  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
917 
918  RTC::TimedLong rtd;
919  rtd <<= data;
920  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
921  }
922 
923  coil::usleep(300000);
924  //データを確認する。
925  for(int icc(0);icc<8;++icc)
926  {
927  cdrMemoryStream data;
928  data = consumer->get_m_put_data();
929  CORBA::ULong inlen = data.bufSize();
930  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
931 
932  RTC::TimedLong rtd;
933  rtd <<= data;
934  CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data);
935  }
936  {
937  cdrMemoryStream cdr;
938  RTC::TimedLong td;
939  td.data = 17;
940  td >>= cdr;
941  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
942  publisher.write(cdr,0,0));
943  coil::usleep(150000);
944  }
945  //データを確認する。
946  {
947  cdrMemoryStream data;
948  data = consumer->get_m_put_data();
949  CORBA::ULong inlen = data.bufSize();
950  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
951 
952  RTC::TimedLong rtd;
953  rtd <<= data;
954  CPPUNIT_ASSERT_EQUAL((long)17, (long)rtd.data);
955  }
956 
957  coil::usleep(150000);
958  publisher.deactivate();
959 
960  delete buffer;
961  delete consumer;
962 
963  }
968  void test_pushFifo(void)
969  {
970  InPortCorbaCdrConsumerMock* consumer
972  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
973  PublisherPeriodicMock publisher;
974 
976  prop.setProperty("publisher.push_policy","fifo");
977  prop.setProperty("publisher.skip_count","0");
978  prop.setProperty("thread_type","default");
979  prop.setProperty("measurement.exec_time","enable");
980  prop.setProperty("measurement.exec_count","0");
981  prop.setProperty("measurement.period_time","enable");
982  prop.setProperty("measurement.period_count","0");
983  prop.setProperty("publisher.push_rate","10");
984  publisher.init(prop);
985  coil::usleep(10000);
986 
987  //ConnectorInfo
988  coil::vstring ports;
989  RTC::ConnectorInfo info("name", "id", ports, prop);
990 
991  //ConnectorListeners
993  new DataListener("ON_BUFFER_WRITE"), true);
995  new DataListener("ON_BUFFER_FULL"), true);
997  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
999  new DataListener("ON_BUFFER_OVERWRITE"), true);
1001  new DataListener("ON_BUFFER_READ"), true);
1003  new DataListener("ON_SEND"), true);
1005  new DataListener("ON_RECEIVED"), true);
1007  new DataListener("ON_RECEIVER_FULL"), true);
1009  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1011  new DataListener("ON_RECEIVER_ERROR"), true);
1012 
1013  // setListener
1014  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1015  publisher.setListener(info, 0));
1016  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1017  publisher.setListener(info, &m_listeners));
1018 
1019  publisher.setConsumer(consumer);
1020  publisher.setBuffer(buffer);
1021  publisher.activate();
1022 
1023  for(int icc(0);icc<8;++icc)
1024  {
1025  cdrMemoryStream cdr;
1026  RTC::TimedLong td;
1027  td.data = icc;
1028  td >>= cdr;
1029 
1030  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1031  publisher.write(cdr,0,0));
1032 
1033  coil::usleep(150000);
1034  }
1035 
1036  //provider 側のバッファ full の状態でコール(full)
1037  {
1038  cdrMemoryStream cdr;
1039  RTC::TimedLong td;
1040  td.data = 8;
1041  td >>= cdr;
1042  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1043  publisher.write(cdr,0,0));
1044  coil::usleep(150000);
1045  }
1046  {
1047  cdrMemoryStream cdr;
1048  RTC::TimedLong td;
1049  td.data = 9;
1050  td >>= cdr;
1051  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1052  publisher.write(cdr,0,0));
1053  coil::usleep(150000);
1054  }
1055 
1056  //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(220000); //Waits to complete writing 8 and 9. //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1057  //(full ではない状態にする )
1058  for(int icc(0);icc<4;++icc)
1059  {
1060  cdrMemoryStream data;
1061  data = consumer->get_m_put_data();
1062  CORBA::ULong inlen = data.bufSize();
1063  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1064 
1065  RTC::TimedLong rtd;
1066  rtd <<= data;
1067  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
1068  }
1069  coil::usleep(220000); //Waits to complete writing 8 and 9.
1070 
1071  //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data); } coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded. for(int icc(0);icc<2;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","fifo"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1072  {
1073  cdrMemoryStream cdr;
1074  RTC::TimedLong td;
1075  td.data = 10;
1076  td >>= cdr;
1077  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1078  publisher.write(cdr,0,0));
1079  coil::usleep(150000);
1080  }
1081  {
1082  cdrMemoryStream cdr;
1083  RTC::TimedLong td;
1084  td.data = 11;
1085  td >>= cdr;
1086  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1087  publisher.write(cdr,0,0));
1088  coil::usleep(150000);
1089  }
1090  {
1091  cdrMemoryStream cdr;
1092  RTC::TimedLong td;
1093  td.data = 12;
1094  td >>= cdr;
1095  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1096  publisher.write(cdr,0,0));
1097  coil::usleep(150000);
1098  }
1099  {
1100  cdrMemoryStream cdr;
1101  RTC::TimedLong td;
1102  td.data = 13;
1103  td >>= cdr;
1104  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1105  publisher.write(cdr,0,0));
1106  coil::usleep(150000);
1107  }
1108 
1109  //データ抜けががないことを確認する。
1110  for(int icc(0);icc<8;++icc)
1111  {
1112  cdrMemoryStream data;
1113  data = consumer->get_m_put_data();
1114  CORBA::ULong inlen = data.bufSize();
1115  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1116 
1117  RTC::TimedLong rtd;
1118  rtd <<= data;
1119  CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data);
1120  }
1121  coil::usleep(400000); //Meanwhile, 12 and 13 are forwarded.
1122  for(int icc(0);icc<2;++icc)
1123  {
1124  cdrMemoryStream data;
1125  data = consumer->get_m_put_data();
1126  CORBA::ULong inlen = data.bufSize();
1127  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1128 
1129  RTC::TimedLong rtd;
1130  rtd <<= data;
1131  CPPUNIT_ASSERT_EQUAL((long)icc+12, (long)rtd.data);
1132  }
1133 
1134 
1135  coil::usleep(10000);
1136  publisher.deactivate();
1137  delete buffer;
1138  delete consumer;
1139 
1140  }
1146  void test_pushFifo_2(void)
1147  {
1148  InPortCorbaCdrConsumerMock* consumer
1150  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1151  PublisherPeriodicMock publisher;
1152 
1154  prop.setProperty("publisher.push_policy","fifo");
1155  prop.setProperty("publisher.skip_count","0");
1156  prop.setProperty("thread_type","default");
1157  prop.setProperty("measurement.exec_time","enable");
1158  prop.setProperty("measurement.exec_count","0");
1159  prop.setProperty("measurement.period_time","enable");
1160  prop.setProperty("measurement.period_count","0");
1161  prop.setProperty("publisher.push_rate","10");
1162  publisher.init(prop);
1163  coil::usleep(10000);
1164 
1165  //ConnectorInfo
1166  coil::vstring ports;
1167  RTC::ConnectorInfo info("name", "id", ports, prop);
1168 
1169  //ConnectorListeners
1171  new DataListener("ON_BUFFER_WRITE"), true);
1173  new DataListener("ON_BUFFER_FULL"), true);
1175  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1177  new DataListener("ON_BUFFER_OVERWRITE"), true);
1179  new DataListener("ON_BUFFER_READ"), true);
1181  new DataListener("ON_SEND"), true);
1183  new DataListener("ON_RECEIVED"), true);
1185  new DataListener("ON_RECEIVER_FULL"), true);
1187  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1189  new DataListener("ON_RECEIVER_ERROR"), true);
1190 
1191  // setListener
1192  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1193  publisher.setListener(info, 0));
1194  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1195  publisher.setListener(info, &m_listeners));
1196 
1197  publisher.setConsumer(consumer);
1198  publisher.setBuffer(buffer);
1199  publisher.activate();
1200 
1201  //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<9) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(100000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data); } coil::usleep(800000); // この write データは転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17+icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<1) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } //else //{ // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, // ret); //} coil::usleep(100000); } coil::usleep(80000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data); } coil::usleep(100000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, // publisher.write(cdr,0,0)); coil::usleep(100000); } coil::usleep(800000); //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); for(int icc(0);icc<16;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1202  for(int icc(0);icc<16;++icc)
1203  {
1204  cdrMemoryStream cdr;
1205  RTC::TimedLong td;
1206  td.data = icc;
1207  td >>= cdr;
1208 
1210  ret = publisher.write(cdr,0,0);
1211  if(icc<9)
1212  {
1213  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1214  ret);
1215  }
1216  else
1217  {
1218  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1219  ret);
1220  }
1221  coil::usleep(150000);
1222 
1223  }
1224 
1225  //consumer と provider 両方の buffer が full 状態のため、
1226  // この write データは抜ける。
1227  {
1228  cdrMemoryStream cdr;
1229  RTC::TimedLong td;
1230  td.data = 16;
1231  td >>= cdr;
1232  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1233  publisher.write(cdr,0,0));
1234  coil::usleep(100000);
1235  }
1236 
1237  //データを確認する。
1238  for(int icc(0);icc<8;++icc)
1239  {
1240  cdrMemoryStream data;
1241  data = consumer->get_m_put_data();
1242  CORBA::ULong inlen = data.bufSize();
1243  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1244 
1245  RTC::TimedLong rtd;
1246  rtd <<= data;
1247  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
1248  }
1249 
1250  coil::usleep(800000);
1251  // この write データは転送される。
1252  for(int icc(0);icc<8;++icc)
1253  {
1254  cdrMemoryStream cdr;
1255  RTC::TimedLong td;
1256  td.data = 17+icc;
1257  td >>= cdr;
1259  ret = publisher.write(cdr,0,0);
1260  if(icc<1)
1261  {
1262  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1263  ret);
1264  }
1265  //else
1266  //{
1267  // CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1268  // ret);
1269  //}
1270  coil::usleep(100000);
1271  }
1272  coil::usleep(80000);
1273  //データを確認する。
1274  for(int icc(0);icc<8;++icc)
1275  {
1276  cdrMemoryStream data;
1277  data = consumer->get_m_put_data();
1278  CORBA::ULong inlen = data.bufSize();
1279  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1280 
1281  RTC::TimedLong rtd;
1282  rtd <<= data;
1283  CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data);
1284  }
1285  coil::usleep(100000);
1286  {
1287  cdrMemoryStream cdr;
1288  RTC::TimedLong td;
1289  td.data = 25;
1290  td >>= cdr;
1291  //CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1292  // publisher.write(cdr,0,0));
1293  coil::usleep(100000);
1294  }
1295  coil::usleep(800000);
1296  //データを確認する。
1297  for(int icc(0);icc<8;++icc)
1298  {
1299  cdrMemoryStream data;
1300  data = consumer->get_m_put_data();
1301  CORBA::ULong inlen = data.bufSize();
1302  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1303 
1304  RTC::TimedLong rtd;
1305  rtd <<= data;
1306  CPPUNIT_ASSERT_EQUAL((long)icc+17, (long)rtd.data);
1307  }
1308 
1309 
1310  coil::usleep(100000);
1311  publisher.deactivate();
1312 
1313  delete buffer;
1314  delete consumer;
1315 
1316  }
1321  void test_pushSkip(void)
1322  {
1323  InPortCorbaCdrConsumerMock* consumer
1325  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1326  PublisherPeriodicMock publisher;
1327 
1329  prop.setProperty("publisher.push_policy","skip");
1330  prop.setProperty("publisher.skip_count","1");
1331  prop.setProperty("thread_type","default");
1332  prop.setProperty("measurement.exec_time","enable");
1333  prop.setProperty("measurement.exec_count","0");
1334  prop.setProperty("measurement.period_time","enable");
1335  prop.setProperty("measurement.period_count","0");
1336  prop.setProperty("publisher.push_rate","10.0");
1337  publisher.init(prop);
1338  coil::usleep(10000);
1339 
1340  //ConnectorInfo
1341  coil::vstring ports;
1342  RTC::ConnectorInfo info("name", "id", ports, prop);
1343 
1344  //ConnectorListeners
1346  new DataListener("ON_BUFFER_WRITE"), true);
1348  new DataListener("ON_BUFFER_FULL"), true);
1350  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1352  new DataListener("ON_BUFFER_OVERWRITE"), true);
1354  new DataListener("ON_BUFFER_READ"), true);
1356  new DataListener("ON_SEND"), true);
1358  new DataListener("ON_RECEIVED"), true);
1360  new DataListener("ON_RECEIVER_FULL"), true);
1362  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1364  new DataListener("ON_RECEIVER_ERROR"), true);
1365 
1366  // setListener
1367  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1368  publisher.setListener(info, 0));
1369  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1370  publisher.setListener(info, &m_listeners));
1371 
1372  publisher.setConsumer(consumer);
1373  publisher.setBuffer(buffer);
1374  publisher.activate();
1375 
1376  for(int icc(0);icc<16;++icc)
1377  {
1378  cdrMemoryStream cdr;
1379  RTC::TimedLong td;
1380  td.data = icc;
1381  td >>= cdr;
1382 
1383  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1384  publisher.write(cdr,0,0));
1385 
1386  coil::usleep(150000);
1387  }
1388 
1389  //provider 側のバッファ full の状態でコール(full)
1390  {
1391  cdrMemoryStream cdr;
1392  RTC::TimedLong td;
1393  td.data = 16;
1394  td >>= cdr;
1395  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1396  publisher.write(cdr,0,0));
1397  coil::usleep(150000);
1398  }
1399  {
1400  cdrMemoryStream cdr;
1401  RTC::TimedLong td;
1402  td.data = 17;
1403  td >>= cdr;
1404  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1405  publisher.write(cdr,0,0));
1406  coil::usleep(150000);
1407  }
1408 
1409  //provider 側のバッファから 4 件取得 //(full ではない状態にする ) for(int icc(0);icc<4;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(450000); //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1410  //(full ではない状態にする )
1411  for(int icc(0);icc<4;++icc)
1412  {
1413  cdrMemoryStream data;
1414  data = consumer->get_m_put_data();
1415  CORBA::ULong inlen = data.bufSize();
1416  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1417 
1418  RTC::TimedLong rtd;
1419  rtd <<= data;
1420  CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data);
1421  }
1422 
1423  coil::usleep(450000);
1424  //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 19; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データ抜けががないことを確認する。 CPPUNIT_ASSERT_EQUAL(6, consumer->get_m_put_data_len()); for(int icc(0);icc<6;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","skip"); prop.setProperty("publisher.skip_count","1"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10.0"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1425  {
1426  cdrMemoryStream cdr;
1427  RTC::TimedLong td;
1428  td.data = 18;
1429  td >>= cdr;
1430  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1431  publisher.write(cdr,0,0));
1432  coil::usleep(150000);
1433  }
1434  {
1435  cdrMemoryStream cdr;
1436  RTC::TimedLong td;
1437  td.data = 19;
1438  td >>= cdr;
1439  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1440  publisher.write(cdr,0,0));
1441  coil::usleep(150000);
1442  }
1443 
1444  //データ抜けががないことを確認する。
1445  CPPUNIT_ASSERT_EQUAL(6,
1446  consumer->get_m_put_data_len());
1447  for(int icc(0);icc<6;++icc)
1448  {
1449  cdrMemoryStream data;
1450  data = consumer->get_m_put_data();
1451  CORBA::ULong inlen = data.bufSize();
1452  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1453 
1454  RTC::TimedLong rtd;
1455  rtd <<= data;
1456  CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data);
1457  }
1458 
1459  coil::usleep(100000);
1460  publisher.deactivate();
1461  delete buffer;
1462  delete consumer;
1463  }
1469  void test_pushSkip_2(void)
1470  {
1471  InPortCorbaCdrConsumerMock* consumer
1473  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1474  PublisherPeriodicMock publisher;
1475 
1477  prop.setProperty("publisher.push_policy","skip");
1478  prop.setProperty("publisher.skip_count","1");
1479  prop.setProperty("thread_type","default");
1480  prop.setProperty("measurement.exec_time","enable");
1481  prop.setProperty("measurement.exec_count","0");
1482  prop.setProperty("measurement.period_time","enable");
1483  prop.setProperty("measurement.period_count","0");
1484  prop.setProperty("publisher.push_rate","10.0");
1485  publisher.init(prop);
1486  coil::usleep(10000);
1487 
1488  //ConnectorInfo
1489  coil::vstring ports;
1490  RTC::ConnectorInfo info("name", "id", ports, prop);
1491 
1492  //ConnectorListeners
1494  new DataListener("ON_BUFFER_WRITE"), true);
1496  new DataListener("ON_BUFFER_FULL"), true);
1498  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1500  new DataListener("ON_BUFFER_OVERWRITE"), true);
1502  new DataListener("ON_BUFFER_READ"), true);
1504  new DataListener("ON_SEND"), true);
1506  new DataListener("ON_RECEIVED"), true);
1508  new DataListener("ON_RECEIVER_FULL"), true);
1510  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1512  new DataListener("ON_RECEIVER_ERROR"), true);
1513 
1514  // setListener
1515  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1516  publisher.setListener(info, 0));
1517  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1518  publisher.setListener(info, &m_listeners));
1519 
1520  publisher.setConsumer(consumer);
1521  publisher.setBuffer(buffer);
1522  publisher.activate();
1523 
1524  //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<25;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; RTC::PublisherBase::ReturnCode ret; ret = publisher.write(cdr,0,0); if(icc<18) { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, ret); } coil::usleep(150000); } //consumer と provider 両方の buffer が full 状態のため、 // この write データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 for(int icc(0);icc<8;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data); } coil::usleep(150000); //データを確認する。 int len =consumer->get_m_put_data_len(); CPPUNIT_ASSERT_EQUAL(4,len); for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data); } coil::usleep(150000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(150000); } //データを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","new"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); publisher.setConsumer(consumer); publisher.setBuffer(buffer); publisher.activate(); //8件のデータは転送されない //最新データの7は転送される。 for(int icc(0);icc<8;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(150000); //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1525  for(int icc(0);icc<25;++icc)
1526  {
1527  cdrMemoryStream cdr;
1528  RTC::TimedLong td;
1529  td.data = icc;
1530  td >>= cdr;
1531 
1533  ret = publisher.write(cdr,0,0);
1534  if(icc<18)
1535  {
1536  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1537  ret);
1538  }
1539  else
1540  {
1541  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1542  ret);
1543  }
1544  coil::usleep(150000);
1545 
1546  }
1547 
1548  //consumer と provider 両方の buffer が full 状態のため、
1549  // この write データは抜ける。
1550  {
1551  cdrMemoryStream cdr;
1552  RTC::TimedLong td;
1553  td.data = 25;
1554  td >>= cdr;
1555  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::BUFFER_FULL,
1556  publisher.write(cdr,0,0));
1557  coil::usleep(150000);
1558  }
1559 
1560  //データを確認する。
1561  for(int icc(0);icc<8;++icc)
1562  {
1563  cdrMemoryStream data;
1564  data = consumer->get_m_put_data();
1565  CORBA::ULong inlen = data.bufSize();
1566  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1567 
1568  RTC::TimedLong rtd;
1569  rtd <<= data;
1570  CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data);
1571  }
1572 
1573  coil::usleep(150000);
1574  //データを確認する。
1575  int len =consumer->get_m_put_data_len();
1576  CPPUNIT_ASSERT_EQUAL(4,len);
1577  for(int icc(0);icc<len;++icc)
1578  {
1579  cdrMemoryStream data;
1580  data = consumer->get_m_put_data();
1581  CORBA::ULong inlen = data.bufSize();
1582  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1583 
1584  RTC::TimedLong rtd;
1585  rtd <<= data;
1586  CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data);
1587  }
1588  coil::usleep(150000);
1589  {
1590  cdrMemoryStream cdr;
1591  RTC::TimedLong td;
1592  td.data = 26;
1593  td >>= cdr;
1594  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1595  publisher.write(cdr,0,0));
1596  coil::usleep(150000);
1597  }
1598  {
1599  cdrMemoryStream cdr;
1600  RTC::TimedLong td;
1601  td.data = 27;
1602  td >>= cdr;
1603  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1604  publisher.write(cdr,0,0));
1605  coil::usleep(150000);
1606  }
1607  //データを確認する。
1608  {
1609 
1610  cdrMemoryStream data;
1611  data = consumer->get_m_put_data();
1612  CORBA::ULong inlen = data.bufSize();
1613  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1614 
1615  RTC::TimedLong rtd;
1616  rtd <<= data;
1617  CPPUNIT_ASSERT_EQUAL((long)26, (long)rtd.data);
1618  }
1619 
1620  coil::usleep(100000);
1621  publisher.deactivate();
1622 
1623  delete buffer;
1624  delete consumer;
1625 
1626  }
1631  void test_pushNew(void)
1632  {
1633  InPortCorbaCdrConsumerMock* consumer
1635  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1636  PublisherPeriodicMock publisher;
1637 
1639  prop.setProperty("publisher.push_policy","new");
1640  prop.setProperty("publisher.skip_count","0");
1641  prop.setProperty("thread_type","default");
1642  prop.setProperty("measurement.exec_time","enable");
1643  prop.setProperty("measurement.exec_count","0");
1644  prop.setProperty("measurement.period_time","enable");
1645  prop.setProperty("measurement.period_count","0");
1646  prop.setProperty("publisher.push_rate","10");
1647  publisher.init(prop);
1648  coil::usleep(10000);
1649 
1650  //ConnectorInfo
1651  coil::vstring ports;
1652  RTC::ConnectorInfo info("name", "id", ports, prop);
1653 
1654  //ConnectorListeners
1656  new DataListener("ON_BUFFER_WRITE"), true);
1658  new DataListener("ON_BUFFER_FULL"), true);
1660  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1662  new DataListener("ON_BUFFER_OVERWRITE"), true);
1664  new DataListener("ON_BUFFER_READ"), true);
1666  new DataListener("ON_SEND"), true);
1668  new DataListener("ON_RECEIVED"), true);
1670  new DataListener("ON_RECEIVER_FULL"), true);
1672  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1674  new DataListener("ON_RECEIVER_ERROR"), true);
1675 
1676  // setListener
1677  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1678  publisher.setListener(info, 0));
1679  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1680  publisher.setListener(info, &m_listeners));
1681 
1682  publisher.setConsumer(consumer);
1683  publisher.setBuffer(buffer);
1684  publisher.activate();
1685 
1686  //8件のデータは転送されない
1687  //最新データの7は転送される。
1688  for(int icc(0);icc<8;++icc)
1689  {
1690  cdrMemoryStream cdr;
1691  RTC::TimedLong td;
1692  td.data = icc;
1693  td >>= cdr;
1694 
1695  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1696  publisher.write(cdr,0,0));
1697 
1698  }
1699 
1700 
1701  coil::usleep(150000);
1702  //provider 側のバッファから取得 // int len = consumer->get_m_put_data_len() -1; for(int icc(0);icc<len;++icc) { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); } coil::usleep(150000); //最新データが転送されていることを確認する。 { cdrMemoryStream data; data = consumer->get_m_put_data(); CORBA::ULong inlen = data.bufSize(); CPPUNIT_ASSERT_EQUAL(12,(int)inlen); RTC::TimedLong rtd; rtd <<= data; CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock* consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherPeriodicMock publisher; coil::Properties prop; prop.setProperty("publisher.push_policy","all"); prop.setProperty("publisher.skip_count","0"); prop.setProperty("thread_type","default"); prop.setProperty("measurement.exec_time","enable"); prop.setProperty("measurement.exec_count","0"); prop.setProperty("measurement.period_time","enable"); prop.setProperty("measurement.period_count","0"); prop.setProperty("publisher.push_rate","10"); publisher.init(prop); coil::usleep(10000); //ConnectorInfo coil::vstring ports; RTC::ConnectorInfo info("name", "id", ports, prop); //ConnectorListeners m_listeners.connectorData_[RTC::ON_BUFFER_WRITE].addListener( new DataListener("ON_BUFFER_WRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_FULL].addListener( new DataListener("ON_BUFFER_FULL"), true); m_listeners.connectorData_[RTC::ON_BUFFER_WRITE_TIMEOUT].addListener( new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_BUFFER_OVERWRITE].addListener( new DataListener("ON_BUFFER_OVERWRITE"), true); m_listeners.connectorData_[RTC::ON_BUFFER_READ].addListener( new DataListener("ON_BUFFER_READ"), true); m_listeners.connectorData_[RTC::ON_SEND].addListener( new DataListener("ON_SEND"), true); m_listeners.connectorData_[RTC::ON_RECEIVED].addListener( new DataListener("ON_RECEIVED"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_FULL].addListener( new DataListener("ON_RECEIVER_FULL"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_TIMEOUT].addListener( new DataListener("ON_RECEIVER_TIMEOUT"), true); m_listeners.connectorData_[RTC::ON_RECEIVER_ERROR].addListener( new DataListener("ON_RECEIVER_ERROR"), true); // setListener CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS, publisher.setListener(info, 0)); CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK, publisher.setListener(info, &m_listeners)); // { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(100000); } // publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 123; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(100000); } //Listener callback check cdrMemoryStream cdr; RTC::TimedLong td; td.data = 777; td >>= cdr; //m_OnCheck = 1; // PORT_OK:onReceived() //publisher.write(cdr,0,0); //coil::usleep(10000); m_OnCheck = 2; // PORT_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 3; // SEND_FULL:onReceiverFull() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(100000); delete buffer; delete consumer; } /*! * @brief デストラクタのテスト * * - デストラクタ呼出により、release()メソッドを呼び出さずともPublisherの動作が問題なく停止するか? */ /* void test_destructor() { CounterConsumer* consumer1 = new CounterConsumer(); { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1703  //
1704  int len = consumer->get_m_put_data_len() -1;
1705  for(int icc(0);icc<len;++icc)
1706  {
1707  cdrMemoryStream data;
1708  data = consumer->get_m_put_data();
1709  CORBA::ULong inlen = data.bufSize();
1710  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1711  }
1712  coil::usleep(150000);
1713  //最新データが転送されていることを確認する。
1714  {
1715  cdrMemoryStream data;
1716  data = consumer->get_m_put_data();
1717  CORBA::ULong inlen = data.bufSize();
1718  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1719 
1720  RTC::TimedLong rtd;
1721  rtd <<= data;
1722  CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data);
1723  }
1724 
1725  coil::usleep(100000);
1726  publisher.deactivate();
1727  delete buffer;
1728  delete consumer;
1729  }
1735  void test_write(void)
1736  {
1737  InPortCorbaCdrConsumerMock* consumer
1739  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1740  PublisherPeriodicMock publisher;
1741 
1743  prop.setProperty("publisher.push_policy","all");
1744  prop.setProperty("publisher.skip_count","0");
1745  prop.setProperty("thread_type","default");
1746  prop.setProperty("measurement.exec_time","enable");
1747  prop.setProperty("measurement.exec_count","0");
1748  prop.setProperty("measurement.period_time","enable");
1749  prop.setProperty("measurement.period_count","0");
1750  prop.setProperty("publisher.push_rate","10");
1751  publisher.init(prop);
1752  coil::usleep(10000);
1753 
1754  //ConnectorInfo
1755  coil::vstring ports;
1756  RTC::ConnectorInfo info("name", "id", ports, prop);
1757 
1758  //ConnectorListeners
1760  new DataListener("ON_BUFFER_WRITE"), true);
1762  new DataListener("ON_BUFFER_FULL"), true);
1764  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1766  new DataListener("ON_BUFFER_OVERWRITE"), true);
1768  new DataListener("ON_BUFFER_READ"), true);
1770  new DataListener("ON_SEND"), true);
1772  new DataListener("ON_RECEIVED"), true);
1774  new DataListener("ON_RECEIVER_FULL"), true);
1776  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1778  new DataListener("ON_RECEIVER_ERROR"), true);
1779 
1780  // setListener
1781  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1782  publisher.setListener(info, 0));
1783  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1784  publisher.setListener(info, &m_listeners));
1785 
1786  //
1787  {
1788  cdrMemoryStream cdr;
1789  RTC::TimedLong td;
1790  td.data = 123;
1791  td >>= cdr;
1792  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
1793  publisher.write(cdr,0,0));
1794  coil::usleep(100000);
1795  }
1796 
1797  //
1798  publisher.setBuffer(buffer);
1799  {
1800  cdrMemoryStream cdr;
1801  RTC::TimedLong td;
1802  td.data = 123;
1803  td >>= cdr;
1804  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PRECONDITION_NOT_MET,
1805  publisher.write(cdr,0,0));
1806  coil::usleep(100000);
1807  }
1808 
1809  //
1810  publisher.setConsumer(consumer);
1811  {
1812  cdrMemoryStream cdr;
1813  RTC::TimedLong td;
1814  td.data = 123;
1815  td >>= cdr;
1816  CPPUNIT_ASSERT_EQUAL(RTC::PublisherPeriodic::PORT_OK,
1817  publisher.write(cdr,0,0));
1818  coil::usleep(100000);
1819  }
1820 
1821  //Listener callback check
1822  cdrMemoryStream cdr;
1823  RTC::TimedLong td;
1824  td.data = 777;
1825  td >>= cdr;
1826  //m_OnCheck = 1; // PORT_OK:onReceived()
1827  //publisher.write(cdr,0,0);
1828  //coil::usleep(10000);
1829  m_OnCheck = 2; // PORT_ERROR:onReceiverError()
1830  publisher.write(cdr,0,0);
1831  coil::usleep(10000);
1832  m_OnCheck = 3; // SEND_FULL:onReceiverFull()
1833  publisher.write(cdr,0,0);
1834  coil::usleep(100000);
1835  m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout()
1836  publisher.write(cdr,0,0);
1837  coil::usleep(100000);
1838  m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError()
1839  publisher.write(cdr,0,0);
1840  coil::usleep(100000);
1841  m_OnCheck = 6; // CONNECTION_LOST:onReceiverError()
1842  publisher.write(cdr,0,0);
1843  coil::usleep(100000);
1844 
1845  delete buffer;
1846  delete consumer;
1847  }
1853 /*
1854  void test_destructor()
1855  {
1856  CounterConsumer* consumer1 = new CounterConsumer();
1857 
1858  { // Publisherのインスタンススコープ開始 CounterConsumer* consumer2 = new CounterConsumer(consumer1); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer2, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1859  CounterConsumer* consumer2 = new CounterConsumer(consumer1);
1860  coil::Properties prop;
1861  prop.setProperty("dataport.push_rate", "10"); // 10 [Hz]
1862  RTC::PublisherPeriodic publisher(consumer2, prop);
1863  // 5 [sec]だけ動作させる coil::usleep(5000000); } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1864  coil::usleep(5000000);
1865 
1866  } // デストラクタを呼び出す(スコープを終了させる) coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1867 
1868  coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1869 
1870  // この時点での呼出回数を記録する int countReleased = consumer1->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1871  int countReleased = consumer1->getCount();
1872 
1873  // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1874  coil::usleep(5000000); // 5 [sec]
1875 
1876  // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない
1877  // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer1->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作が停止するか? */ /* void test_release() { CounterConsumer* consumer = new CounterConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1878  int countSleeped = consumer1->getCount();
1879  CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped);
1880  }
1881 */
1882 
1888 /*
1889  void test_release()
1890  {
1891  CounterConsumer* consumer = new CounterConsumer();
1892  coil::Properties prop;
1893  prop.setProperty("dataport.push_rate", "10"); // 10 [Hz]
1894  RTC::PublisherPeriodic publisher(consumer, prop);
1895 
1896  // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1897  coil::usleep(5000000);
1898 
1899  // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1900  publisher.release();
1901  coil::usleep(1000000); // 完全停止するまで待つ // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1902 
1903  // この時点での呼出回数を記録する int countReleased = consumer->getCount(); // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1904  int countReleased = consumer->getCount();
1905 
1906  // さらにConsumerがコールバックされ得る時間を与える coil::usleep(5000000); // 5 [sec] // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1907  coil::usleep(5000000); // 5 [sec]
1908 
1909  // この時点での呼出回数を取得し、先に記録しておいた回数から変化がない
1910  // (つまり、Publisherの動作が停止している)ことを確認する int countSleeped = consumer->getCount(); CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped); } */ /*! * @brief PublisherによるConsumer呼出間隔精度のテスト * * - Publisherに指定した時間間隔で、正しくConsumerがコールバックされるか? */ /* void test_interval_accuracy() { MockConsumer* consumer = new MockConsumer(); coil::Properties prop; prop.setProperty("dataport.push_rate", "10"); // 10 [Hz] RTC::PublisherPeriodic publisher(consumer, prop); // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1911  int countSleeped = consumer->getCount();
1912  CPPUNIT_ASSERT_EQUAL(countReleased, countSleeped);
1913  }
1914 */
1915 
1921 /*
1922  void test_interval_accuracy()
1923  {
1924  MockConsumer* consumer = new MockConsumer();
1925  coil::Properties prop;
1926  prop.setProperty("dataport.push_rate", "10"); // 10 [Hz]
1927  RTC::PublisherPeriodic publisher(consumer, prop);
1928 
1929  // 5 [sec]だけ動作させる coil::usleep(5000000); // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1930  coil::usleep(5000000);
1931 
1932  // Publisherの動作を停止させる publisher.release(); coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1933  publisher.release();
1934  coil::usleep(1000000); // 完全停止するまで待つ // 指定した時間間隔で正しくConsumerがコールバックされているか? long permissibleTickMin = static_cast<long>(100000 * 0.9); long permissibleTickMax = static_cast<long>(100000 * 1.1); const std::vector<long> intervalTicks = consumer->getIntervalTicks(); CPPUNIT_ASSERT(intervalTicks.size() > 0); for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++) { long tick = intervalTicks[i]; CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax)); } } */ }; }; // namespace PublisherPeriodic /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // PublisherPeriodic_cpp
1935 
1936  // 指定した時間間隔で正しくConsumerがコールバックされているか?
1937  long permissibleTickMin = static_cast<long>(100000 * 0.9);
1938  long permissibleTickMax = static_cast<long>(100000 * 1.1);
1939  const std::vector<long> intervalTicks = consumer->getIntervalTicks();
1940  CPPUNIT_ASSERT(intervalTicks.size() > 0);
1941 
1942  for (std::vector<long>::size_type i = 0; i < intervalTicks.size(); i++)
1943  {
1944  long tick = intervalTicks[i];
1945  CPPUNIT_ASSERT((permissibleTickMin <= tick) && (tick <= permissibleTickMax));
1946  }
1947  }
1948 */
1949  };
1950 }; // namespace PublisherPeriodic
1951 
1952 /*
1953  * Register test suite
1954  */
1956 
1957 #ifdef LOCAL_MAIN
1958 int main(int argc, char* argv[])
1959 {
1960 
1961  FORMAT format = TEXT_OUT;
1962  int target = 0;
1963  std::string xsl;
1964  std::string ns;
1965  std::string fname;
1966  std::ofstream ofs;
1967 
1968  int i(1);
1969  while (i < argc)
1970  {
1971  std::string arg(argv[i]);
1972  std::string next_arg;
1973  if (i + 1 < argc) next_arg = argv[i + 1];
1974  else next_arg = "";
1975 
1976  if (arg == "--text") { format = TEXT_OUT; break; }
1977  if (arg == "--xml")
1978  {
1979  if (next_arg == "")
1980  {
1981  fname = argv[0];
1982  fname += ".xml";
1983  }
1984  else
1985  {
1986  fname = next_arg;
1987  }
1988  format = XML_OUT;
1989  ofs.open(fname.c_str());
1990  }
1991  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
1992  if ( arg == "--cerr" ) { target = 1; break; }
1993  if ( arg == "--xsl" )
1994  {
1995  if (next_arg == "") xsl = "default.xsl";
1996  else xsl = next_arg;
1997  }
1998  if ( arg == "--namespace" )
1999  {
2000  if (next_arg == "")
2001  {
2002  std::cerr << "no namespace specified" << std::endl;
2003  exit(1);
2004  }
2005  else
2006  {
2007  xsl = next_arg;
2008  }
2009  }
2010  ++i;
2011  }
2012  CppUnit::TextUi::TestRunner runner;
2013  if ( ns.empty() )
2014  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
2015  else
2016  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
2017  CppUnit::Outputter* outputter = 0;
2018  std::ostream* stream = target ? &std::cerr : &std::cout;
2019  switch ( format )
2020  {
2021  case TEXT_OUT :
2022  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
2023  break;
2024  case XML_OUT :
2025  std::cout << "XML_OUT" << std::endl;
2026  outputter = new CppUnit::XmlOutputter(&runner.result(),
2027  ofs, "shift_jis");
2028  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
2029  break;
2030  case COMPILER_OUT :
2031  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
2032  break;
2033  }
2034  runner.setOutputter(outputter);
2035  runner.run();
2036  return 0; // runner.run() ? 0 : 1;
2037 }
2038 #endif // MAIN
2039 #endif // PublisherPeriodic_cpp
CPPUNIT_TEST_SUITE_REGISTRATION(PublisherPeriodic::PublisherPeriodicTests)
void test_pushAll(void)
write(), pushAll() メソッドのテスト
ConnectorListeners class.
InPortConsumer abstract class.
virtual InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
int main(int argc, char **argv)
virtual void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
InPortCorbaCdrConsumer class.
virtual void init(coil::Properties &prop)
Initializing configuration.
RT-Component.
void test_pushAll_2(void)
write(), pushAll() メソッドのテスト
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
void addListener(ConnectorDataListener *listener, bool autoclean)
Add the listener.
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void test_pushSkip_2(void)
write(), pushSkip() メソッドのテスト
void test_pushNew(void)
pushNew()メソッドのテスト
void test_setConsumer(void)
setConsumer()メソッドのテスト
virtual ReturnCode activate()
activation
void test_pushSkip(void)
pushSklip()メソッドのテスト
RingBuffer< cdrMemoryStream > CdrRingBuffer
Definition: CdrRingBuffer.h:28
CounterConsumer(CounterConsumer *component=NULL)
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
virtual ReturnCode init(coil::Properties &prop)
Initialization.
void test_pushFifo_2(void)
write(), pushFifo() メソッドのテスト
void test_pushFifo(void)
pushFifo()メソッドのテスト
virtual ReturnCode setConsumer(InPortConsumer *consumer)
Store InPort consumer.
std::vector< std::string > vstring
Definition: stringutil.h:37
virtual ReturnCode deactivate()
deactivation
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
virtual bool subscribeInterface(const SDOPackage::NVList &)
Subscribe the data send notification.
ConnectorDataListenerHolder connectorData_[CONNECTOR_DATA_LISTENER_NUM]
ConnectorDataListenerType listener array The ConnectorDataListenerType listener is stored...
virtual void unsubscribeInterface(const SDOPackage::NVList &)
Unsubscribe the data send notification.
PublisherPeriodic class.
ConnectorDataListenerT class.
virtual ReturnCode setBuffer(CdrBufferBase *buffer)
Setting buffer pointer.
virtual bool isActive()
If publisher is active state.
virtual void unsubscribeInterface(const SDOPackage::NVList &)
Unsubscribe the data send notification.
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
Definition: Properties.cpp:236
virtual void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
PublisherPeriodic class.
void test_activate_deactivate_isActive(void)
activate(),deactivate(),isActiveメソッドのテスト
virtual void setUp()
Test initialization.
::RTC::BufferStatus::Enum ReturnCode
void test_setBuffer(void)
setBuffer()メソッドのテスト
virtual ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
prop
Organization::get_organization_property ();.
RingBuffer for CDR.
Class represents a set of properties.
Definition: Properties.h:101
virtual bool subscribeInterface(const SDOPackage::NVList &)
Subscribe the data send notification.
void test_write(void)
write()メソッドのテスト
InPortCorbaCdrConsumer class.
virtual RTC::InPortConsumer * clone() const
virtual InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
void test_init(void)
init()メソッドのテスト
virtual const std::vector< long > & getIntervalTicks() const
virtual ReturnCode setListener(ConnectorInfo &info, ConnectorListeners *listeners)
Set the listener.
virtual void tearDown()
Test finalization.
virtual ReturnCode write(const cdrMemoryStream &data, unsigned long sec, unsigned long usec)
Write data.
BufferBase abstract class.
Definition: BufferBase.h:104
virtual RTC::InPortConsumer * clone() const
InPortConsumer class.
connector listener class
virtual void init(coil::Properties &prop)
Initializing configuration.
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
Definition: ace/coil/Time.h:51


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:54