PublisherNewTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: PublisherNewTests.cpp,v $
14  * Revision 1.2 2008/01/23 09:19:31 arafune
15  * added some tests.
16  *
17  * Revision 1.1 2007/12/20 07:50:16 arafune
18  * *** empty log message ***
19  *
20  * Revision 1.2 2007/01/12 14:54:39 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:43 n-ando
25  * The first commitment.
26  *
27  *
28  */
29 
30 #ifndef PublisherNew_cpp
31 #define PublisherNew_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 <coil/Properties.h>
40 #include <rtm/InPortConsumer.h>
41 #include <rtm/PublisherNew.h>
42 #include <coil/Time.h>
43 #include <rtm/CORBA_SeqUtil.h>
44 #include <rtm/NVUtil.h>
46 #include <rtm/CdrRingBuffer.h>
47 
48 #include <rtm/idl/BasicDataTypeSkel.h>
49 #include <rtm/ConnectorListener.h>
50 
55 namespace PublisherNew
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::PublisherNew
88  {
89  public:
91  {
92  ;
93  }
94  virtual ~PublisherNewMock(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  };
227 
229  : public CppUnit::TestFixture
230  {
231  CPPUNIT_TEST_SUITE(PublisherNewTests);
232 
233  //CPPUNIT_TEST(test_init); // OK
234  CPPUNIT_TEST(test_setConsumer);
235  CPPUNIT_TEST(test_setBuffer);
236  CPPUNIT_TEST(test_activate_deactivate_isActive);
237  CPPUNIT_TEST(test_pushAll);
238  CPPUNIT_TEST(test_pushAll_2);
239  CPPUNIT_TEST(test_pushFifo);
240  CPPUNIT_TEST(test_pushFifo_2);
241  CPPUNIT_TEST(test_pushSkip);
242  CPPUNIT_TEST(test_pushSkip_2);
243  CPPUNIT_TEST(test_pushNew);
244  CPPUNIT_TEST(test_write);
245 
246  CPPUNIT_TEST_SUITE_END();
247 
248  private:
249 
250  public:
252 
257  {
258  }
259 
264  {
265  }
266 
270  virtual void setUp()
271  {
272 // coil::usleep(1000000);
273  }
274 
278  virtual void tearDown()
279  {
280  }
281 
286  void test_init(void)
287  {
288  PublisherNewMock publisher;
291 
292  //Propertiesが空の状態でも正常に動作することを確認する retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode); prop.setProperty("publisher.push_policy","new"); prop.setProperty("thread_type","bar"); prop.setProperty("measurement.exec_time","default"); prop.setProperty("measurement.period_count","1"); //thread_type が不正の場合 INVALID_ARGS を返すことを確認する。 retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::INVALID_ARGS, 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"); retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::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"); retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::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"); retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::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"); retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::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"); retcode = publisher.init(prop); coil::usleep(10000); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode); } /*! * @brief setConsumer()メソッドのテスト * */ void test_setConsumer(void) { RTC::InPortCorbaCdrConsumer *consumer0 = new RTC::InPortCorbaCdrConsumer(); RTC::InPortCorbaCdrConsumer *consumer1 = new RTC::InPortCorbaCdrConsumer(); RTC::PublisherNew publisher; //NULLを渡した場合INVALID_ARGSとなることを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::INVALID_ARGS, publisher.setConsumer(NULL)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.setConsumer(consumer0)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.setConsumer(consumer1)); delete consumer0; delete consumer1; } /*! * @brief setBuffer()メソッドのテスト * */ void test_setBuffer(void) { RTC::CdrBufferBase* buffer0 = new RTC::CdrRingBuffer(); RTC::CdrBufferBase* buffer1 = new RTC::CdrRingBuffer(); RTC::PublisherNew publisher; //NULLを渡した場合INVALID_ARGSとなることを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::INVALID_ARGS, publisher.setBuffer(NULL)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.setBuffer(buffer0)); // CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.setBuffer(buffer1)); delete buffer0; delete buffer1; } /*! * @brief activate(),deactivate(),isActiveメソッドのテスト * */ void test_activate_deactivate_isActive(void) { RTC::InPortCorbaCdrConsumer *consumer = new RTC::InPortCorbaCdrConsumer(); RTC::PublisherNew publisher; publisher.setConsumer(consumer); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.activate()); CPPUNIT_ASSERT_EQUAL(true, publisher.isActive()); //既に activate されている場合は //activateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.activate()); CPPUNIT_ASSERT_EQUAL(true, publisher.isActive()); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); //activate されていない状態で、 //deactivateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); coil::usleep(10000); delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * -provider 側のバッファ full 状態でもデータ抜けががないことを確認する。 */ void test_pushAll(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; RTC::PublisherBase::ReturnCode ret = publisher.write(cdr,0,0); bool bret = false; if( (ret == RTC::PublisherNew::PORT_OK) || (ret == RTC::PublisherNew::BUFFER_FULL) ) bret = true; CPPUNIT_ASSERT(bret); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(50000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) coil::usleep(10000); 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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
293  retcode = publisher.init(prop);
294  coil::usleep(10000);
295  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode);
296 
297  prop.setProperty("publisher.push_policy","new");
298  prop.setProperty("thread_type","bar");
299  prop.setProperty("measurement.exec_time","default");
300  prop.setProperty("measurement.period_count","1");
301 
302  //thread_type が不正の場合 INVALID_ARGS を返すことを確認する。
303  retcode = publisher.init(prop);
304  coil::usleep(10000);
305  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::INVALID_ARGS, retcode);
306 
307  //以下のpropertiesの設定で動作することを確認する。
308  prop.setProperty("publisher.push_policy","all");
309  prop.setProperty("publisher.skip_count","0");
310  prop.setProperty("thread_type","default");
311  prop.setProperty("measurement.exec_time","enable");
312  prop.setProperty("measurement.exec_count","0");
313  prop.setProperty("measurement.period_time","enable");
314  prop.setProperty("measurement.period_count","0");
315  retcode = publisher.init(prop);
316  coil::usleep(10000);
317  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode);
318 
319  prop.setProperty("publisher.push_policy","fifo");
320  prop.setProperty("publisher.skip_count","1");
321  prop.setProperty("thread_type","default");
322  prop.setProperty("measurement.exec_time","disable");
323  prop.setProperty("measurement.exec_count","1");
324  prop.setProperty("measurement.period_time","disable");
325  prop.setProperty("measurement.period_count","1");
326  retcode = publisher.init(prop);
327  coil::usleep(10000);
328  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode);
329 
330  prop.setProperty("publisher.push_policy","skip");
331  prop.setProperty("publisher.skip_count","-1");
332  prop.setProperty("thread_type","default");
333  prop.setProperty("measurement.exec_time","bar");
334  prop.setProperty("measurement.exec_count","-1");
335  prop.setProperty("measurement.period_time","bar");
336  prop.setProperty("measurement.period_count","-1");
337  retcode = publisher.init(prop);
338  coil::usleep(10000);
339  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode);
340 
341  prop.setProperty("publisher.push_policy","new");
342  prop.setProperty("publisher.skip_count","foo");
343  prop.setProperty("thread_type","default");
344  prop.setProperty("measurement.exec_time","enable");
345  prop.setProperty("measurement.exec_count","foo");
346  prop.setProperty("measurement.period_time","enable");
347  prop.setProperty("measurement.period_count","foo");
348  retcode = publisher.init(prop);
349  coil::usleep(10000);
350  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode);
351 
352  prop.setProperty("publisher.push_policy","bar");
353  prop.setProperty("publisher.skip_count","0");
354  prop.setProperty("thread_type","default");
355  prop.setProperty("measurement.exec_time","enable");
356  prop.setProperty("measurement.exec_count","0");
357  prop.setProperty("measurement.period_time","enable");
358  prop.setProperty("measurement.period_count","0");
359  retcode = publisher.init(prop);
360  coil::usleep(10000);
361  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, retcode);
362 
363  }
368  void test_setConsumer(void)
369  {
370  RTC::InPortCorbaCdrConsumer *consumer0
372  RTC::InPortCorbaCdrConsumer *consumer1
374  RTC::PublisherNew publisher;
375 
376  //NULLを渡した場合INVALID_ARGSとなることを確認する。
377  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::INVALID_ARGS,
378  publisher.setConsumer(NULL));
379 
380  //
381  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
382  publisher.setConsumer(consumer0));
383 
384  //
385  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
386  publisher.setConsumer(consumer1));
387 
388  delete consumer0;
389  delete consumer1;
390  }
395  void test_setBuffer(void)
396  {
397  RTC::CdrBufferBase* buffer0 = new RTC::CdrRingBuffer();
398  RTC::CdrBufferBase* buffer1 = new RTC::CdrRingBuffer();
399  RTC::PublisherNew publisher;
400 
401  //NULLを渡した場合INVALID_ARGSとなることを確認する。
402  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::INVALID_ARGS,
403  publisher.setBuffer(NULL));
404 
405  //
406  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
407  publisher.setBuffer(buffer0));
408 
409  //
410  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
411  publisher.setBuffer(buffer1));
412 
413  delete buffer0;
414  delete buffer1;
415  }
421  {
422  RTC::InPortCorbaCdrConsumer *consumer
424  RTC::PublisherNew publisher;
425  publisher.setConsumer(consumer);
426 
427  CPPUNIT_ASSERT_EQUAL(false,
428  publisher.isActive());
429 
430  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
431  publisher.activate());
432 
433  CPPUNIT_ASSERT_EQUAL(true,
434  publisher.isActive());
435 
436  //既に activate されている場合は
437  //activateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.activate()); CPPUNIT_ASSERT_EQUAL(true, publisher.isActive()); CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); //activate されていない状態で、 //deactivateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); coil::usleep(10000); delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * -provider 側のバッファ full 状態でもデータ抜けががないことを確認する。 */ void test_pushAll(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; RTC::PublisherBase::ReturnCode ret = publisher.write(cdr,0,0); bool bret = false; if( (ret == RTC::PublisherNew::PORT_OK) || (ret == RTC::PublisherNew::BUFFER_FULL) ) bret = true; CPPUNIT_ASSERT(bret); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(50000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) coil::usleep(10000); 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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
438  //PORT_OK を返すことを確認する。
439  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
440  publisher.activate());
441 
442  CPPUNIT_ASSERT_EQUAL(true,
443  publisher.isActive());
444 
445  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
446  publisher.deactivate());
447 
448  CPPUNIT_ASSERT_EQUAL(false,
449  publisher.isActive());
450 
451  //activate されていない状態で、
452  //deactivateすると //PORT_OK を返すことを確認する。 CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.deactivate()); CPPUNIT_ASSERT_EQUAL(false, publisher.isActive()); coil::usleep(10000); delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * -provider 側のバッファ full 状態でもデータ抜けががないことを確認する。 */ void test_pushAll(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; RTC::PublisherBase::ReturnCode ret = publisher.write(cdr,0,0); bool bret = false; if( (ret == RTC::PublisherNew::PORT_OK) || (ret == RTC::PublisherNew::BUFFER_FULL) ) bret = true; CPPUNIT_ASSERT(bret); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(50000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) coil::usleep(10000); 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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
453  //PORT_OK を返すことを確認する。
454  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
455  publisher.deactivate());
456 
457  CPPUNIT_ASSERT_EQUAL(false,
458  publisher.isActive());
459 
460  coil::usleep(10000);
461  delete consumer;
462  }
468  void test_pushAll(void)
469  {
470  InPortCorbaCdrConsumerMock *consumer
472  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
473  PublisherNewMock publisher;
474 
476  prop.setProperty("publisher.push_policy","all");
477  prop.setProperty("publisher.skip_count","0");
478  prop.setProperty("thread_type","default");
479  prop.setProperty("measurement.exec_time","enable");
480  prop.setProperty("measurement.exec_count","0");
481  prop.setProperty("measurement.period_time","enable");
482  prop.setProperty("measurement.period_count","0");
483  publisher.init(prop);
484  coil::usleep(10000);
485 
486  //ConnectorInfo
487  coil::vstring ports;
488  RTC::ConnectorInfo info("name", "id", ports, prop);
489 
490  //ConnectorListeners
492  new DataListener("ON_BUFFER_WRITE"), true);
494  new DataListener("ON_BUFFER_FULL"), true);
496  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
498  new DataListener("ON_BUFFER_OVERWRITE"), true);
500  new DataListener("ON_BUFFER_READ"), true);
502  new DataListener("ON_SEND"), true);
504  new DataListener("ON_RECEIVED"), true);
506  new DataListener("ON_RECEIVER_FULL"), true);
508  new DataListener("ON_RECEIVER_TIMEOUT"), true);
510  new DataListener("ON_RECEIVER_ERROR"), true);
511 
512  // setListener
513  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
514  publisher.setListener(info, 0));
515  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
516  publisher.setListener(info, &m_listeners));
517 
518  publisher.setConsumer(consumer);
519  publisher.setBuffer(buffer);
520  publisher.activate();
521 
522  for(int icc(0);icc<8;++icc)
523  {
524  cdrMemoryStream cdr;
525  RTC::TimedLong td;
526  td.data = icc;
527  td >>= cdr;
528 
529  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
530  publisher.write(cdr,0,0));
531 
532  }
533 
534  //provider 側のバッファ full の状態でコール(full)
535  {
536  cdrMemoryStream cdr;
537  RTC::TimedLong td;
538  td.data = 8;
539  td >>= cdr;
540  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
541  publisher.write(cdr,0,0));
542  coil::usleep(10000);
543  }
544  {
545  cdrMemoryStream cdr;
546  RTC::TimedLong td;
547  td.data = 9;
548  td >>= cdr;
549  RTC::PublisherBase::ReturnCode ret = publisher.write(cdr,0,0);
550  bool bret = false;
551  if( (ret == RTC::PublisherNew::PORT_OK) ||
552  (ret == RTC::PublisherNew::BUFFER_FULL) ) bret = true;
553  CPPUNIT_ASSERT(bret);
554  coil::usleep(10000);
555  }
556 
557  //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(50000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) coil::usleep(10000); 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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
558  //(full ではない状態にする )
559  for(int icc(0);icc<4;++icc)
560  {
561  cdrMemoryStream data;
562  data = consumer->get_m_put_data();
563  CORBA::ULong inlen = data.bufSize();
564  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
565 
566  RTC::TimedLong rtd;
567  rtd <<= data;
568  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
569  }
570 
571  //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushAll() メソッドのテスト * * - */ void test_pushAll_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 18; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushFifo()メソッドのテスト * */ void test_pushFifo(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(50000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファから 4 件取得 //(full ではない状態にする ) coil::usleep(10000); 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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
572  {
573  cdrMemoryStream cdr;
574  RTC::TimedLong td;
575  td.data = 10;
576  td >>= cdr;
577  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
578  publisher.write(cdr,0,0));
579  coil::usleep(10000);
580  }
581  {
582  cdrMemoryStream cdr;
583  RTC::TimedLong td;
584  td.data = 11;
585  td >>= cdr;
586  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
587  publisher.write(cdr,0,0));
588  coil::usleep(10000);
589  }
590 
591  //データ抜けががないことを確認する。
592  for(int icc(0);icc<8;++icc)
593  {
594  cdrMemoryStream data;
595  data = consumer->get_m_put_data();
596  CORBA::ULong inlen = data.bufSize();
597  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
598 
599  RTC::TimedLong rtd;
600  rtd <<= data;
601  CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data);
602  }
603  publisher.deactivate();
604 
605  coil::usleep(10000);
606  delete buffer;
607  delete consumer;
608 
609  }
615  void test_pushAll_2(void)
616  {
617  InPortCorbaCdrConsumerMock *consumer
619  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
620  PublisherNewMock publisher;
621 
623  prop.setProperty("publisher.push_policy","all");
624  prop.setProperty("publisher.skip_count","0");
625  prop.setProperty("thread_type","default");
626  prop.setProperty("measurement.exec_time","enable");
627  prop.setProperty("measurement.exec_count","0");
628  prop.setProperty("measurement.period_time","enable");
629  prop.setProperty("measurement.period_count","0");
630  publisher.init(prop);
631  coil::usleep(10000);
632 
633  //ConnectorInfo
634  coil::vstring ports;
635  RTC::ConnectorInfo info("name", "id", ports, prop);
636 
637  //ConnectorListeners
639  new DataListener("ON_BUFFER_WRITE"), true);
641  new DataListener("ON_BUFFER_FULL"), true);
643  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
645  new DataListener("ON_BUFFER_OVERWRITE"), true);
647  new DataListener("ON_BUFFER_READ"), true);
649  new DataListener("ON_SEND"), true);
651  new DataListener("ON_RECEIVED"), true);
653  new DataListener("ON_RECEIVER_FULL"), true);
655  new DataListener("ON_RECEIVER_TIMEOUT"), true);
657  new DataListener("ON_RECEIVER_ERROR"), true);
658 
659  // setListener
660  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
661  publisher.setListener(info, 0));
662  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
663  publisher.setListener(info, &m_listeners));
664 
665  publisher.setConsumer(consumer);
666  publisher.setBuffer(buffer);
667  publisher.activate();
668 
669  for(int icc(0);icc<16;++icc)
670  {
671  cdrMemoryStream cdr;
672  RTC::TimedLong td;
673  td.data = icc;
674  td >>= cdr;
675 
677  ret = publisher.write(cdr,0,0);
678  if(icc<9)
679  {
680  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
681  ret);
682  }
683  else
684  {
685  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
686  ret);
687  }
688  coil::usleep(10000);
689 
690  }
691 
692  //consumer と provider 両方の buffer が full 状態のため、
693  // この weite データは抜ける。
694  {
695  cdrMemoryStream cdr;
696  RTC::TimedLong td;
697  td.data = 16;
698  td >>= cdr;
699  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
700  publisher.write(cdr,0,0));
701  coil::usleep(10000);
702  }
703 
704  //データを確認する。
705  for(int icc(0);icc<8;++icc)
706  {
707  cdrMemoryStream data;
708  data = consumer->get_m_put_data();
709  CORBA::ULong inlen = data.bufSize();
710  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
711 
712  RTC::TimedLong rtd;
713  rtd <<= data;
714  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
715  }
716 
717  //consumer の buffer が full 状態のため、
718  // この weite データは抜ける。
719  {
720  cdrMemoryStream cdr;
721  RTC::TimedLong td;
722  td.data = 17;
723  td >>= cdr;
724  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
725  publisher.write(cdr,0,0));
726  coil::usleep(10000);
727  }
728  //データを確認する。
729  for(int icc(0);icc<8;++icc)
730  {
731  cdrMemoryStream data;
732  data = consumer->get_m_put_data();
733  CORBA::ULong inlen = data.bufSize();
734  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
735 
736  RTC::TimedLong rtd;
737  rtd <<= data;
738  CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data);
739  }
740  {
741  cdrMemoryStream cdr;
742  RTC::TimedLong td;
743  td.data = 18;
744  td >>= cdr;
745  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
746  publisher.write(cdr,0,0));
747  coil::usleep(10000);
748  }
749  //データを確認する。
750  {
751  cdrMemoryStream data;
752  data = consumer->get_m_put_data();
753  CORBA::ULong inlen = data.bufSize();
754  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
755 
756  RTC::TimedLong rtd;
757  rtd <<= data;
758  CPPUNIT_ASSERT_EQUAL((long)18, (long)rtd.data);
759  }
760 
761  coil::usleep(10000);
762  publisher.deactivate();
763 
764  coil::usleep(10000);
765  delete buffer;
766  delete consumer;
767 
768  }
773  void test_pushFifo(void)
774  {
775  InPortCorbaCdrConsumerMock *consumer
777  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
778  PublisherNewMock publisher;
779 
781  prop.setProperty("publisher.push_policy","fifo");
782  prop.setProperty("publisher.skip_count","0");
783  prop.setProperty("thread_type","default");
784  prop.setProperty("measurement.exec_time","enable");
785  prop.setProperty("measurement.exec_count","0");
786  prop.setProperty("measurement.period_time","enable");
787  prop.setProperty("measurement.period_count","0");
788  publisher.init(prop);
789  coil::usleep(10000);
790 
791  //ConnectorInfo
792  coil::vstring ports;
793  RTC::ConnectorInfo info("name", "id", ports, prop);
794 
795  //ConnectorListeners
797  new DataListener("ON_BUFFER_WRITE"), true);
799  new DataListener("ON_BUFFER_FULL"), true);
801  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
803  new DataListener("ON_BUFFER_OVERWRITE"), true);
805  new DataListener("ON_BUFFER_READ"), true);
807  new DataListener("ON_SEND"), true);
809  new DataListener("ON_RECEIVED"), true);
811  new DataListener("ON_RECEIVER_FULL"), true);
813  new DataListener("ON_RECEIVER_TIMEOUT"), true);
815  new DataListener("ON_RECEIVER_ERROR"), true);
816 
817  // setListener
818  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
819  publisher.setListener(info, 0));
820  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
821  publisher.setListener(info, &m_listeners));
822 
823  publisher.setConsumer(consumer);
824  publisher.setBuffer(buffer);
825  publisher.activate();
826 
827  for(int icc(0);icc<8;++icc)
828  {
829  cdrMemoryStream cdr;
830  RTC::TimedLong td;
831  td.data = icc;
832  td >>= cdr;
833 
834  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
835  publisher.write(cdr,0,0));
836 
837  coil::usleep(10000);
838  }
839 
840  //provider 側のバッファ full の状態でコール(full)
841  {
842  cdrMemoryStream cdr;
843  RTC::TimedLong td;
844  td.data = 8;
845  td >>= cdr;
846  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
847  publisher.write(cdr,0,0));
848  coil::usleep(50000);
849  }
850  {
851  cdrMemoryStream cdr;
852  RTC::TimedLong td;
853  td.data = 9;
854  td >>= cdr;
855  //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
856  // publisher.write(cdr,0,0));
857  publisher.write(cdr,0,0);
858  coil::usleep(10000);
859  }
860 
861  //provider 側のバッファから 4 件取得 //(full ではない状態にする ) coil::usleep(10000); 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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
862  //(full ではない状態にする )
863  coil::usleep(10000);
864  for(int icc(0);icc<4;++icc)
865  {
866  cdrMemoryStream data;
867  data = consumer->get_m_put_data();
868  CORBA::ULong inlen = data.bufSize();
869  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
870 
871  RTC::TimedLong rtd;
872  rtd <<= data;
873  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
874  }
875 
876  //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(30000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 12; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 13; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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); } //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
877  {
878  cdrMemoryStream cdr;
879  RTC::TimedLong td;
880  td.data = 10;
881  td >>= cdr;
882  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
883  publisher.write(cdr,0,0));
884  coil::usleep(30000);
885  }
886  {
887  cdrMemoryStream cdr;
888  RTC::TimedLong td;
889  td.data = 11;
890  td >>= cdr;
891  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
892  publisher.write(cdr,0,0));
893  coil::usleep(10000);
894  }
895  {
896  cdrMemoryStream cdr;
897  RTC::TimedLong td;
898  td.data = 12;
899  td >>= cdr;
900  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
901  publisher.write(cdr,0,0));
902  coil::usleep(10000);
903  }
904  {
905  cdrMemoryStream cdr;
906  RTC::TimedLong td;
907  td.data = 13;
908  td >>= cdr;
909  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
910  publisher.write(cdr,0,0));
911  coil::usleep(10000);
912  }
913 
914  //データ抜けががないことを確認する。
915  for(int icc(0);icc<8;++icc)
916  {
917  cdrMemoryStream data;
918  data = consumer->get_m_put_data();
919  CORBA::ULong inlen = data.bufSize();
920  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
921 
922  RTC::TimedLong rtd;
923  rtd <<= data;
924  CPPUNIT_ASSERT_EQUAL((long)icc+4, (long)rtd.data);
925  }
926 
927  //この時点で consumer 側のバッファにデータが 2 件格納されている状態 coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushFifo() メソッドのテスト * * - */ void test_pushFifo_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
928 
929  coil::usleep(10000);
930  publisher.deactivate();
931  coil::usleep(10000);
932  delete buffer;
933  delete consumer;
934 
935  }
941  void test_pushFifo_2(void)
942  {
943  InPortCorbaCdrConsumerMock *consumer
945  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
946  PublisherNewMock publisher;
947 
949  prop.setProperty("publisher.push_policy","fifo");
950  prop.setProperty("publisher.skip_count","0");
951  prop.setProperty("thread_type","default");
952  prop.setProperty("measurement.exec_time","enable");
953  prop.setProperty("measurement.exec_count","0");
954  prop.setProperty("measurement.period_time","enable");
955  prop.setProperty("measurement.period_count","0");
956  publisher.init(prop);
957  coil::usleep(10000);
958 
959  //ConnectorInfo
960  coil::vstring ports;
961  RTC::ConnectorInfo info("name", "id", ports, prop);
962 
963  //ConnectorListeners
965  new DataListener("ON_BUFFER_WRITE"), true);
967  new DataListener("ON_BUFFER_FULL"), true);
969  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
971  new DataListener("ON_BUFFER_OVERWRITE"), true);
973  new DataListener("ON_BUFFER_READ"), true);
975  new DataListener("ON_SEND"), true);
977  new DataListener("ON_RECEIVED"), true);
979  new DataListener("ON_RECEIVER_FULL"), true);
981  new DataListener("ON_RECEIVER_TIMEOUT"), true);
983  new DataListener("ON_RECEIVER_ERROR"), true);
984 
985  // setListener
986  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
987  publisher.setListener(info, 0));
988  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
989  publisher.setListener(info, &m_listeners));
990 
991  publisher.setConsumer(consumer);
992  publisher.setBuffer(buffer);
993  publisher.activate();
994 
995  //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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 16; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 17; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } // この weite データは転送される。 for(int icc(0);icc<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = (18+icc); td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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 = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)18, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushSklip()メソッドのテスト * */ void test_pushSkip(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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::PublisherNew::PORT_OK, // publisher.write(cdr,0,0)); publisher.write(cdr,0,0); coil::usleep(10000); } //provider 側のバッファ full の状態でコール(full) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 8; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 9; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
996  for(int icc(0);icc<16;++icc)
997  {
998  cdrMemoryStream cdr;
999  RTC::TimedLong td;
1000  td.data = icc;
1001  td >>= cdr;
1002 
1004  ret = publisher.write(cdr,0,0);
1005  if(icc<9)
1006  {
1007  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1008  ret);
1009  }
1010  else
1011  {
1012  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1013  ret);
1014  }
1015  coil::usleep(10000);
1016 
1017  }
1018 
1019  //consumer と provider 両方の buffer が full 状態のため、
1020  // この weite データは抜ける。
1021  {
1022  cdrMemoryStream cdr;
1023  RTC::TimedLong td;
1024  td.data = 16;
1025  td >>= cdr;
1026  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1027  publisher.write(cdr,0,0));
1028  coil::usleep(10000);
1029  }
1030 
1031  //データを確認する。
1032  for(int icc(0);icc<8;++icc)
1033  {
1034  cdrMemoryStream data;
1035  data = consumer->get_m_put_data();
1036  CORBA::ULong inlen = data.bufSize();
1037  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1038 
1039  RTC::TimedLong rtd;
1040  rtd <<= data;
1041  CPPUNIT_ASSERT_EQUAL((long)icc, (long)rtd.data);
1042  }
1043 
1044  //consumer の buffer が full 状態のため、
1045  // この weite データは抜ける。
1046  {
1047  cdrMemoryStream cdr;
1048  RTC::TimedLong td;
1049  td.data = 17;
1050  td >>= cdr;
1051  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1052  publisher.write(cdr,0,0));
1053  coil::usleep(10000);
1054  }
1055  // この weite データは転送される。
1056  for(int icc(0);icc<7;++icc)
1057  {
1058  cdrMemoryStream cdr;
1059  RTC::TimedLong td;
1060  td.data = (18+icc);
1061  td >>= cdr;
1062  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1063  publisher.write(cdr,0,0));
1064  coil::usleep(10000);
1065  }
1066  //データを確認する。
1067  for(int icc(0);icc<8;++icc)
1068  {
1069  cdrMemoryStream data;
1070  data = consumer->get_m_put_data();
1071  CORBA::ULong inlen = data.bufSize();
1072  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1073 
1074  RTC::TimedLong rtd;
1075  rtd <<= data;
1076  CPPUNIT_ASSERT_EQUAL((long)icc+8, (long)rtd.data);
1077  }
1078  {
1079  cdrMemoryStream cdr;
1080  RTC::TimedLong td;
1081  td.data = 26;
1082  td >>= cdr;
1083  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1084  publisher.write(cdr,0,0));
1085  coil::usleep(10000);
1086  }
1087  //データを確認する。
1088  {
1089  cdrMemoryStream data;
1090  data = consumer->get_m_put_data();
1091  CORBA::ULong inlen = data.bufSize();
1092  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1093 
1094  RTC::TimedLong rtd;
1095  rtd <<= data;
1096  CPPUNIT_ASSERT_EQUAL((long)18, (long)rtd.data);
1097  }
1098 
1099 
1100  coil::usleep(10000);
1101  publisher.deactivate();
1102 
1103  coil::usleep(10000);
1104  delete buffer;
1105  delete consumer;
1106 
1107  }
1112  void test_pushSkip(void)
1113  {
1114  InPortCorbaCdrConsumerMock *consumer
1116  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1117  PublisherNewMock publisher;
1118 
1120  prop.setProperty("publisher.push_policy","skip");
1121  prop.setProperty("publisher.skip_count","1");
1122  prop.setProperty("thread_type","default");
1123  prop.setProperty("measurement.exec_time","enable");
1124  prop.setProperty("measurement.exec_count","0");
1125  prop.setProperty("measurement.period_time","enable");
1126  prop.setProperty("measurement.period_count","0");
1127  publisher.init(prop);
1128  coil::usleep(10000);
1129 
1130  //ConnectorInfo
1131  coil::vstring ports;
1132  RTC::ConnectorInfo info("name", "id", ports, prop);
1133 
1134  //ConnectorListeners
1136  new DataListener("ON_BUFFER_WRITE"), true);
1138  new DataListener("ON_BUFFER_FULL"), true);
1140  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1142  new DataListener("ON_BUFFER_OVERWRITE"), true);
1144  new DataListener("ON_BUFFER_READ"), true);
1146  new DataListener("ON_SEND"), true);
1148  new DataListener("ON_RECEIVED"), true);
1150  new DataListener("ON_RECEIVER_FULL"), true);
1152  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1154  new DataListener("ON_RECEIVER_ERROR"), true);
1155 
1156  // setListener
1157  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1158  publisher.setListener(info, 0));
1159  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1160  publisher.setListener(info, &m_listeners));
1161 
1162  publisher.setConsumer(consumer);
1163  publisher.setBuffer(buffer);
1164  publisher.activate();
1165 
1166  for(int icc(0);icc<16;++icc)
1167  {
1168  cdrMemoryStream cdr;
1169  RTC::TimedLong td;
1170  td.data = icc;
1171  td >>= cdr;
1172 
1173  //CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1174  // publisher.write(cdr,0,0));
1175  publisher.write(cdr,0,0);
1176  coil::usleep(10000);
1177  }
1178 
1179  //provider 側のバッファ full の状態でコール(full)
1180  {
1181  cdrMemoryStream cdr;
1182  RTC::TimedLong td;
1183  td.data = 8;
1184  td >>= cdr;
1185  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1186  publisher.write(cdr,0,0));
1187  coil::usleep(10000);
1188  }
1189  {
1190  cdrMemoryStream cdr;
1191  RTC::TimedLong td;
1192  td.data = 9;
1193  td >>= cdr;
1194  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1195  publisher.write(cdr,0,0));
1196  coil::usleep(10000);
1197  }
1198 
1199  //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); } //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1200  //(full ではない状態にする )
1201  for(int icc(0);icc<4;++icc)
1202  {
1203  cdrMemoryStream data;
1204  data = consumer->get_m_put_data();
1205  CORBA::ULong inlen = data.bufSize();
1206  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1207 
1208  RTC::TimedLong rtd;
1209  rtd <<= data;
1210  CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data);
1211  }
1212 
1213  //provider 側のバッファ full ではない状態でコール { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 10; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 11; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データ抜けががないことを確認する。 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*2+9, (long)rtd.data); } coil::usleep(100000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief write(), pushSkip() メソッドのテスト * * - */ void test_pushSkip_2(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1214  {
1215  cdrMemoryStream cdr;
1216  RTC::TimedLong td;
1217  td.data = 10;
1218  td >>= cdr;
1219  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1220  publisher.write(cdr,0,0));
1221  coil::usleep(10000);
1222  }
1223  {
1224  cdrMemoryStream cdr;
1225  RTC::TimedLong td;
1226  td.data = 11;
1227  td >>= cdr;
1228  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1229  publisher.write(cdr,0,0));
1230  coil::usleep(10000);
1231  }
1232 
1233  //データ抜けががないことを確認する。
1234  for(int icc(0);icc<2;++icc)
1235  {
1236  cdrMemoryStream data;
1237  data = consumer->get_m_put_data();
1238  CORBA::ULong inlen = data.bufSize();
1239  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1240 
1241  RTC::TimedLong rtd;
1242  rtd <<= data;
1243  CPPUNIT_ASSERT_EQUAL((long)icc*2+9, (long)rtd.data);
1244  }
1245 
1246  coil::usleep(100000);
1247  publisher.deactivate();
1248  coil::usleep(10000);
1249  delete buffer;
1250  delete consumer;
1251  }
1257  void test_pushSkip_2(void)
1258  {
1259  InPortCorbaCdrConsumerMock *consumer
1261  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1262  PublisherNewMock publisher;
1263 
1265  prop.setProperty("publisher.push_policy","skip");
1266  prop.setProperty("publisher.skip_count","1");
1267  prop.setProperty("thread_type","default");
1268  prop.setProperty("measurement.exec_time","enable");
1269  prop.setProperty("measurement.exec_count","0");
1270  prop.setProperty("measurement.period_time","enable");
1271  prop.setProperty("measurement.period_count","0");
1272  publisher.init(prop);
1273  coil::usleep(10000);
1274 
1275  //ConnectorInfo
1276  coil::vstring ports;
1277  RTC::ConnectorInfo info("name", "id", ports, prop);
1278 
1279  //ConnectorListeners
1281  new DataListener("ON_BUFFER_WRITE"), true);
1283  new DataListener("ON_BUFFER_FULL"), true);
1285  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1287  new DataListener("ON_BUFFER_OVERWRITE"), true);
1289  new DataListener("ON_BUFFER_READ"), true);
1291  new DataListener("ON_SEND"), true);
1293  new DataListener("ON_RECEIVED"), true);
1295  new DataListener("ON_RECEIVER_FULL"), true);
1297  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1299  new DataListener("ON_RECEIVER_ERROR"), true);
1300 
1301  // setListener
1302  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1303  publisher.setListener(info, 0));
1304  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1305  publisher.setListener(info, &m_listeners));
1306 
1307  publisher.setConsumer(consumer);
1308  publisher.setBuffer(buffer);
1309  publisher.activate();
1310 
1311  //consumer と provider 両方の buffer を full 状態にする for(int icc(0);icc<24;++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::PublisherNew::PORT_OK, ret); } else { CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, ret); } coil::usleep(10000); } //consumer と provider 両方の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 24; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } //consumer の buffer が full 状態のため、 // この weite データは抜ける。 { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 25; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 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); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 26; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 27; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //データを確認する。 { 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)27, (long)rtd.data); } coil::usleep(10000); publisher.deactivate(); coil::usleep(10000); delete buffer; delete consumer; } /*! * @brief pushNew()メソッドのテスト * */ void test_pushNew(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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<7;++icc) { cdrMemoryStream cdr; RTC::TimedLong td; td.data = icc; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 7; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); } coil::usleep(10000); //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1312  for(int icc(0);icc<24;++icc)
1313  {
1314  cdrMemoryStream cdr;
1315  RTC::TimedLong td;
1316  td.data = icc;
1317  td >>= cdr;
1318 
1320  ret = publisher.write(cdr,0,0);
1321  if(icc<18)
1322  {
1323  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1324  ret);
1325  }
1326  else
1327  {
1328  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1329  ret);
1330  }
1331  coil::usleep(10000);
1332 
1333  }
1334 
1335  //consumer と provider 両方の buffer が full 状態のため、
1336  // この weite データは抜ける。
1337  {
1338  cdrMemoryStream cdr;
1339  RTC::TimedLong td;
1340  td.data = 24;
1341  td >>= cdr;
1342  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1343  publisher.write(cdr,0,0));
1344  coil::usleep(10000);
1345  }
1346 
1347  //データを確認する。
1348  for(int icc(0);icc<8;++icc)
1349  {
1350  cdrMemoryStream data;
1351  data = consumer->get_m_put_data();
1352  CORBA::ULong inlen = data.bufSize();
1353  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1354 
1355  RTC::TimedLong rtd;
1356  rtd <<= data;
1357  CPPUNIT_ASSERT_EQUAL((long)icc*2+1, (long)rtd.data);
1358  }
1359 
1360  //consumer の buffer が full 状態のため、
1361  // この weite データは抜ける。
1362  {
1363  cdrMemoryStream cdr;
1364  RTC::TimedLong td;
1365  td.data = 25;
1366  td >>= cdr;
1367  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::BUFFER_FULL,
1368  publisher.write(cdr,0,0));
1369  coil::usleep(10000);
1370  }
1371  //データを確認する。
1372  int len =consumer->get_m_put_data_len();
1373  CPPUNIT_ASSERT_EQUAL(4,len);
1374  for(int icc(0);icc<len;++icc)
1375  {
1376  cdrMemoryStream data;
1377  data = consumer->get_m_put_data();
1378  CORBA::ULong inlen = data.bufSize();
1379  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1380 
1381  RTC::TimedLong rtd;
1382  rtd <<= data;
1383  CPPUNIT_ASSERT_EQUAL((long)icc*2+17, (long)rtd.data);
1384  }
1385  {
1386  cdrMemoryStream cdr;
1387  RTC::TimedLong td;
1388  td.data = 26;
1389  td >>= cdr;
1390  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1391  publisher.write(cdr,0,0));
1392  coil::usleep(10000);
1393  }
1394  {
1395  cdrMemoryStream cdr;
1396  RTC::TimedLong td;
1397  td.data = 27;
1398  td >>= cdr;
1399  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1400  publisher.write(cdr,0,0));
1401  coil::usleep(10000);
1402  }
1403  //データを確認する。
1404  {
1405  cdrMemoryStream data;
1406  data = consumer->get_m_put_data();
1407  CORBA::ULong inlen = data.bufSize();
1408  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1409 
1410  RTC::TimedLong rtd;
1411  rtd <<= data;
1412  CPPUNIT_ASSERT_EQUAL((long)27, (long)rtd.data);
1413  }
1414 
1415  coil::usleep(10000);
1416  publisher.deactivate();
1417 
1418  coil::usleep(10000);
1419  delete buffer;
1420  delete consumer;
1421 
1422  }
1427  void test_pushNew(void)
1428  {
1429  InPortCorbaCdrConsumerMock *consumer
1431  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1432  PublisherNewMock publisher;
1433 
1435  prop.setProperty("publisher.push_policy","new");
1436  prop.setProperty("publisher.skip_count","0");
1437  prop.setProperty("thread_type","default");
1438  prop.setProperty("measurement.exec_time","enable");
1439  prop.setProperty("measurement.exec_count","0");
1440  prop.setProperty("measurement.period_time","enable");
1441  prop.setProperty("measurement.period_count","0");
1442  publisher.init(prop);
1443  coil::usleep(10000);
1444 
1445  //ConnectorInfo
1446  coil::vstring ports;
1447  RTC::ConnectorInfo info("name", "id", ports, prop);
1448 
1449  //ConnectorListeners
1451  new DataListener("ON_BUFFER_WRITE"), true);
1453  new DataListener("ON_BUFFER_FULL"), true);
1455  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1457  new DataListener("ON_BUFFER_OVERWRITE"), true);
1459  new DataListener("ON_BUFFER_READ"), true);
1461  new DataListener("ON_SEND"), true);
1463  new DataListener("ON_RECEIVED"), true);
1465  new DataListener("ON_RECEIVER_FULL"), true);
1467  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1469  new DataListener("ON_RECEIVER_ERROR"), true);
1470 
1471  // setListener
1472  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1473  publisher.setListener(info, 0));
1474  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1475  publisher.setListener(info, &m_listeners));
1476 
1477  publisher.setConsumer(consumer);
1478  publisher.setBuffer(buffer);
1479  publisher.activate();
1480 
1481  //8件のデータは転送されない
1482  //最新データの7は転送される。
1483  for(int icc(0);icc<7;++icc)
1484  {
1485  cdrMemoryStream cdr;
1486  RTC::TimedLong td;
1487  td.data = icc;
1488  td >>= cdr;
1489 
1490  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1491  publisher.write(cdr,0,0));
1492 
1493  }
1494 
1495  coil::usleep(10000);
1496  {
1497  cdrMemoryStream cdr;
1498  RTC::TimedLong td;
1499  td.data = 7;
1500  td >>= cdr;
1501 
1502  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1503  publisher.write(cdr,0,0));
1504 
1505  }
1506 
1507  coil::usleep(10000);
1508  //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); } //最新データが転送されていることを確認する。 { 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(1000000); // ここは長めにしないと落ちます。 publisher.deactivate(); coil::usleep(1000000); // ここは長めにしないと落ちます。 delete buffer; delete consumer; } /*! * @brief write()メソッドのテスト * * - 手順を無視して write した場合 */ void test_write(void) { InPortCorbaCdrConsumerMock *consumer = new InPortCorbaCdrConsumerMock(); RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer(); PublisherNewMock 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"); 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)); // consumer not set check { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 101; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.setBuffer(buffer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 102; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET, publisher.write(cdr,0,0)); coil::usleep(10000); } // consumer set publisher.setConsumer(consumer); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 103; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } publisher.activate(); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 104; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } // 例外スローチェック : OK //consumer->set_m_mode(1); { cdrMemoryStream cdr; RTC::TimedLong td; td.data = 105; td >>= cdr; CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK, publisher.write(cdr,0,0)); coil::usleep(10000); } //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(10000); m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); m_OnCheck = 6; // CONNECTION_LOST:onReceiverError() publisher.write(cdr,0,0); coil::usleep(10000); delete consumer; delete buffer; } /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」>「Consumerのpush()メソッド処理時間」の場合に、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_large_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick * 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 10; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1509  //
1510  int len = consumer->get_m_put_data_len() -1;
1511  for(int icc(0);icc<len;++icc)
1512  {
1513  cdrMemoryStream data;
1514  data = consumer->get_m_put_data();
1515  CORBA::ULong inlen = data.bufSize();
1516  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1517  }
1518  //最新データが転送されていることを確認する。
1519  {
1520  cdrMemoryStream data;
1521  data = consumer->get_m_put_data();
1522  CORBA::ULong inlen = data.bufSize();
1523  CPPUNIT_ASSERT_EQUAL(12,(int)inlen);
1524 
1525  RTC::TimedLong rtd;
1526  rtd <<= data;
1527  CPPUNIT_ASSERT_EQUAL((long)7, (long)rtd.data);
1528  }
1529 
1530  coil::usleep(1000000); // ここは長めにしないと落ちます。
1531  publisher.deactivate();
1532  coil::usleep(1000000); // ここは長めにしないと落ちます。
1533  delete buffer;
1534  delete consumer;
1535  }
1541  void test_write(void)
1542  {
1543  InPortCorbaCdrConsumerMock *consumer
1545  RTC::CdrBufferBase* buffer = new RTC::CdrRingBuffer();
1546  PublisherNewMock publisher;
1547 
1549  prop.setProperty("publisher.push_policy","all");
1550  prop.setProperty("publisher.skip_count","0");
1551  prop.setProperty("thread_type","default");
1552  prop.setProperty("measurement.exec_time","enable");
1553  prop.setProperty("measurement.exec_count","0");
1554  prop.setProperty("measurement.period_time","enable");
1555  prop.setProperty("measurement.period_count","0");
1556  publisher.init(prop);
1557  coil::usleep(10000);
1558 
1559  //ConnectorInfo
1560  coil::vstring ports;
1561  RTC::ConnectorInfo info("name", "id", ports, prop);
1562 
1563  //ConnectorListeners
1565  new DataListener("ON_BUFFER_WRITE"), true);
1567  new DataListener("ON_BUFFER_FULL"), true);
1569  new DataListener("ON_BUFFER_WRITE_TIMEOUT"), true);
1571  new DataListener("ON_BUFFER_OVERWRITE"), true);
1573  new DataListener("ON_BUFFER_READ"), true);
1575  new DataListener("ON_SEND"), true);
1577  new DataListener("ON_RECEIVED"), true);
1579  new DataListener("ON_RECEIVER_FULL"), true);
1581  new DataListener("ON_RECEIVER_TIMEOUT"), true);
1583  new DataListener("ON_RECEIVER_ERROR"), true);
1584 
1585  // setListener
1586  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::INVALID_ARGS,
1587  publisher.setListener(info, 0));
1588  CPPUNIT_ASSERT_EQUAL(RTC::DataPortStatus::PORT_OK,
1589  publisher.setListener(info, &m_listeners));
1590 
1591  // consumer not set check
1592  {
1593  cdrMemoryStream cdr;
1594  RTC::TimedLong td;
1595  td.data = 101;
1596  td >>= cdr;
1597  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET,
1598  publisher.write(cdr,0,0));
1599  coil::usleep(10000);
1600  }
1601  publisher.setBuffer(buffer);
1602  {
1603  cdrMemoryStream cdr;
1604  RTC::TimedLong td;
1605  td.data = 102;
1606  td >>= cdr;
1607  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PRECONDITION_NOT_MET,
1608  publisher.write(cdr,0,0));
1609  coil::usleep(10000);
1610  }
1611 
1612  // consumer set
1613  publisher.setConsumer(consumer);
1614  {
1615  cdrMemoryStream cdr;
1616  RTC::TimedLong td;
1617  td.data = 103;
1618  td >>= cdr;
1619  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1620  publisher.write(cdr,0,0));
1621  coil::usleep(10000);
1622  }
1623  publisher.activate();
1624 
1625  {
1626  cdrMemoryStream cdr;
1627  RTC::TimedLong td;
1628  td.data = 104;
1629  td >>= cdr;
1630  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1631  publisher.write(cdr,0,0));
1632  coil::usleep(10000);
1633  }
1634 
1635  // 例外スローチェック : OK
1636  //consumer->set_m_mode(1);
1637  {
1638  cdrMemoryStream cdr;
1639  RTC::TimedLong td;
1640  td.data = 105;
1641  td >>= cdr;
1642  CPPUNIT_ASSERT_EQUAL(RTC::PublisherNew::PORT_OK,
1643  publisher.write(cdr,0,0));
1644  coil::usleep(10000);
1645  }
1646 
1647  //Listener callback check
1648  cdrMemoryStream cdr;
1649  RTC::TimedLong td;
1650  td.data = 777;
1651  td >>= cdr;
1652  //m_OnCheck = 1; // PORT_OK:onReceived()
1653  //publisher.write(cdr,0,0);
1654  //coil::usleep(10000);
1655  m_OnCheck = 2; // PORT_ERROR:onReceiverError()
1656  publisher.write(cdr,0,0);
1657  coil::usleep(10000);
1658  m_OnCheck = 3; // SEND_FULL:onReceiverFull()
1659  publisher.write(cdr,0,0);
1660  coil::usleep(10000);
1661  m_OnCheck = 4; // SEND_TIMEOUT:onReceiverTimeout()
1662  publisher.write(cdr,0,0);
1663  coil::usleep(10000);
1664  m_OnCheck = 5; // UNKNOWN_ERROR:onReceiverError()
1665  publisher.write(cdr,0,0);
1666  coil::usleep(10000);
1667  m_OnCheck = 6; // CONNECTION_LOST:onReceiverError()
1668  publisher.write(cdr,0,0);
1669  coil::usleep(10000);
1670 
1671  delete consumer;
1672  delete buffer;
1673 
1674  }
1682 /*
1683  void test_update_large_interval()
1684  {
1685  long sleepTick = 100000; // 0.1[sec]
1686  long intervalTick = sleepTick * 10;
1687 
1688  MockConsumer* consumer = new MockConsumer(sleepTick);
1689  coil::Properties prop;
1690  RTC::PublisherNew publisher(consumer, prop);
1691 
1692  for (int i = 0; i < 10; i++)
1693  {
1694  consumer->setDelayStartTime();
1695  publisher.update();
1696  coil::usleep(intervalTick);
1697  }
1698 
1699  // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1700  coil::usleep(5000000); // 5 [sec]
1701 
1702  // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか?
1703  // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、
1704  // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief update()メソッドのテスト * * - 「Publisherのupdate()メソッド呼出間隔」<「Consumerのpush()メソッド処理時間」の場合に、update()呼出が溜ってしまうことなく、update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? * * @attention リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、ここでの所定時間はテスト作成者の主観によるものに過ぎない。 */ /* void test_update_small_interval() { long sleepTick = 100000; // 0.1[sec] long intervalTick = sleepTick / 10; MockConsumer* consumer = new MockConsumer(sleepTick); coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); for (int i = 0; i < 1000; i++) { consumer->setDelayStartTime(); publisher.update(); coil::usleep(intervalTick); } // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1705  long permissibleDelay = sleepTick + 100000;
1706  const std::vector<long>& delayTicks = consumer->getDelayTicks();
1707  for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++)
1708  {
1709  //std::cout << "delay tick = " << delayTicks[i] << std::endl;
1710  CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay);
1711  }
1712  publisher.release();
1713  }
1714 */
1722 /*
1723  void test_update_small_interval()
1724  {
1725  long sleepTick = 100000; // 0.1[sec]
1726  long intervalTick = sleepTick / 10;
1727 
1728  MockConsumer* consumer = new MockConsumer(sleepTick);
1729  coil::Properties prop;
1730  RTC::PublisherNew publisher(consumer, prop);
1731 
1732  for (int i = 0; i < 1000; i++)
1733  {
1734  consumer->setDelayStartTime();
1735  publisher.update();
1736  coil::usleep(intervalTick);
1737  }
1738 
1739  // Consumer呼出が完了するであろうタイミングまで待つ coil::usleep(5000000); // 5 [sec] // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか? // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、 // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1740  coil::usleep(5000000); // 5 [sec]
1741 
1742  // update()呼出からpush()呼出までの時間間隔が、所定時間内に収まっているか?
1743  // (リアルタイム性が保証されているわけでもなく、仕様上も呼出までの時間を明記しているわけではないので、
1744  // ここでの所定時間はテスト作成者の主観によるものに過ぎない。) long permissibleDelay = sleepTick + 100000; const std::vector<long>& delayTicks = consumer->getDelayTicks(); for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++) { //std::cout << "delay tick = " << delayTicks[i] << std::endl; CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay); } publisher.release(); } */ /*! * @brief release()メソッドのテスト * * - release()メソッド呼出によりPublisherの動作を確実に停止できるか? */ /* void test_release() { MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec] coil::Properties prop; RTC::PublisherNew publisher(consumer, prop); // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1745  long permissibleDelay = sleepTick + 100000;
1746  const std::vector<long>& delayTicks = consumer->getDelayTicks();
1747  for (std::vector<long>::size_type i = 0; i < delayTicks.size(); i++)
1748  {
1749  //std::cout << "delay tick = " << delayTicks[i] << std::endl;
1750  CPPUNIT_ASSERT(delayTicks[i] < permissibleDelay);
1751  }
1752  publisher.release();
1753  }
1754 */
1755 
1761 /*
1762  void test_release()
1763  {
1764  MockConsumer* consumer = new MockConsumer(1000000); // 1 [sec]
1765  coil::Properties prop;
1766  RTC::PublisherNew publisher(consumer, prop);
1767 
1768  // update()を呼出して、Consumerを呼び出させる publisher.update(); coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1769  publisher.update();
1770  coil::usleep(3000000); // Consumerを呼出す時間を与える publisher.release(); CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); // 再度update()を呼出し、Consumerを呼出しうる時間を与える。 // (実際には、前段のrelease()によりPublisherが停止済みであり、 // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1771  publisher.release();
1772 
1773  CPPUNIT_ASSERT_EQUAL(1, consumer->getCount());
1774 
1775  // 再度update()を呼出し、Consumerを呼出しうる時間を与える。
1776  // (実際には、前段のrelease()によりPublisherが停止済みであり、
1777  // update()呼出は何ら影響を与えないことを予期している。) publisher.update(); coil::usleep(3000000); // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1778  publisher.update();
1779  coil::usleep(3000000);
1780 
1781  // Consumer呼出回数が変わっていないこと、つまりPublisherの動作が停止していることを確認する CPPUNIT_ASSERT_EQUAL(1, consumer->getCount()); } */ }; }; // namespace PublisherNew /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests); #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 // PublisherNew_cpp
1782  CPPUNIT_ASSERT_EQUAL(1, consumer->getCount());
1783  }
1784 */
1785 
1786  };
1787 }; // namespace PublisherNew
1788 
1789 /*
1790  * Register test suite
1791  */
1793 
1794 #ifdef LOCAL_MAIN
1795 int main(int argc, char* argv[])
1796 {
1797 
1798  FORMAT format = TEXT_OUT;
1799  int target = 0;
1800  std::string xsl;
1801  std::string ns;
1802  std::string fname;
1803  std::ofstream ofs;
1804 
1805  int i(1);
1806  while (i < argc)
1807  {
1808  std::string arg(argv[i]);
1809  std::string next_arg;
1810  if (i + 1 < argc) next_arg = argv[i + 1];
1811  else next_arg = "";
1812 
1813  if (arg == "--text") { format = TEXT_OUT; break; }
1814  if (arg == "--xml")
1815  {
1816  if (next_arg == "")
1817  {
1818  fname = argv[0];
1819  fname += ".xml";
1820  }
1821  else
1822  {
1823  fname = next_arg;
1824  }
1825  format = XML_OUT;
1826  ofs.open(fname.c_str());
1827  }
1828  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
1829  if ( arg == "--cerr" ) { target = 1; break; }
1830  if ( arg == "--xsl" )
1831  {
1832  if (next_arg == "") xsl = "default.xsl";
1833  else xsl = next_arg;
1834  }
1835  if ( arg == "--namespace" )
1836  {
1837  if (next_arg == "")
1838  {
1839  std::cerr << "no namespace specified" << std::endl;
1840  exit(1);
1841  }
1842  else
1843  {
1844  xsl = next_arg;
1845  }
1846  }
1847  ++i;
1848  }
1849  CppUnit::TextUi::TestRunner runner;
1850  if ( ns.empty() )
1851  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1852  else
1853  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1854  CppUnit::Outputter* outputter = 0;
1855  std::ostream* stream = target ? &std::cerr : &std::cout;
1856  switch ( format )
1857  {
1858  case TEXT_OUT :
1859  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
1860  break;
1861  case XML_OUT :
1862  std::cout << "XML_OUT" << std::endl;
1863  outputter = new CppUnit::XmlOutputter(&runner.result(),
1864  ofs, "shift_jis");
1865  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
1866  break;
1867  case COMPILER_OUT :
1868  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
1869  break;
1870  }
1871  runner.setOutputter(outputter);
1872  runner.run();
1873  return 0; // runner.run() ? 0 : 1;
1874 }
1875 #endif // MAIN
1876 #endif // PublisherNew_cpp
ConnectorListeners class.
void test_setBuffer(void)
setBuffer()メソッドのテスト
virtual ReturnCode setListener(ConnectorInfo &info, ConnectorListeners *listeners)
Set the listener.
int main(int argc, char **argv)
InPortCorbaCdrConsumer class.
virtual ReturnCode write(const cdrMemoryStream &data, unsigned long sec, unsigned long usec)
Write data.
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
virtual ReturnCode deactivate()
deactivation
void test_pushAll(void)
write(), pushAll() メソッドのテスト
void addListener(ConnectorDataListener *listener, bool autoclean)
Add the listener.
virtual ReturnCode setBuffer(CdrBufferBase *buffer)
Setting buffer pointer.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual ReturnCode init(coil::Properties &prop)
Initialization.
virtual bool isActive()
If publisher is active state.
void test_pushSkip_2(void)
write(), pushSkip() メソッドのテスト
RingBuffer< cdrMemoryStream > CdrRingBuffer
Definition: CdrRingBuffer.h:28
void test_pushNew(void)
pushNew()メソッドのテスト
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
virtual ReturnCode activate()
activation
std::vector< std::string > vstring
Definition: stringutil.h:37
CPPUNIT_TEST_SUITE_REGISTRATION(PublisherNew::PublisherNewTests)
ConnectorDataListenerHolder connectorData_[CONNECTOR_DATA_LISTENER_NUM]
ConnectorDataListenerType listener array The ConnectorDataListenerType listener is stored...
void test_activate_deactivate_isActive(void)
activate(),deactivate(),isActiveメソッドのテスト
virtual void setUp()
Test initialization.
virtual ReturnCode setConsumer(InPortConsumer *consumer)
Store InPort consumer.
ConnectorDataListenerT class.
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
NameValue and NVList utility functions.
CORBA sequence utility template functions.
void test_pushFifo_2(void)
write(), pushFifo() メソッドのテスト
void test_pushAll_2(void)
write(), pushAll() メソッドのテスト
::RTC::BufferStatus::Enum ReturnCode
prop
Organization::get_organization_property ();.
RingBuffer for CDR.
RTC::ConnectorListeners m_listeners
Class represents a set of properties.
Definition: Properties.h:101
void test_write(void)
write()メソッドのテスト
void test_pushSkip(void)
pushSklip()メソッドのテスト
void test_pushFifo(void)
pushFifo()メソッドのテスト
virtual ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
void test_init(void)
init()メソッドのテスト
InPortCorbaCdrConsumer class.
virtual void tearDown()
Test finalization.
bret
7 送受信データ比較
Definition: ConnectTest.py:377
PublisherNew class.
Definition: PublisherNew.h:69
void test_setConsumer(void)
setConsumer()メソッドのテスト
BufferBase abstract class.
Definition: BufferBase.h:104
InPortConsumer class.
connector listener class
PublisherNew class.
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