OutPortTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: OutPortTests.cpp,v $
14  * Revision 1.2 2008/02/19 08:13:36 arafune
15  * Some tests were added and orthogonalized.
16  *
17  * Revision 1.1 2007/12/20 07:50:18 arafune
18  * *** empty log message ***
19  *
20  * Revision 1.2 2006/12/02 18:52:54 n-ando
21  * Some tests were added.
22  *
23  * Revision 1.1 2006/11/29 04:26:28 n-ando
24  * CppUnit tests for OutPort.
25  *
26  *
27  */
28 
29 #ifndef OutPort_cpp
30 #define OutPort_cpp
31 
32 #include <cppunit/ui/text/TestRunner.h>
33 #include <cppunit/TextOutputter.h>
34 #include <cppunit/extensions/TestFactoryRegistry.h>
35 #include <cppunit/extensions/HelperMacros.h>
36 #include <cppunit/TestAssert.h>
37 
38 #include <rtm/idl/BasicDataTypeSkel.h>
39 #include <rtm/idl/DataPortSkel.h>
40 #include <rtm/DataPortStatus.h>
41 #include <rtm/OutPort.h>
42 #include <rtm/OutPortBase.h>
44 #include <rtm/InPort.h>
45 #include <rtm/CorbaConsumer.h>
46 
47 #define WTIMEOUT_USEC 1000000
48 #define USEC_PER_SEC 1000000
49 
54 namespace OutPort
55 {
60  template <class DataType>
62  : public RTC::OutPort<DataType>
63  {
64  public:
69  OutPortMock(const char* name, DataType& value)
70  : RTC::OutPort<DataType>(name, value)
71  {
72  }
77  virtual ~OutPortMock()
78  {
79  }
85  createConnector_public(RTC::ConnectorProfile& cprof,
88  {
89  return RTC::OutPort<DataType>::createConnector(cprof, prop, provider);
90  }
96  createConnector_public(RTC::ConnectorProfile& cprof,
98  RTC::InPortConsumer* consumer)
99  {
100  return RTC::OutPort<DataType>::createConnector(cprof, prop, consumer);
101  }
102  };
108  class Logger
109  {
110  public:
111  void log(const std::string& msg)
112  {
113  m_log.push_back(msg);
114  }
115 
116  int countLog(const std::string& msg)
117  {
118  int count = 0;
119 
120  for (int i = 0; i < (int) m_log.size(); ++i)
121  {
122  if (m_log[i] == msg) ++count;
123  }
124  return count;
125  }
126 
127  void clearLog(void)
128  {
129  m_log.clear();
130  }
131  private:
132  std::vector<std::string> m_log;
133  };
140  : public RTC::InPortConsumer,
141  public RTC::CorbaConsumer< ::OpenRTM::InPortCdr >
142  {
143 
144  public:
146  {
147  m_logger = NULL;
148  }
150  {
151  }
157  {
158  if (m_logger != NULL)
159  {
160  m_logger->log("InPortCorbaCdrConsumerMock::init");
161  }
162  }
167  RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
168  {
169  return PORT_OK;
170  }
176  {
177  return;
178  }
179 
185  {
186 
187  return true;;
188  }
189 
195  {
196  }
197 
198 
204  {
205  m_logger = logger;
206  }
207  private:
209 
210  };
217  : public RTC::OutPortProvider,
218  public virtual ::POA_OpenRTM::OutPortCdr,
219  public virtual PortableServer::RefCountServantBase
220  {
221 
222  public:
224  {
225  m_logger = NULL;
226  }
228  {
229  }
235  {
236  if (m_logger != NULL)
237  {
238  m_logger->log("OutPortCorbaCdrProviderMock::init");
239  }
240  }
245  virtual ::OpenRTM::PortStatus get(::OpenRTM::CdrData_out data)
246  {
247  return ::OpenRTM::PORT_OK;
248  }
253  RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
254  {
255  return PORT_OK;
256  }
262  {
263  return;
264  }
265 
271  {
272 
273  return true;;
274  }
275 
281  {
282  }
283 
284 
290  {
291  m_logger = logger;
292  }
293  private:
295 
296  };
297 /****
298  template <class DataType>
299  class FullBuffer
300  : public RTC::NullBuffer<DataType>
301  {
302  public:
303  FullBuffer(long int length) {};
304  virtual bool isFull() const
305  {
306  return true;
307  }
308  };
309 
310  template <class DataType>
311  class OnOverflowMock
312  : public RTC::OnOverflow<DataType>
313  {
314  public:
315  virtual void operator()(const DataType& value)
316  {
317  m_value = value;
318  }
319  DataType m_value;
320  };
321 ****/
322 
328  template <class DataType>
330  : public RTC::BufferBase<DataType>
331  {
332  public:
334  RingBufferMock(long int length = 8)
335  {
336  m_logger = NULL;
337  logger.log("RingBufferMock::Constructor");
338  m_read_return_value = BUFFER_OK;
339  m_readable_return_value = 0;
340 
341  }
342  virtual ~RingBufferMock(void)
343  {
344  }
345 
346 
352  {
353  m_read_return_value = value;
354  }
359  virtual void init(const coil::Properties& prop)
360  {
361  }
366  virtual size_t length(void) const
367  {
368  return 0;
369  }
374  virtual ReturnCode length(size_t n)
375  {
376  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
377  }
382  virtual ReturnCode reset()
383  {
384  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
385  }
390  virtual DataType* wptr(long int n = 0)
391  {
392  return &m_data;
393  }
398  virtual ReturnCode advanceWptr(long int n = 1)
399  {
400  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
401  }
406  virtual ReturnCode put(const DataType& value)
407  {
408  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
409  }
414  virtual ReturnCode write(const DataType& value,
415  long int sec = -1, long int nsec = -1)
416  {
417  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
418  }
423  virtual size_t writable() const
424  {
425  return 0;
426  }
431  virtual bool full(void) const
432  {
433  return true;
434  }
439  virtual DataType* rptr(long int n = 0)
440  {
441  return &m_data;
442  }
447  virtual ReturnCode advanceRptr(long int n = 1)
448  {
449  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
450  }
455  virtual ReturnCode get(DataType& value)
456  {
457  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
458  }
463  virtual DataType& get()
464  {
465  return m_data;
466  }
471  virtual ReturnCode read(DataType& value,
472  long int sec = -1, long int nsec = -1)
473  {
474  if (m_logger != NULL)
475  {
476  m_logger->log("RingBufferMock::read");
477  }
478  logger.log("RingBufferMock::read");
479  return m_read_return_value; //BUFFER_OK;
480  }
485  virtual size_t readable() const
486  {
487  return m_readable_return_value;
488  }
493  void set_readable_return_value(size_t value)
494  {
495  m_readable_return_value = value;
496  }
501  virtual bool empty(void) const
502  {
503  return true;
504  }
510  {
511  m_logger = logger;
512  }
513 
514  static Logger logger;
515  private:
516  DataType m_data;
517  std::vector<DataType> m_buffer;
521  };
522  template <class DataType>
531  : public RTC::PublisherBase
532  {
533  public:
535  {
536  m_logger = NULL;
537  }
539  {
540  }
545  RTC::PublisherBase::ReturnCode write(const cdrMemoryStream& data,
546  unsigned long sec,
547  unsigned long usec)
548  {
549  cdrMemoryStream cdr(data);
550  CORBA::ULong inlen = cdr.bufSize();
551 
552  CORBA::Octet oct[8];
553  cdr.get_octet_array (oct, (int)inlen);
554  long lval(0);
555  for(int ic(0);ic<(int)inlen;++ic)
556  {
557  lval = lval+(int)(oct[ic]<<(ic*8));
558  }
559  std::stringstream ss;
560  ss << lval;
561  if (m_logger != NULL)
562  {
563  m_logger->log("PublisherFlushMock::write");
564  m_logger->log(ss.str());
565  }
566  logger.log("PublisherFlushMock::write");
567  logger.log(ss.str());
568  return PORT_OK;
569  }
574  bool isActive()
575  {
576  return true;
577  }
578 
584  {
585  if (m_logger != NULL)
586  {
587  m_logger->log("PublisherFlushMock::activate");
588  }
589  logger.log("PublisherFlushMock::activate");
590  return PORT_OK;
591  }
592 
598  {
599  if (m_logger != NULL)
600  {
601  m_logger->log("PublisherFlushMock::deactivate");
602  }
603  logger.log("PublisherFlushMock::deactivate");
604  return PORT_OK;
605  }
611  {
612  return PORT_OK;
613  }
619  {
620  if (m_logger != NULL)
621  {
622  m_logger->log("PublisherFlushMock::setConsumer");
623  }
624  logger.log("PublisherFlushMock::setConsumer");
625  return PORT_OK;
626  }
627 
633  {
634  if (m_logger != NULL)
635  {
636  m_logger->log("PublisherFlushMock::setBuffer");
637  if(buffer == NULL)
638  {
639  m_logger->log("buffer NG");
640  }
641  else
642  {
643  m_logger->log("buffer OK");
644  }
645  }
646  logger.log("PublisherFlushMock::setBuffer");
647  if(buffer == NULL)
648  {
649  logger.log("buffer NG");
650  }
651  else
652  {
653  logger.log("buffer OK");
654  }
655  return PORT_OK;
656  }
657 
663  RTC::ConnectorListeners* listeners)
664  {
665  if (m_logger != NULL)
666  {
667  m_logger->log("PublisherFlushMock::setListener");
668  if (listeners == 0)
669  {
670  m_logger->log("listeners NG");
671  }
672  else
673  {
674  m_logger->log("listeners OK");
675  }
676  }
677  logger.log("PublisherFlushMock::setListener");
678  if (listeners == 0)
679  {
680  logger.log("listeners NG");
681  }
682  else
683  {
684  logger.log("listeners OK");
685  }
686  return PORT_OK;
687  }
688 
694  {
695  m_logger = logger;
696  }
697  static Logger logger;
698  private:
700  };
702 
703 };
711 namespace RTC
712 {
734  OutPortPushConnector::OutPortPushConnector(ConnectorInfo info,
735  InPortConsumer* consumer,
736  ConnectorListeners& listeners,
737  CdrBufferBase* buffer)
738  : OutPortConnector(info),
739  m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer)
740  {
741 
742  }
751  {
752  }
761  {
762  return PORT_OK;
763  }
769  {
770  return m_buffer;
771  }
780  OutPortPushConnector::write(const cdrMemoryStream& data)
781  {
782  RTC_logger.log("OutPortPushConnector::write");
783  RTC::TimedDouble td;
784  cdrMemoryStream cdr(data);
785  td <<= cdr;
786  std::ostringstream os;
787  os<<td.data;
788  RTC_logger.log(os.str());
789 // ::CORBA::Any any;
790 // any <<= cdr;
791 // std::cout<<any.type()->kind()<<std::endl;
792 
794  }
800  {
801  }
807  {
808  }
814  {
816  }
822  {
823  return new ::OutPort::PublisherFlushMock();
824  }
825 
826 
827 
835  Manager* Manager::manager = NULL;
842  : m_initProc(NULL),
844  m_runner(NULL), m_terminator(NULL)
845  {
846  }
852  {
853  // DCL for singleton
854  if (!manager)
855  {
856  Guard guard(mutex);
857  if (!manager)
858  {
859  manager = new Manager();
860  manager->initORB();
861  }
862  }
863  return *manager;
864  }
869  CORBA::ORB_ptr Manager::getORB()
870  {
871  return m_pORB;
872  }
877  bool Manager::initORB()
878  {
879  // Initialize ORB
880  try
881  {
882  std::vector<std::string> args(coil::split(NULL, " "));
883  // TAO's ORB_init needs argv[0] as command name.
884  args.insert(args.begin(), "manager");
885  char** argv = coil::toArgv(args);
886  int argc(args.size());
887 
888  // ORB initialization
889  m_pORB = CORBA::ORB_init(argc, argv);
890  // Get the RootPOA
891  CORBA::Object_var obj = m_pORB->resolve_initial_references("RootPOA");
892  PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(obj);
893  CORBA::PolicyList policies;
894  policies.length(2);
895  policies[(CORBA::ULong)0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
896  policies[(CORBA::ULong)1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
897  PortableServer::POAManager_var rootManager = rootPOA->the_POAManager();
898  m_pPOA = rootPOA->create_POA("persistent", rootManager, policies);
899  if (CORBA::is_nil(m_pPOA))
900  {
901  return false;
902  }
903  // Get the POAManager
904  m_pPOAManager = m_pPOA->the_POAManager();
905  }
906  catch (...)
907  {
908  RTC_ERROR(("Exception: Caught unknown exception in initORB()." ));
909  return false;
910  }
911  return true;
912  }
913 
922  const char* Logger::m_levelString[] =
923  {
924  " SILENT: ",
925  " FATAL: ",
926  " ERROR: ",
927  " WARNING: ",
928  " INFO: ",
929  " DEBUG: ",
930  " TRACE: ",
931  " VERBOSE: ",
932  " PARANOID: "
933  };
934 
935  Logger::Logger(const char* name)
936  : ::coil::LogStream(&m_logStreamBuf, 0, 8, 0)
937  {
938  }
939 
940  Logger::Logger(LogStreamBuf* streambuf)
941  : ::coil::LogStream(&m_logStreamBuf, 0, 8, 0)
942  {
943  }
944 
945  Logger::~Logger(void)
946  {
947  }
948 
956  bool Logger::setLevel(const char* level)
957  {
958  return true;
959  }
960 
968  void Logger::setDateFormat(const char* format)
969  {
970  }
971 
979  void Logger::setName(const char* name)
980  {
981  }
982 
990  void Logger::header(int level)
991  {
992  }
993 
1001  std::string Logger::getDate(void)
1002  {
1003  const int maxsize = 256;
1004  char buf[maxsize];
1005 
1006  return std::string(buf);
1007  }
1008 
1016  int Logger::strToLevel(const char* level)
1017  {
1018  return 0;
1019  }
1028  {
1029  }
1030 
1032  {
1033  }
1034 
1036  {
1037  }
1038 
1047  {
1048  NVUtil::appendStringValue(prop, "dataport.interface_type",
1049  m_interfaceType.c_str());
1050  NVUtil::append(prop, m_properties);
1051  }
1052 
1061  {
1062 
1063  if (!NVUtil::isStringValue(prop,
1064  "dataport.interface_type",
1065  m_interfaceType.c_str()))
1066  {
1067  return false;
1068  }
1069 
1070  NVUtil::append(prop, m_properties);
1071  return true;
1072  }
1073 
1081  void OutPortProvider::setPortType(const char* port_type)
1082  {
1083  m_portType = port_type;
1084  }
1085 
1093  void OutPortProvider::setDataType(const char* data_type)
1094  {
1095  m_dataType = data_type;
1096  }
1097 
1105  void OutPortProvider::setInterfaceType(const char* interface_type)
1106  {
1107  m_interfaceType = interface_type;
1108  }
1109 
1117  void OutPortProvider::setDataFlowType(const char* dataflow_type)
1118  {
1119  m_dataflowType = dataflow_type;
1120  }
1121 
1129  void OutPortProvider::setSubscriptionType(const char* subs_type)
1130  {
1131  m_subscriptionType = subs_type;
1132  }
1133 
1134 
1135 }; // namespace RTC
1143 namespace OutPort
1144 {
1150  template <class DataType>
1152  : public RTC::OnWrite<DataType>
1153  {
1154  public:
1160  {
1161  m_logger = NULL;
1162  }
1167  virtual void operator()(const DataType& value)
1168  {
1169  m_value = value;
1170  if (m_logger != NULL)
1171  {
1172  m_logger->log("OnWriteMock::operator");
1173  }
1174  }
1175  DataType m_value;
1181  {
1182  m_logger = logger;
1183  }
1184  private:
1186  };
1191  template <class DataType>
1193  : public RTC::OnWriteConvert<DataType>
1194  {
1195  public:
1200  OnWriteConvertMock(RTC::TimedDouble amplitude)
1201  : m_amplitude(amplitude)
1202  {
1203  m_logger = NULL;
1204  }
1209  virtual DataType operator()(const DataType& value)
1210  {
1211  DataType td;
1212  td.data = m_amplitude.data * value.data;
1213  if (m_logger != NULL)
1214  {
1215  m_logger->log("OnWriteConvertMock::operator");
1216  }
1217  return td;
1218  }
1219  RTC::TimedDouble m_amplitude;
1225  {
1226  m_logger = logger;
1227  }
1228  private:
1230  };
1236  : public CppUnit::TestFixture
1237  {
1238  CPPUNIT_TEST_SUITE(OutPortTests);
1239  CPPUNIT_TEST(test_write); // include onWrite and OnWriteConver
1240 /*
1241  CPPUNIT_TEST(test_write_OnWrite);
1242  CPPUNIT_TEST(test_write_OnWriteConvert);
1243  CPPUNIT_TEST(test_write_OnWrite_full);
1244  CPPUNIT_TEST(test_write_OnOverflow);
1245  CPPUNIT_TEST(test_write_OnOverflow_not_full);
1246  CPPUNIT_TEST(test_write_timeout);
1247 */
1248  CPPUNIT_TEST_SUITE_END();
1249 
1250  private:
1251  CORBA::ORB_ptr m_pORB;
1252  PortableServer::POA_ptr m_pPOA;
1254 
1255  public:
1256 
1261  {
1262  int argc(0);
1263  char** argv(NULL);
1264  m_pORB = CORBA::ORB_init(argc, argv);
1265  m_pPOA = PortableServer::POA::_narrow(
1266  m_pORB->resolve_initial_references("RootPOA"));
1267  m_pPOA->the_POAManager()->activate();
1268  m_logger = NULL;
1269 
1270  }
1271 
1276  {
1277  }
1278 
1282  virtual void setUp()
1283  {
1284  }
1285 
1289  virtual void tearDown()
1290  {
1291  }
1292 
1297  void test_write(void)
1298  {
1299  RTC::TimedDouble td;
1300  td.data = 123;
1301  OutPortMock<RTC::TimedDouble> outport("testi_write0",td);
1302 
1304  Logger logger;
1305  onWrite.setLogger(&logger);
1306  outport.setOnWrite(&onWrite);
1307 
1308  bool ret;
1309  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnWriteMock::operator"));
1310  ret = outport.write();
1311  //no connectors was return false
1312  CPPUNIT_ASSERT_EQUAL(false, ret);
1313  CPPUNIT_ASSERT_EQUAL(1,logger.countLog("OnWriteMock::operator"));
1314 
1315  RTC::ConnectorProfile prof;
1316  coil::Properties prop(outport.properties());
1318  RTC::OutPortConnector* connector
1319  = outport.createConnector_public(prof, prop, consumer);
1320  CPPUNIT_ASSERT(0!= connector);
1321  //
1322  //
1323  //
1324  RTC::TimedDouble amplitude;
1325 // amplitude.data = 1.41421356;
1326  amplitude.data = 1;
1327  OnWriteConvertMock<RTC::TimedDouble> onWriteConvert(amplitude);
1328  onWriteConvert.setLogger(&logger);
1329 
1332  int logcount;
1333  int writedatacount;
1334 
1335  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnWriteConvertMock::operator"));
1336  logcount = ::RTC::RTC_logger.countLog("OntPortPushConnector::write");
1337  ret = outport.write();
1338  //data read succeeded
1339  CPPUNIT_ASSERT_EQUAL(true, ret);
1340  CPPUNIT_ASSERT_EQUAL(logcount+1,
1341  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1342  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnReadConvertMock::operator"));
1343 
1344  outport.setOnWriteConvert(&onWriteConvert);
1345  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnReadConvertMock::operator"));
1346  logcount = ::RTC::RTC_logger.countLog("OutPortPushConnector::write");
1347  ret = outport.write();
1348  //data read succeeded
1349  CPPUNIT_ASSERT_EQUAL(true, ret);
1350  CPPUNIT_ASSERT_EQUAL(logcount+1,
1351  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1352  CPPUNIT_ASSERT_EQUAL(1,logger.countLog("OnWriteConvertMock::operator"));
1353 
1354  //
1355  //
1356  //
1359  outport.setOnWrite(&onWrite);
1360 
1361  logcount = ::RTC::RTC_logger.countLog("OutPortPushConnector::write");
1362  writedatacount = ::RTC::RTC_logger.countLog("123");
1363  ret = outport.write();
1364  //data read succeeded
1365  CPPUNIT_ASSERT_EQUAL(true, ret);
1366  CPPUNIT_ASSERT_EQUAL(logcount+1,
1367  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1368  CPPUNIT_ASSERT_EQUAL(writedatacount+1,
1369  ::RTC::RTC_logger.countLog("123"));
1370  //
1371  //
1372  //
1373 /*** check OK
1374  RTC::OutPortPushConnector_write_return_value
1375  = RTC::ConnectorBase::PRECONDITION_NOT_MET;
1376  logcount = ::RTC::RTC_logger.countLog("OutPortPushConnector::write");
1377  ret = outport.write();
1378  //data read succeeded
1379  CPPUNIT_ASSERT_EQUAL(false, ret);
1380  CPPUNIT_ASSERT_EQUAL(logcount+1,
1381  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1382 ***/
1383 
1384  //
1385  //
1386  //
1387 /*** check OK
1388  RTC::OutPortPushConnector_write_return_value
1389  = RTC::ConnectorBase::CONNECTION_LOST;
1390  logcount = ::RTC::RTC_logger.countLog("OutPortPushConnector::write");
1391  ret = outport.write();
1392  //data read succeeded
1393  CPPUNIT_ASSERT_EQUAL(false, ret);
1394  CPPUNIT_ASSERT_EQUAL(logcount+1,
1395  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1396 ***/
1397 
1398  //
1399  //
1400  //
1401 /*** check OK
1402  RTC::OutPortPushConnector_write_return_value
1403  = RTC::ConnectorBase::BUFFER_FULL;
1404  logcount = ::RTC::RTC_logger.countLog("OutPortPushConnector::write");
1405  ret = outport.write();
1406  //data read succeeded
1407  CPPUNIT_ASSERT_EQUAL(false, ret);
1408  CPPUNIT_ASSERT_EQUAL(logcount+1,
1409  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1410 ***/
1411 
1412  //
1413  //
1414  //
1415 
1416  RTC::OutPortPushConnector_write_return_value
1418 
1419  outport.setOnWrite(&onWrite);
1420 
1421  logcount = ::RTC::RTC_logger.countLog("OutPortPushConnector::write");
1422  writedatacount = ::RTC::RTC_logger.countLog("55");
1423  RTC::TimedDouble doublevalue;
1424  doublevalue.data = 55;
1425 
1426  ret = outport.write(doublevalue);
1427  //data write succeeded
1428  CPPUNIT_ASSERT_EQUAL(true, ret);
1429  CPPUNIT_ASSERT_EQUAL(logcount+1,
1430  ::RTC::RTC_logger.countLog("OutPortPushConnector::write"));
1431  CPPUNIT_ASSERT_EQUAL(writedatacount+1,
1432  ::RTC::RTC_logger.countLog("55"));
1433 
1434  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&outport));
1435  delete consumer;
1436  }
1437 
1444  {
1445  RTC::TimedDouble bindValue;
1447  = new OutPortMock<RTC::TimedDouble>("OutPort", bindValue);
1448 
1449 
1451  onWrite.m_value.data = 0;
1452  outPort->setOnWrite(&onWrite);
1453 
1454  // write()メソッドは成功するか?
1455  RTC::TimedDouble writeValue;
1456  writeValue.data = 3.14159265;
1457  CPPUNIT_ASSERT(outPort->write(writeValue));
1458 
1459  // あらかじめ設定されたOnWriteコールバックが正しく呼び出されたか?
1460  CPPUNIT_ASSERT_EQUAL(writeValue.data, onWrite.m_value.data);
1461 
1462  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(outPort));
1463  delete outPort;
1464  }
1465 
1472  {
1473  RTC::TimedDouble bindValue;
1475  = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue);
1476 
1478  onWrite.m_value.data = 0;
1479  outPort->setOnWrite(&onWrite);
1480 
1481  RTC::PortService_var oportref = outPort->get_port_profile()->port_ref;
1482 
1483  RTC::TimedDouble InbindValue;
1485  = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue);
1486 
1487  coil::Properties dummy;
1488  inPort->init(dummy);
1489  RTC::PortService_var iportref = inPort->get_port_profile()->port_ref;
1490 
1491  RTC::ConnectorProfile prof;
1492  prof.connector_id = "";
1493  prof.name = CORBA::string_dup("connector0");
1494  prof.ports.length(2);
1495  prof.ports[0] = oportref;
1496  prof.ports[1] = iportref;
1497 
1498  CORBA_SeqUtil::push_back(prof.properties,
1499  NVUtil::newNV("dataport.interface_type",
1500  "corba_cdr"));
1501 
1502  CORBA_SeqUtil::push_back(prof.properties,
1503  NVUtil::newNV("dataport.dataflow_type",
1504  "push"));
1505  CORBA_SeqUtil::push_back(prof.properties,
1506  NVUtil::newNV("dataport.subscription_type",
1507  "new"));
1508  inPort->connect(prof);
1509 
1510  // バッファフルによりwrite()メソッドは意図どおり失敗するか?
1511  RTC::TimedDouble writeValue;
1512  writeValue.data = 3.14159265;
1513  for(int ic(0);ic<8;++ic)
1514  {
1515  outPort->write(writeValue);
1516  }
1517  CPPUNIT_ASSERT(! outPort->write(writeValue));
1518 
1519  // あらかじめ設定されたOnWriteコールバックが正しく呼び出されたか?
1520  CPPUNIT_ASSERT_EQUAL(writeValue.data, onWrite.m_value.data);
1521  delete inPort;
1522  delete outPort;
1523  }
1524 
1531  {
1532  // 常にフル状態であるバッファを用いてOutPortオブジェクトを生成する RTC::TimedDouble bindValue; RTC::OutPort<RTC::TimedDouble>* outPort = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue); // OnOverflowMock<RTC::TimedDouble> onOverflow; // onOverflow.m_value.data = 0; // outPort->setOnOverflow(&onOverflow); RTC::PortService_var oportref = outPort->get_port_profile()->port_ref; RTC::TimedDouble InbindValue; RTC::InPort<RTC::TimedDouble>* inPort = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue); coil::Properties dummy; inPort->init(dummy); RTC::PortService_var iportref = inPort->get_port_profile()->port_ref; RTC::ConnectorProfile prof; prof.connector_id = ""; prof.name = CORBA::string_dup("connector0"); prof.ports.length(2); prof.ports[0] = oportref; prof.ports[1] = iportref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); inPort->connect(prof); // バッファフルによりwrite()メソッドは意図どおり失敗するか? RTC::TimedDouble writeValue; writeValue.data = 3.14159265; for(int ic(0);ic<8;++ic) { outPort->write(writeValue); } CPPUNIT_ASSERT(! outPort->write(writeValue)); // OutPortに割り当てされたバッファがフルの場合に、あらかじめ設定されたOnOverflowコールバックが正しく呼び出されたか? // CPPUNIT_ASSERT_EQUAL(writeValue.data, onOverflow.m_value.data); delete inPort; delete outPort; } /*! * @brief バッファフルでない時の、write()メソッドのOnOverflowコールバック呼出テスト * * - バッファフルでない場合、OnOverflowコールバックが意図どおり未呼出のままか? */ void test_write_OnOverflow_not_full() { RTC::TimedDouble bindValue; RTC::OutPort<RTC::TimedDouble>* outPort = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue); // OnOverflowMock<RTC::TimedDouble> onOverflow; // onOverflow.m_value.data = 0; // outPort->setOnOverflow(&onOverflow); RTC::PortService_var oportref = outPort->get_port_profile()->port_ref; RTC::TimedDouble InbindValue; RTC::InPort<RTC::TimedDouble>* inPort = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue); coil::Properties dummy; inPort->init(dummy); RTC::PortService_var iportref = inPort->get_port_profile()->port_ref; RTC::ConnectorProfile prof; prof.connector_id = ""; prof.name = CORBA::string_dup("connector0"); prof.ports.length(2); prof.ports[0] = oportref; prof.ports[1] = iportref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); inPort->connect(prof); // write()メソッドは成功するか? RTC::TimedDouble writeValue; writeValue.data = 3.14159265; CPPUNIT_ASSERT(outPort->write(writeValue)); // バッファフルでない場合、OnOverflowコールバックが意図どおり未呼出のままか? // CPPUNIT_ASSERT_EQUAL((double) 0, onOverflow.m_value.data); delete inPort; delete outPort; } void test_write_OnWriteConvert() { RTC::TimedDouble bindValue; OutPortMock<RTC::TimedDouble>* outPort = new OutPortMock<RTC::TimedDouble>("OutPort", bindValue); RTC::ConnectorProfile prof; coil::Properties prop(outPort->properties()); RTC::InPortConsumer* consumer = new InPortCorbaCdrConsumerMock(); RTC::OutPortConnector* connector = outPort->createConnector_public(prof, prop, consumer); RTC::TimedDouble amplitude; amplitude.data = 1.41421356; OnWriteConvertMock<RTC::TimedDouble> onWriteConvert(amplitude); outPort->setOnWriteConvert(&onWriteConvert); for (int i = 0; i < 100; ++i) { RTC::TimedDouble writeValue; writeValue.data = i * 3.14159265; RTC::TimedDouble expectedValue; expectedValue.data = amplitude.data * writeValue.data; std::ostringstream os; os << expectedValue.data; int logcount; logcount = ::RTC::RTC_logger.countLog(os.str()); CPPUNIT_ASSERT(outPort->write(writeValue)); CPPUNIT_ASSERT_EQUAL(logcount+1, ::RTC::RTC_logger.countLog(os.str())); } m_pPOA->deactivate_object(*m_pPOA->servant_to_id(outPort)); delete consumer; delete outPort; } /*! * @brief write()メソッドのタイムアウト処理テスト * * - OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトするか? * - OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? */ void test_write_timeout() { // 常にフル状態であるバッファを用いてOutPortオブジェクトを生成する RTC::TimedDouble bindValue; RTC::OutPort<RTC::TimedDouble>* outPort = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue); RTC::PortService_var oportref = outPort->get_port_profile()->port_ref; RTC::TimedDouble InbindValue; RTC::InPort<RTC::TimedDouble>* inPort = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue); coil::Properties dummy; inPort->init(dummy); RTC::PortService_var iportref = inPort->get_port_profile()->port_ref; RTC::ConnectorProfile prof; prof.connector_id = ""; prof.name = CORBA::string_dup("connector0"); prof.ports.length(2); prof.ports[0] = oportref; prof.ports[1] = iportref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); inPort->connect(prof); // OutPortオブジェクトに対して、ブロッキングモードONを指定する // outPort->setWriteBlock(true); // OutPortオブジェクトに対して、タイムアウト値を指定する // outPort->setWriteTimeout(WTIMEOUT_USEC); timeval tm_pre; gettimeofday(&tm_pre, 0); for(int ic(0);ic<8;++ic) { RTC::TimedDouble writeValue; writeValue.data = 3.14159265; outPort->write(writeValue); } for (int i = 0; i < 10; ++i) { RTC::TimedDouble writeValue; writeValue.data = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! outPort->write(writeValue)); // OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトしているか? timeval tm_cur; gettimeofday(&tm_cur, 0); timeval tm_diff; timersub(&tm_cur, &tm_pre, &tm_diff); double interval = (double) tm_diff.tv_sec + (double) tm_diff.tv_usec / USEC_PER_SEC; tm_pre = tm_cur; CPPUNIT_ASSERT_DOUBLES_EQUAL( (double) WTIMEOUT_USEC / USEC_PER_SEC, interval, 0.1 * WTIMEOUT_USEC/USEC_PER_SEC); } delete inPort; delete outPort; } }; }; // namespace OutPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPort::OutPortTests); #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 // OutPort_cpp
1533  RTC::TimedDouble bindValue;
1535  = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue);
1536 
1537 // OnOverflowMock<RTC::TimedDouble> onOverflow;
1538 // onOverflow.m_value.data = 0;
1539 // outPort->setOnOverflow(&onOverflow);
1540 
1541  RTC::PortService_var oportref = outPort->get_port_profile()->port_ref;
1542  RTC::TimedDouble InbindValue;
1544  = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue);
1545 
1546  coil::Properties dummy;
1547  inPort->init(dummy);
1548  RTC::PortService_var iportref = inPort->get_port_profile()->port_ref;
1549 
1550  RTC::ConnectorProfile prof;
1551  prof.connector_id = "";
1552  prof.name = CORBA::string_dup("connector0");
1553  prof.ports.length(2);
1554  prof.ports[0] = oportref;
1555  prof.ports[1] = iportref;
1556 
1557  CORBA_SeqUtil::push_back(prof.properties,
1558  NVUtil::newNV("dataport.interface_type",
1559  "corba_cdr"));
1560 
1561  CORBA_SeqUtil::push_back(prof.properties,
1562  NVUtil::newNV("dataport.dataflow_type",
1563  "push"));
1564  CORBA_SeqUtil::push_back(prof.properties,
1565  NVUtil::newNV("dataport.subscription_type",
1566  "new"));
1567  inPort->connect(prof);
1568 
1569  // バッファフルによりwrite()メソッドは意図どおり失敗するか?
1570  RTC::TimedDouble writeValue;
1571  writeValue.data = 3.14159265;
1572  for(int ic(0);ic<8;++ic)
1573  {
1574  outPort->write(writeValue);
1575  }
1576  CPPUNIT_ASSERT(! outPort->write(writeValue));
1577 
1578  // OutPortに割り当てされたバッファがフルの場合に、あらかじめ設定されたOnOverflowコールバックが正しく呼び出されたか?
1579 // CPPUNIT_ASSERT_EQUAL(writeValue.data, onOverflow.m_value.data);
1580  delete inPort;
1581  delete outPort;
1582  }
1583 
1590  {
1591  RTC::TimedDouble bindValue;
1593  = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue);
1594 
1595 // OnOverflowMock<RTC::TimedDouble> onOverflow;
1596 // onOverflow.m_value.data = 0;
1597 // outPort->setOnOverflow(&onOverflow);
1598 
1599  RTC::PortService_var oportref = outPort->get_port_profile()->port_ref;
1600 
1601  RTC::TimedDouble InbindValue;
1603  = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue);
1604 
1605  coil::Properties dummy;
1606  inPort->init(dummy);
1607  RTC::PortService_var iportref = inPort->get_port_profile()->port_ref;
1608 
1609  RTC::ConnectorProfile prof;
1610  prof.connector_id = "";
1611  prof.name = CORBA::string_dup("connector0");
1612  prof.ports.length(2);
1613  prof.ports[0] = oportref;
1614  prof.ports[1] = iportref;
1615 
1616  CORBA_SeqUtil::push_back(prof.properties,
1617  NVUtil::newNV("dataport.interface_type",
1618  "corba_cdr"));
1619 
1620  CORBA_SeqUtil::push_back(prof.properties,
1621  NVUtil::newNV("dataport.dataflow_type",
1622  "push"));
1623  CORBA_SeqUtil::push_back(prof.properties,
1624  NVUtil::newNV("dataport.subscription_type",
1625  "new"));
1626  inPort->connect(prof);
1627  // write()メソッドは成功するか?
1628  RTC::TimedDouble writeValue;
1629  writeValue.data = 3.14159265;
1630  CPPUNIT_ASSERT(outPort->write(writeValue));
1631 
1632  // バッファフルでない場合、OnOverflowコールバックが意図どおり未呼出のままか?
1633 // CPPUNIT_ASSERT_EQUAL((double) 0, onOverflow.m_value.data);
1634  delete inPort;
1635  delete outPort;
1636  }
1637 
1638 
1640  {
1641  RTC::TimedDouble bindValue;
1643  = new OutPortMock<RTC::TimedDouble>("OutPort", bindValue);
1644 
1645  RTC::ConnectorProfile prof;
1646  coil::Properties prop(outPort->properties());
1648  RTC::OutPortConnector* connector
1649  = outPort->createConnector_public(prof, prop, consumer);
1650 
1651  RTC::TimedDouble amplitude;
1652  amplitude.data = 1.41421356;
1653  OnWriteConvertMock<RTC::TimedDouble> onWriteConvert(amplitude);
1654  outPort->setOnWriteConvert(&onWriteConvert);
1655 
1656  for (int i = 0; i < 100; ++i)
1657  {
1658  RTC::TimedDouble writeValue;
1659  writeValue.data = i * 3.14159265;
1660  RTC::TimedDouble expectedValue;
1661  expectedValue.data = amplitude.data * writeValue.data;
1662 
1663  std::ostringstream os;
1664  os << expectedValue.data;
1665  int logcount;
1666  logcount = ::RTC::RTC_logger.countLog(os.str());
1667  CPPUNIT_ASSERT(outPort->write(writeValue));
1668  CPPUNIT_ASSERT_EQUAL(logcount+1,
1669  ::RTC::RTC_logger.countLog(os.str()));
1670 
1671 
1672  }
1673  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(outPort));
1674  delete consumer;
1675  delete outPort;
1676  }
1677 
1678 
1686  {
1687  // 常にフル状態であるバッファを用いてOutPortオブジェクトを生成する RTC::TimedDouble bindValue; RTC::OutPort<RTC::TimedDouble>* outPort = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue); RTC::PortService_var oportref = outPort->get_port_profile()->port_ref; RTC::TimedDouble InbindValue; RTC::InPort<RTC::TimedDouble>* inPort = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue); coil::Properties dummy; inPort->init(dummy); RTC::PortService_var iportref = inPort->get_port_profile()->port_ref; RTC::ConnectorProfile prof; prof.connector_id = ""; prof.name = CORBA::string_dup("connector0"); prof.ports.length(2); prof.ports[0] = oportref; prof.ports[1] = iportref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); inPort->connect(prof); // OutPortオブジェクトに対して、ブロッキングモードONを指定する // outPort->setWriteBlock(true); // OutPortオブジェクトに対して、タイムアウト値を指定する // outPort->setWriteTimeout(WTIMEOUT_USEC); timeval tm_pre; gettimeofday(&tm_pre, 0); for(int ic(0);ic<8;++ic) { RTC::TimedDouble writeValue; writeValue.data = 3.14159265; outPort->write(writeValue); } for (int i = 0; i < 10; ++i) { RTC::TimedDouble writeValue; writeValue.data = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! outPort->write(writeValue)); // OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトしているか? timeval tm_cur; gettimeofday(&tm_cur, 0); timeval tm_diff; timersub(&tm_cur, &tm_pre, &tm_diff); double interval = (double) tm_diff.tv_sec + (double) tm_diff.tv_usec / USEC_PER_SEC; tm_pre = tm_cur; CPPUNIT_ASSERT_DOUBLES_EQUAL( (double) WTIMEOUT_USEC / USEC_PER_SEC, interval, 0.1 * WTIMEOUT_USEC/USEC_PER_SEC); } delete inPort; delete outPort; } }; }; // namespace OutPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPort::OutPortTests); #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 // OutPort_cpp
1688  RTC::TimedDouble bindValue;
1690  = new RTC::OutPort<RTC::TimedDouble>("OutPort", bindValue);
1691 
1692  RTC::PortService_var oportref = outPort->get_port_profile()->port_ref;
1693 
1694  RTC::TimedDouble InbindValue;
1696  = new RTC::InPort<RTC::TimedDouble>("InPort", InbindValue);
1697 
1698  coil::Properties dummy;
1699  inPort->init(dummy);
1700  RTC::PortService_var iportref = inPort->get_port_profile()->port_ref;
1701 
1702  RTC::ConnectorProfile prof;
1703  prof.connector_id = "";
1704  prof.name = CORBA::string_dup("connector0");
1705  prof.ports.length(2);
1706  prof.ports[0] = oportref;
1707  prof.ports[1] = iportref;
1708 
1709  CORBA_SeqUtil::push_back(prof.properties,
1710  NVUtil::newNV("dataport.interface_type",
1711  "corba_cdr"));
1712 
1713  CORBA_SeqUtil::push_back(prof.properties,
1714  NVUtil::newNV("dataport.dataflow_type",
1715  "push"));
1716  CORBA_SeqUtil::push_back(prof.properties,
1717  NVUtil::newNV("dataport.subscription_type",
1718  "new"));
1719  inPort->connect(prof);
1720 
1721  // OutPortオブジェクトに対して、ブロッキングモードONを指定する// outPort->setWriteBlock(true); // OutPortオブジェクトに対して、タイムアウト値を指定する // outPort->setWriteTimeout(WTIMEOUT_USEC); timeval tm_pre; gettimeofday(&tm_pre, 0); for(int ic(0);ic<8;++ic) { RTC::TimedDouble writeValue; writeValue.data = 3.14159265; outPort->write(writeValue); } for (int i = 0; i < 10; ++i) { RTC::TimedDouble writeValue; writeValue.data = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! outPort->write(writeValue)); // OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトしているか? timeval tm_cur; gettimeofday(&tm_cur, 0); timeval tm_diff; timersub(&tm_cur, &tm_pre, &tm_diff); double interval = (double) tm_diff.tv_sec + (double) tm_diff.tv_usec / USEC_PER_SEC; tm_pre = tm_cur; CPPUNIT_ASSERT_DOUBLES_EQUAL( (double) WTIMEOUT_USEC / USEC_PER_SEC, interval, 0.1 * WTIMEOUT_USEC/USEC_PER_SEC); } delete inPort; delete outPort; } }; }; // namespace OutPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPort::OutPortTests); #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 // OutPort_cpp
1722 // outPort->setWriteBlock(true);
1723 
1724  // OutPortオブジェクトに対して、タイムアウト値を指定する// outPort->setWriteTimeout(WTIMEOUT_USEC); timeval tm_pre; gettimeofday(&tm_pre, 0); for(int ic(0);ic<8;++ic) { RTC::TimedDouble writeValue; writeValue.data = 3.14159265; outPort->write(writeValue); } for (int i = 0; i < 10; ++i) { RTC::TimedDouble writeValue; writeValue.data = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! outPort->write(writeValue)); // OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトしているか? timeval tm_cur; gettimeofday(&tm_cur, 0); timeval tm_diff; timersub(&tm_cur, &tm_pre, &tm_diff); double interval = (double) tm_diff.tv_sec + (double) tm_diff.tv_usec / USEC_PER_SEC; tm_pre = tm_cur; CPPUNIT_ASSERT_DOUBLES_EQUAL( (double) WTIMEOUT_USEC / USEC_PER_SEC, interval, 0.1 * WTIMEOUT_USEC/USEC_PER_SEC); } delete inPort; delete outPort; } }; }; // namespace OutPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPort::OutPortTests); #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 // OutPort_cpp
1725 // outPort->setWriteTimeout(WTIMEOUT_USEC);
1726 
1727  timeval tm_pre;
1728  gettimeofday(&tm_pre, 0);
1729 
1730  for(int ic(0);ic<8;++ic)
1731  {
1732  RTC::TimedDouble writeValue;
1733  writeValue.data = 3.14159265;
1734  outPort->write(writeValue);
1735  }
1736  for (int i = 0; i < 10; ++i) {
1737 
1738  RTC::TimedDouble writeValue;
1739  writeValue.data = i * 3.14159265;
1740 
1741  // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか?
1742  CPPUNIT_ASSERT(! outPort->write(writeValue));
1743 
1744  // OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトしているか?
1745  timeval tm_cur;
1746  gettimeofday(&tm_cur, 0);
1747 
1748  timeval tm_diff;
1749  timersub(&tm_cur, &tm_pre, &tm_diff);
1750 
1751  double interval = (double) tm_diff.tv_sec
1752  + (double) tm_diff.tv_usec / USEC_PER_SEC;
1753 
1754  tm_pre = tm_cur;
1755 
1756  CPPUNIT_ASSERT_DOUBLES_EQUAL(
1757  (double) WTIMEOUT_USEC / USEC_PER_SEC, interval,
1758  0.1 * WTIMEOUT_USEC/USEC_PER_SEC);
1759  }
1760  delete inPort;
1761  delete outPort;
1762  }
1763 
1764  };
1765 }; // namespace OutPort
1766 
1767 /*
1768  * Register test suite
1769  */
1771 
1772 #ifdef LOCAL_MAIN
1773 int main(int argc, char* argv[])
1774 {
1775 
1776  FORMAT format = TEXT_OUT;
1777  int target = 0;
1778  std::string xsl;
1779  std::string ns;
1780  std::string fname;
1781  std::ofstream ofs;
1782 
1783  int i(1);
1784  while (i < argc)
1785  {
1786  std::string arg(argv[i]);
1787  std::string next_arg;
1788  if (i + 1 < argc) next_arg = argv[i + 1];
1789  else next_arg = "";
1790 
1791  if (arg == "--text") { format = TEXT_OUT; break; }
1792  if (arg == "--xml")
1793  {
1794  if (next_arg == "")
1795  {
1796  fname = argv[0];
1797  fname += ".xml";
1798  }
1799  else
1800  {
1801  fname = next_arg;
1802  }
1803  format = XML_OUT;
1804  ofs.open(fname.c_str());
1805  }
1806  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
1807  if ( arg == "--cerr" ) { target = 1; break; }
1808  if ( arg == "--xsl" )
1809  {
1810  if (next_arg == "") xsl = "default.xsl";
1811  else xsl = next_arg;
1812  }
1813  if ( arg == "--namespace" )
1814  {
1815  if (next_arg == "")
1816  {
1817  std::cerr << "no namespace specified" << std::endl;
1818  exit(1);
1819  }
1820  else
1821  {
1822  xsl = next_arg;
1823  }
1824  }
1825  ++i;
1826  }
1827  CppUnit::TextUi::TestRunner runner;
1828  if ( ns.empty() )
1829  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1830  else
1831  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1832  CppUnit::Outputter* outputter = 0;
1833  std::ostream* stream = target ? &std::cerr : &std::cout;
1834  switch ( format )
1835  {
1836  case TEXT_OUT :
1837  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
1838  break;
1839  case XML_OUT :
1840  std::cout << "XML_OUT" << std::endl;
1841  outputter = new CppUnit::XmlOutputter(&runner.result(),
1842  ofs, "shift_jis");
1843  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
1844  break;
1845  case COMPILER_OUT :
1846  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
1847  break;
1848  }
1849  runner.setOutputter(outputter);
1850  runner.run();
1851  return 0; // runner.run() ? 0 : 1;
1852 }
1853 #endif // MAIN
1854 #endif // OutPort_cpp
void setDateFormat(const char *format)
Set date/time format for adding the header.
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
virtual ReturnCode write(const cdrMemoryStream &data)
Writing data.
ConnectorListeners class.
RTC::PublisherBase::ReturnCode write(const cdrMemoryStream &data, unsigned long sec, unsigned long usec)
Write data.
void test_write(void)
write()メソッドのテスト
InPortConsumer abstract class.
virtual ~Logger(void)
Virtual destructor.
RTC::PublisherBase::ReturnCode deactivate()
deactivation
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
int main(int argc, char **argv)
static Mutex mutex
The mutex of the pointer to the Manager.
Definition: Manager.h:1555
RTC::PublisherBase::ReturnCode activate()
activation
void setLogger(Logger *logger)
virtual void activate()
Connector activation.
virtual void header(int level)
Message prefix appender function.
CORBA Consumer class.
InPort template class.
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
OutPortConnector base class.
DataPortStatus class.
void test_write_OnOverflow()
write()メソッドのOnOverflowコールバック呼出テスト
RT-Component.
virtual void setUp()
Test initialization.
LogStreamBuf m_logStreamBuf
void test_write_OnWrite()
write()メソッドのOnWriteコールバック呼出テスト
void setSubscriptionType(const char *subs_type)
Set the subscription type.
virtual ReturnCode_t connect(ConnectorProfile &connector_profile)
[CORBA interface] Connect the Port
Definition: InPortBase.cpp:433
void setOnWriteConvert(OnWriteConvert< DataType > *on_wconvert)
Set OnWriteConvert callback.
Definition: OutPort.h:456
Data convert callback abstract class on write()
Definition: PortCallback.h:258
virtual CdrBufferBase * getBuffer()
Getting Buffer.
void log(const std::string &msg)
PortableServer::POA_ptr m_pPOA
RTC::PublisherBase::ReturnCode setConsumer(RTC::InPortConsumer *consumer)
Store InPort consumer.
virtual void deactivate()
Connector deactivation.
void setPortType(const char *port_type)
Set the port type.
log_streambuf template class
virtual ReturnCode reset()
Reset the buffer status.
Mutex class.
void setInterfaceType(const char *interface_type)
Set the interface type.
bool appendStringValue(SDOPackage::NVList &nv, const char *name, const char *value)
Append the specified string to element of NVList.
Definition: NVUtil.cpp:313
::RTC::BufferStatus::Enum m_read_return_value
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void log(const std::string &msg)
~OutPortTests()
Destructor.
virtual CdrBufferBase * createBuffer(ConnectorInfo &info)
create buffer
void set_readable_return_value(size_t value)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
OutPort class.
ConnectorListeners m_listeners
ConnectorDataListener listener.
Definition: OutPortBase.h:1064
::InPort::Logger RTC_logger
virtual size_t readable() const
Write data into the buffer.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
virtual ReturnCode advanceRptr(long int n=1)
Forward n reading pointers.
Manager class.
Definition: Manager.h:80
virtual ReturnCode disconnect()
disconnect
::RTC::DataPortStatus::Enum setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
void setLogger(Logger *logger)
void setName(const char *name)
Set suffix of date/time string of header.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
log_stream< char > LogStream
virtual DATAPORTSTATUS_ENUM ~OutPortProvider(void)
Destructor.
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
virtual bool full(void) const
Check on whether the buffer is full.
string outport
Definition: README_gen.py:115
OutPortConnector * createConnector(const ConnectorProfile &cprof, coil::Properties &prop, InPortConsumer *consumer)
OutPortPushConnector creation.
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
bool subscribeInterface(const SDOPackage::NVList &properties)
virtual void tearDown()
Test finalization.
void setLogger(Logger *logger)
CdrBufferBase * m_buffer
A pointer to a buffer.
std::vector< DataType > m_buffer
virtual void operator()(const DataType &value)
Callback function.
void test_write_timeout()
write()メソッドのタイムアウト処理テスト
std::vector< std::string > m_log
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
static Manager * manager
The pointer to the Manager.
Definition: Manager.h:1546
bool isActive()
If publisher is active state.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
Definition: BufferStatus.h:157
#define USEC_PER_SEC
BUFFERSTATUS_ENUM RingBufferMock(long int length=8)
void setDataType(const char *data_type)
Set the data type.
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
virtual bool empty(void) const
Check on whether the buffer is empty.
Push type connector class.
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)
Read data from the buffer.
CPPUNIT_TEST_SUITE_REGISTRATION(OutPort::OutPortTests)
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
virtual size_t writable() const
Get a writable number.
void init(coil::Properties &prop)
Initializing configuration.
OnWriteConvertMock(RTC::TimedDouble amplitude)
RTC::OutPortConnector * createConnector_public(RTC::ConnectorProfile &cprof, coil::Properties &prop, RTC::OutPortProvider *provider)
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
Definition: stringutil.cpp:568
virtual PublisherBase * createPublisher(ConnectorInfo &info)
create buffer
void set_read_return_value(::RTC::BufferStatus::Enum value)
ConnectorBase::ReturnCode OutPortPushConnector_write_return_value
Callback abstract class on write()
Definition: PortCallback.h:192
virtual void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data send notification.
void setDataFlowType(const char *dataflow_type)
Set the data flow type.
OutPortMock(const char *name, DataType &value)
Manager()
Protected Constructor.
Definition: Manager.cpp:80
#define WTIMEOUT_USEC
OutPortProvider.
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
Definition: NVUtil.cpp:354
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
virtual ReturnCode length(size_t n)
Set the buffer length.
bool setLevel(const char *level)
Set log level by string.
::RTC::BufferStatus::Enum ReturnCode
prop
Organization::get_organization_property ();.
RTC::PublisherBase::ReturnCode setBuffer(RTC::CdrBufferBase *buffer)
Setting buffer pointer.
OutPortTests()
Constructor.
void setLogger(Logger *logger)
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
Definition: PortBase.cpp:100
InPortBase base class.
virtual DataType * wptr(long int n=0)
Get the writing pointer.
virtual void init(coil::Properties &prop)
Initializing configuration.
Logger rtclog
Logger stream.
Class represents a set of properties.
Definition: Properties.h:101
virtual size_t length(void) const
Get the buffer length.
void test_write_OnOverflow_not_full()
バッファフルでない時の、write()メソッドのOnOverflowコールバック呼出テスト
Base class of Publisher.
Definition: PublisherBase.h:63
InPort template class.
Definition: InPort.h:89
OutPort template class.
Definition: OutPort.h:106
virtual bool publishInterface(SDOPackage::NVList &properties)
Publish interface information.
virtual bool write(DataType &value)
Write data.
Definition: OutPort.h:203
Logger(const char *name="")
Constructor.
void setOnWrite(OnWrite< DataType > *on_write)
Set OnWrite callback.
Definition: OutPort.h:415
::OutPortBase::Logger logger
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
bool isStringValue(const SDOPackage::NVList &nv, const char *name, const char *value)
Check whether the value of specified name specified matches the specified string. ...
Definition: NVUtil.cpp:262
void clearLog(void)
virtual ~OutPortPushConnector()
Destructor.
int strToLevel(const char *level)
Set the log level Set the log level corresponding to the given string.
int countLog(const std::string &msg)
virtual ReturnCode advanceWptr(long int n=1)
Forward n writing pointers.
int countLog(const std::string &msg)
static const char * m_levelString[]
Definition: SystemLogger.h:342
void init(coil::Properties &prop)
Initializing properties.
Definition: InPortBase.cpp:96
virtual DataType operator()(const DataType &value)
Callback function.
virtual DataType * rptr(long int n=0)
Get the reading pointer.
virtual void init(const coil::Properties &prop)
Set the buffer.
void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data send notification.
BufferBase abstract class.
Definition: BufferBase.h:104
RTC::PublisherBase::ReturnCode init(coil::Properties &prop)
Initializing configuration.
std::string getDate(void)
Get the current formatted date/time string Get the current datetime described by specified format...
Enum
DataPortStatus return codes.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
void unsubscribeInterface(const SDOPackage::NVList &properties)
virtual void setBuffer(CdrBufferBase *buffer)=0
Setting outside buffer&#39;s pointer.
void test_write_OnWrite_full()
バッファフル時のwrite()メソッドのOnWriteコールバック呼出テスト
RTC::OutPortConnector * createConnector_public(RTC::ConnectorProfile &cprof, coil::Properties &prop, RTC::InPortConsumer *consumer)
virtual ~RingBufferMock(void)
bool initORB()
CORBA ORB initialization.
Definition: Manager.cpp:1073
coil::Properties & properties()
Get properties.
void init(coil::Properties &prop)
Initializing configuration.
const char * name()
Getting Connector name.
DataType & m_value
The reference to type-T variable that is bound.
Definition: OutPort.h:470


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