InPortTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 /*
22  * $Log: InPortTests.cpp,v $
23  * Revision 1.2 2008/03/13 13:12:25 arafune
24  * Added some new tests.
25  *
26  * Revision 1.1 2007/12/20 07:50:19 arafune
27  * *** empty log message ***
28  *
29  * Revision 1.2 2007/01/12 14:51:20 n-ando
30  * Callback functions' namespace were changed.
31  *
32  * Revision 1.1 2006/11/27 08:32:39 n-ando
33  * TestSuites are devided into each directory.
34  *
35  *
36  */
37 
38 #ifndef InPort_cpp
39 #define InPort_cpp
40 
41 #include <cppunit/ui/text/TestRunner.h>
42 #include <cppunit/TextOutputter.h>
43 #include <cppunit/extensions/TestFactoryRegistry.h>
44 #include <cppunit/extensions/HelperMacros.h>
45 #include <cppunit/TestAssert.h>
46 
47 #include <rtm/idl/BasicDataTypeSkel.h>
48 #include <rtm/idl/DataPortSkel.h>
49 #include <rtm/InPortConsumer.h>
50 #include <rtm/InPortProvider.h>
51 #include <rtm/InPort.h>
52 #include <rtm/InPortBase.h>
53 #include <rtm/CorbaConsumer.h>
54 #include <rtm/OutPortConsumer.h>
55 #include <rtm/CdrBufferBase.h>
56 
57 #include <string>
58 #include <vector>
59 #include <coil/Guard.h>
60 #include <coil/Mutex.h>
61 #include <rtm/idl/RTCSkel.h>
62 #include <rtm/CORBA_SeqUtil.h>
63 #include <rtm/NVUtil.h>
64 #include <assert.h>
65 #include <coil/UUID.h>
66 #include <memory>
67 #include <rtm/RTC.h>
68 
69 #include <coil/Logger.h>
70 #include <rtm/SystemLogger.h>
71 #include <rtm/Manager.h>
72 #include <rtm/PortCallback.h>
74 #include <rtm/ConnectorBase.h>
75 #include <rtm/OutPortConnector.h>
76 
77 #define WTIMEOUT_USEC 1000000
78 #define USEC_PER_SEC 1000000
79 
84 namespace InPort
85 {
90  template <class DataType>
91  class InPortMock
92  : public RTC::InPort<DataType>
93  {
94  public:
99  InPortMock(const char* name, DataType& value,
100  int bufsize=64,
101  bool read_block = false, bool write_block = false,
102  int read_timeout = 0, int write_timeout = 0)
103  : RTC::InPort<DataType>(name , value)
104  {
105  }
110  virtual ~InPortMock()
111  {
112  }
118  {
120  }
126  {
128  }
134  {
136  }
142  createConnector_public(RTC::ConnectorProfile& cprof,
145  {
146  // return RTC::InPort<DataType>::createConnector(cprof, prop, provider);
147  return RTC::InPortBase::createConnector(cprof, prop, provider);
148  }
154  {
156  }
162  {
164  }
165  };
171  class Logger
172  {
173  public:
174  void log(const std::string& msg)
175  {
176  m_log.push_back(msg);
177  }
178 
179  int countLog(const std::string& msg)
180  {
181  int count = 0;
182  for (int i = 0; i < (int) m_log.size(); ++i)
183  {
184  if (m_log[i] == msg) ++count;
185  }
186  return count;
187  }
188 
189  void clearLog(void)
190  {
191  m_log.clear();
192  }
193  private:
194  std::vector<std::string> m_log;
195  };
202  : public RTC::InPortProvider,
203  public virtual POA_OpenRTM::InPortCdr,
204  public virtual PortableServer::RefCountServantBase
205  {
206 
207  public:
209  {
210  m_logger = NULL;
211  // PortProfile setting
212  setInterfaceType("corba_cdr");
213 
214  // ConnectorProfile setting
215  m_objref = this->_this();
216 
217  // set InPort's reference
218  std::vector<std::string> args(coil::split("-ORBendPoint giop:tcp:2809", " "));
219  // TAO's ORB_init needs argv[0] as command name.
220  args.insert(args.begin(), "manager");
221  char** argv = coil::toArgv(args);
222  int argc(args.size());
223 
224  // ORB initialization
225  CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
226 
229  NVUtil::newNV("dataport.corba_cdr.inport_ior",
230  orb->object_to_string(m_objref.in())));
233  NVUtil::newNV("dataport.corba_cdr.inport_ref",
234  m_objref));
235  }
237  {
238  PortableServer::ObjectId_var oid;
239  oid = _default_POA()->servant_to_id(this);
240  _default_POA()->deactivate_object(oid);
241  }
247  {
248  if (m_logger != NULL)
249  {
250  m_logger->log("InPortCorbaCdrProviderMock::setBuffer");
251  }
252  }
253 
255  RTC::ConnectorListeners* listeners)
256  {
257  // m_profile = info;
258  // m_listeners = listeners;
259  }
261  {
262  // m_connector = connector;
263  }
268  ::OpenRTM::PortStatus put(const ::OpenRTM::CdrData& data)
269  throw (CORBA::SystemException)
270  {
271  return ::OpenRTM::PORT_OK;
272  }
278  {
279  if (m_logger != NULL)
280  {
281  m_logger->log("InPortCorbaCdrProviderMock::init");
282  }
283  }
288  RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
289  {
291  }
297  {
298  return;
299  }
300 
306  {
307  return true;;
308  }
309 
315  {
316  }
317 
318 
323 /*
324  bool publishInterface(SDOPackage::NVList& prop)
325  {
326  return true;
327  }
328 */
334  {
335  m_logger = logger;
336  }
337  private:
339  ::OpenRTM::InPortCdr_var m_objref;
340 
341  };
343  : public RTC::OutPortConsumer,
344  public RTC::CorbaConsumer< ::OpenRTM::OutPortCdr >
345  {
346 
347  public:
349  {
350  m_logger = NULL;
351  }
353  {
354  }
360  {
361  if (m_logger != NULL)
362  {
363  m_logger->log("OutPortCorbaCdrConsumerMock::setBuffer");
364  }
365  }
367  RTC::ConnectorListeners* listeners)
368  {
369  // m_profile = info;
370  // m_listeners = listeners;
371  }
373  {
374  // m_connector = connector;
375  }
376 
381  ::OpenRTM::PortStatus put(const ::OpenRTM::CdrData& data)
382  throw (CORBA::SystemException)
383  {
384  return ::OpenRTM::PORT_OK;
385  }
391  {
392  if (m_logger != NULL)
393  {
394  m_logger->log("OutPortCorbaCdrConsumerMock::init");
395  }
396  }
401  RTC::OutPortConsumer::ReturnCode put(const cdrMemoryStream& data)
402  {
403  return PORT_OK;
404  }
410  {
411  return;
412  }
413 
419  {
420 
421  return true;;
422  }
423 
429  {
430  }
435  virtual ReturnCode get(cdrMemoryStream& data)
436  {
437  return PORT_OK;
438  }
439 
440 
446  {
447  m_logger = logger;
448  }
449  private:
451 
452  };
458  template <class DataType>
460  : public RTC::BufferBase<DataType>
461  {
462  public:
464  RingBufferMock(long int length = 8)
465  {
466  m_logger = NULL;
467  logger.log("RingBufferMock::Constructor");
468  m_read_return_value = BUFFER_OK;
469  m_readable_return_value = 0;
470 
471  }
472  virtual ~RingBufferMock(void)
473  {
474  }
475 
476 
482  {
483  m_read_return_value = value;
484  }
489  virtual void init(const coil::Properties& prop)
490  {
491  }
496  virtual size_t length(void) const
497  {
498  return 0;
499  }
504  virtual ReturnCode length(size_t n)
505  {
506  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
507  }
512  virtual ReturnCode reset()
513  {
514  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
515  }
520  virtual DataType* wptr(long int n = 0)
521  {
522  return &m_data;
523  }
528  virtual ReturnCode advanceWptr(long int n = 1)
529  {
530  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
531  }
536  virtual ReturnCode put(const DataType& value)
537  {
538  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
539  }
544  virtual ReturnCode write(const DataType& value,
545  long int sec = -1, long int nsec = -1)
546  {
547  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
548  }
553  virtual size_t writable() const
554  {
555  return 0;
556  }
561  virtual bool full(void) const
562  {
563  return true;
564  }
569  virtual DataType* rptr(long int n = 0)
570  {
571  return &m_data;
572  }
577  virtual ReturnCode advanceRptr(long int n = 1)
578  {
579  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
580  }
585  virtual ReturnCode get(DataType& value)
586  {
587  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
588  }
593  virtual DataType& get()
594  {
595  return m_data;
596  }
601  virtual ReturnCode read(DataType& value,
602  long int sec = -1, long int nsec = -1)
603  {
604  if (m_logger != NULL)
605  {
606  m_logger->log("RingBufferMock::read");
607  }
608  logger.log("RingBufferMock::read");
609  return m_read_return_value; //BUFFER_OK;
610  }
615  virtual size_t readable() const
616  {
617  return m_readable_return_value;
618  }
623  void set_readable_return_value(size_t value)
624  {
625  m_readable_return_value = value;
626  }
631  virtual bool empty(void) const
632  {
633  return true;
634  }
640  {
641  m_logger = logger;
642  }
643 
644  static Logger logger;
645  private:
646  DataType m_data;
647  std::vector<DataType> m_buffer;
651  };
652  template <class DataType>
655 };
656 namespace RTC
657 {
673  InPortPushConnector::InPortPushConnector(ConnectorInfo profile,
675  ConnectorListeners& listeners,
676  CdrBufferBase* buffer)
677  : InPortConnector(profile, buffer),
678  m_listeners(listeners)
679  {
680 
681  InPortPushConnector_read = 0;
682  InPortPushConnector_read_return_value = PORT_OK;
683  if(profile.properties["InPortBaseTests"]=="bad_alloc")
684  {
685  throw std::bad_alloc();
686  }
687 
688  }
694  {
695  }
701  {
702  return PORT_OK;
703  }
709  InPortPushConnector::read(cdrMemoryStream& data)
710  {
711  RTC_logger.log("InPortPushConnector::read");
712  RTC::TimedLong td;
713  td.data = 777;;
714  td >>= data;
716 
717 
718  }
724  {
726  }
734  Manager* Manager::manager = NULL;
741  : m_initProc(NULL),
743  m_runner(NULL), m_terminator(NULL)
744  {
745  }
751  {
752  // DCL for singleton
753  if (!manager)
754  {
755  Guard guard(mutex);
756  if (!manager)
757  {
758  manager = new Manager();
759  manager->initORB();
760  }
761  }
762  return *manager;
763  }
768  CORBA::ORB_ptr Manager::getORB()
769  {
770  return m_pORB;
771  }
776  bool Manager::initORB()
777  {
778  // Initialize ORB
779  try
780  {
781  std::vector<std::string> args(coil::split(NULL, " "));
782  // TAO's ORB_init needs argv[0] as command name.
783  args.insert(args.begin(), "manager");
784  char** argv = coil::toArgv(args);
785  int argc(args.size());
786 
787  // ORB initialization
788  m_pORB = CORBA::ORB_init(argc, argv);
789  // Get the RootPOA
790  CORBA::Object_var obj = m_pORB->resolve_initial_references("RootPOA");
791  PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(obj);
792  CORBA::PolicyList policies;
793  policies.length(2);
794  policies[(CORBA::ULong)0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
795  policies[(CORBA::ULong)1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
796  PortableServer::POAManager_var rootManager = rootPOA->the_POAManager();
797  m_pPOA = rootPOA->create_POA("persistent", rootManager, policies);
798  if (CORBA::is_nil(m_pPOA))
799  {
800  return false;
801  }
802  // Get the POAManager
803  m_pPOAManager = m_pPOA->the_POAManager();
804  }
805  catch (...)
806  {
807  RTC_ERROR(("Exception: Caught unknown exception in initORB()." ));
808  return false;
809  }
810  return true;
811  }
812 
821  const char* Logger::m_levelString[] =
822  {
823  " SILENT: ",
824  " FATAL: ",
825  " ERROR: ",
826  " WARNING: ",
827  " INFO: ",
828  " DEBUG: ",
829  " TRACE: ",
830  " VERBOSE: ",
831  " PARANOID: "
832  };
833 
834  Logger::Logger(const char* name)
835  : ::coil::LogStream(&m_logStreamBuf, 0, 8, 0)
836  {
837  }
838 
839  Logger::Logger(LogStreamBuf* streambuf)
840  : ::coil::LogStream(&m_logStreamBuf, 0, 8, 0)
841  {
842  }
843 
844  Logger::~Logger(void)
845  {
846  }
847 
855  bool Logger::setLevel(const char* level)
856  {
857  return true;
858  }
859 
867  void Logger::setDateFormat(const char* format)
868  {
869  }
870 
878  void Logger::setName(const char* name)
879  {
880  }
881 
889  void Logger::header(int level)
890  {
891  }
892 
900  std::string Logger::getDate(void)
901  {
902  const int maxsize = 256;
903  char buf[maxsize];
904 
905  return std::string(buf);
906  }
907 
915  int Logger::strToLevel(const char* level)
916  {
917  return 0;
918  }
919 
920 #if 1
921  /*
922  *
923  *
924  *
925  *
926  *
927  */
936  {
937  }
938 
947  {
948  }
949 
958  {
959  }
960 
969  {
970  return true;
971  }
972 
973  //----------------------------------------------------------------------
974  // protected functions
975 
983  void InPortProvider::setInterfaceType(const char* interface_type)
984  {
985  }
986 
994  void InPortProvider::setDataFlowType(const char* dataflow_type)
995  {
996  }
997 
1005  void InPortProvider::setSubscriptionType(const char* subs_type)
1006  {
1007  }
1008 #endif
1009 }; // namespace RTC
1010 namespace InPort
1011 {
1016  template <class DataType>
1018  : public RTC::OnRead<DataType>
1019  {
1020  public:
1026  {
1027  m_logger = NULL;
1028  }
1033  virtual void operator()()
1034  {
1035  if (m_logger != NULL)
1036  {
1037  m_logger->log("OnReadMock::operator");
1038  }
1039 
1040  }
1041  DataType m_value;
1047  {
1048  m_logger = logger;
1049  }
1050  private:
1052  };
1057  template <class DataType>
1059  : public RTC::OnReadConvert<DataType>
1060  {
1066  {
1067  m_logger = NULL;
1068  }
1073  virtual DataType operator()(const DataType& value)
1074  {
1075  if (m_logger != NULL)
1076  {
1077  m_logger->log("OnReadConvertMock::operator");
1078  }
1079  return value;
1080  }
1086  {
1087  m_logger = logger;
1088  }
1089  private:
1091  };
1092 
1093 /*
1094  template <class DataType>
1095  class FullBuffer
1096  : public RTC::NullBuffer<DataType>
1097  {
1098  public:
1099  FullBuffer(long int length) {};
1100  virtual bool isFull() const
1101  {
1102  return true;
1103  }
1104  };
1105 */
1106  template <class DataType>
1108  : public RTC::OnWrite<DataType>
1109  {
1110  public:
1111  virtual void operator()(const DataType& value)
1112  {
1113  m_value = value;
1114  }
1115  DataType m_value;
1116  };
1117 
1118  /*
1119  template <class DataType>
1120  class OnOverflowMock
1121  : public RTC::OnOverflow<DataType>
1122  {
1123  public:
1124  virtual void operator()(const DataType& value)
1125  {
1126  m_value = value;
1127  }
1128  DataType m_value;
1129  };
1130  */
1131  /*
1132  class OnWriteConvertMock
1133  : public RTC::OnWriteConvert<double>
1134  {
1135  public:
1136  OnWriteConvertMock(double amplitude)
1137  : m_amplitude(amplitude) {}
1138  virtual double operator()(const double& value)
1139  {
1140  return m_amplitude * value;
1141  }
1142  double m_amplitude;
1143  };
1144  */
1145 
1151  : public CppUnit::TestFixture
1152  {
1153  CPPUNIT_TEST_SUITE(InPortTests);
1154 
1155  CPPUNIT_TEST(test_name);
1156  CPPUNIT_TEST(test_isNew);
1157  CPPUNIT_TEST(test_isEmpty);
1158  CPPUNIT_TEST(test_read);
1159 // CPPUNIT_TEST(test_setOnWrite); //The callback is not used.
1160 // CPPUNIT_TEST(test_setOnUnderflow); //The callback is not used.
1161 
1162 
1163 /*
1164  CPPUNIT_TEST(test_write_and_read);
1165  CPPUNIT_TEST(test_write_OnWrite);
1166  CPPUNIT_TEST(test_write_OnWrite_full);
1167  CPPUNIT_TEST(test_write_OnOverflow);
1168  CPPUNIT_TEST(test_write_OnOverflow_not_full);
1169  CPPUNIT_TEST(test_write_OnWriteConvert);
1170  CPPUNIT_TEST(test_write_timeout);
1171 */
1172  CPPUNIT_TEST_SUITE_END();
1173 
1174  private:
1175  CORBA::ORB_ptr m_pORB;
1176  PortableServer::POA_ptr m_pPOA;
1178 
1179 
1180  public:
1181 
1186  {
1187  int argc(0);
1188  char** argv(NULL);
1189  m_pORB = CORBA::ORB_init(argc, argv);
1190  m_pPOA = PortableServer::POA::_narrow(
1191  m_pORB->resolve_initial_references("RootPOA"));
1192  m_pPOA->the_POAManager()->activate();
1193  m_logger = NULL;
1194  }
1195 
1200  {
1201  }
1202 
1206  virtual void setUp()
1207  {
1208  //既に "corba_cdr" で登録されている場合は削除する。
1209  if( RTC::InPortProviderFactory::instance().hasFactory("corba_cdr") )
1210  {
1211  RTC::InPortProviderFactory::instance().removeFactory("corba_cdr");
1212  }
1213  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
1215  addFactory("corba_cdr",
1220 
1221  //既に "corba_cdr" で登録されている場合は削除する。
1222  if( RTC::OutPortConsumerFactory::instance().hasFactory("corba_cdr") )
1223  {
1224  RTC::OutPortConsumerFactory::instance().removeFactory("corba_cdr");
1225  }
1226  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
1228  addFactory("corba_cdr",
1233 
1234  //既に "ring_buffer" で登録されている場合は削除する。
1235  if( RTC::CdrBufferFactory::instance().hasFactory("ring_buffer") )
1236  {
1237  RTC::CdrBufferFactory::instance().removeFactory("ring_buffer");
1238  }
1239  //"ring_buffer" に CdrRingBufferMock を登録する。
1241  addFactory("ring_buffer",
1242  coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
1243  coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
1244 
1245  }
1246 
1250  virtual void tearDown()
1251  {
1252  }
1257  void test_name(void)
1258  {
1259  RTC::TimedLong tl;
1260  RTC::InPort<RTC::TimedLong> inport("test_name0",tl);
1261  CPPUNIT_ASSERT_EQUAL(std::string("test_name0"),
1262  std::string(inport.name()));
1263 
1264  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1265  }
1266 
1271  void test_isNew(void)
1272  {
1273  RTC::TimedLong tl;
1274  InPortMock<RTC::TimedLong> inport("test_name0",tl);
1275  coil::Properties prop_;
1276  inport.init(prop_);
1277 
1278  //no connectors
1279  CPPUNIT_ASSERT_EQUAL(false, inport.isNew());
1280 
1281  RTC::ConnectorProfile prof;
1282  coil::Properties prop(inport.properties());
1284  RTC::InPortConnector* connector
1285  = inport.createConnector_public(prof, prop, provider);
1286  CPPUNIT_ASSERT(0!= connector);
1287  //no readable data
1288  CPPUNIT_ASSERT_EQUAL(false, inport.isNew());
1289 
1290  /* Dynamic_cast is done for the test.. */
1291  /* Please do not do usual. */
1292  CdrRingBufferMock* pbuffer
1293  = dynamic_cast<CdrRingBufferMock*>(inport.get_m_thebuffer());
1294 
1295  CPPUNIT_ASSERT(0!= pbuffer);
1296  //no readable data
1297  CPPUNIT_ASSERT_EQUAL(false, inport.isNew());
1298  pbuffer->set_readable_return_value((size_t)5);
1299  //readable data
1300  CPPUNIT_ASSERT_EQUAL(true, inport.isNew());
1301 
1302 
1303  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1304  delete provider;
1305  }
1310  void test_isEmpty(void)
1311  {
1312  RTC::TimedLong tl;
1313  InPortMock<RTC::TimedLong> inport("test_name0",tl);
1314  coil::Properties prop_;
1315  inport.init(prop_);
1316 
1317  //no connectors
1318  CPPUNIT_ASSERT_EQUAL(true, inport.isEmpty());
1319 
1320  RTC::ConnectorProfile prof;
1321  coil::Properties prop(inport.properties());
1323  RTC::InPortConnector* connector
1324  = inport.createConnector_public(prof, prop, provider);
1325  CPPUNIT_ASSERT(0!= connector);
1326 
1327  //no readable data
1328  CPPUNIT_ASSERT_EQUAL(true, inport.isEmpty());
1329 
1330  /* Dynamic_cast is done for the test.. */
1331  /* Please do not do usual. */
1332  CdrRingBufferMock* pbuffer
1333  = dynamic_cast<CdrRingBufferMock*>(inport.get_m_thebuffer());
1334 
1335  CPPUNIT_ASSERT(0!= pbuffer);
1336  //no readable data
1337  CPPUNIT_ASSERT_EQUAL(true, inport.isEmpty());
1338  pbuffer->set_readable_return_value((size_t)5);
1339 
1340  //readable data
1341  CPPUNIT_ASSERT_EQUAL(false, inport.isEmpty());
1342 
1343 
1344  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1345  delete provider;
1346  }
1351  void test_read(void)
1352  {
1353  RTC::TimedLong tl;
1354  tl.data = 123;
1355  InPortMock<RTC::TimedLong> inport("test_read0",tl);
1356  coil::Properties prop_;
1357  inport.init(prop_);
1358 
1360  Logger logger;
1361  onRead.setLogger(&logger);
1362  inport.setOnRead(&onRead);
1363 
1364  bool ret;
1365  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnReadMock::operator"));
1366  ret = inport.read();
1367  //no connectors
1368  CPPUNIT_ASSERT_EQUAL(false, ret);
1369  CPPUNIT_ASSERT_EQUAL((CORBA::Long)123, tl.data);
1370  CPPUNIT_ASSERT_EQUAL(1,logger.countLog("OnReadMock::operator"));
1371 
1372  RTC::ConnectorProfile prof;
1373  coil::Properties prop(inport.properties());
1375  RTC::InPortConnector* connector
1376  = inport.createConnector_public(prof, prop, provider);
1377  CPPUNIT_ASSERT(0!= connector);
1378  //
1379  //
1380  //
1381  OnReadConvertMock<RTC::TimedLong> onReadConvert;
1382  onReadConvert.setLogger(&logger);
1383 
1386  RTC::TimedLong tl_;
1387  inport.operator>>(tl_);
1388  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl_.data);
1389 
1390  int logcount;
1391  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnReadConvertMock::operator"));
1392  logcount = ::RTC::RTC_logger.countLog("InPortPushConnector::read");
1393  ret = inport.read();
1394  //data read succeeded
1395  CPPUNIT_ASSERT_EQUAL(true, ret);
1396  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1397  CPPUNIT_ASSERT_EQUAL(logcount+1,
1398  ::RTC::RTC_logger.countLog("InPortPushConnector::read"));
1399  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnReadConvertMock::operator"));
1400 
1401  inport.setOnReadConvert(&onReadConvert);
1402  CPPUNIT_ASSERT_EQUAL(0,logger.countLog("OnReadConvertMock::operator"));
1403  logcount = ::RTC::RTC_logger.countLog("InPortPushConnector::read");
1404  ret = inport.read();
1405  //data read succeeded
1406  CPPUNIT_ASSERT_EQUAL(true, ret);
1407  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1408  CPPUNIT_ASSERT_EQUAL(logcount+1,
1409  ::RTC::RTC_logger.countLog("InPortPushConnector::read"));
1410  CPPUNIT_ASSERT_EQUAL(1,logger.countLog("OnReadConvertMock::operator"));
1411 
1412  //
1413  //
1414  //
1417  inport.setOnRead(&onRead);
1418 
1419  logcount = ::RTC::RTC_logger.countLog("InPortPushConnector::read");
1420  ret = inport.read();
1421  //data read succeeded
1422  CPPUNIT_ASSERT_EQUAL(true, ret);
1423  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1424  CPPUNIT_ASSERT_EQUAL(logcount+1,
1425  ::RTC::RTC_logger.countLog("InPortPushConnector::read"));
1426  //
1427  //
1428  //
1429  RTC::InPortPushConnector_read_return_value
1431  logcount = ::RTC::RTC_logger.countLog("InPortPushConnector::read");
1432  ret = inport.read();
1433  //data read failed, because InPortPushConnectorMock::read() return BUFFER_EMPTY.
1434  CPPUNIT_ASSERT_EQUAL(false, ret);
1435  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1436  CPPUNIT_ASSERT_EQUAL(logcount+1,
1437  ::RTC::RTC_logger.countLog("InPortPushConnector::read"));
1438 
1439  //
1440  //
1441  //
1442  RTC::InPortPushConnector_read_return_value
1444  logcount = ::RTC::RTC_logger.countLog("InPortPushConnector::read");
1445  ret = inport.read();
1446  //data read failed, because InPortPushConnectorMock::read() return BUFFER_TIMEOUT
1447  CPPUNIT_ASSERT_EQUAL(false, ret);
1448  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1449  CPPUNIT_ASSERT_EQUAL(logcount+1,
1450  ::RTC::RTC_logger.countLog("InPortPushConnector::read"));
1451 
1452  //
1453  //
1454  //
1455  RTC::InPortPushConnector_read_return_value
1457  logcount = ::RTC::RTC_logger.countLog("InPortPushConnector::read");
1458  ret = inport.read();
1459  //data read failed, because InPortPushConnectorMock::read() return UNKNOWN_ERROR
1460  CPPUNIT_ASSERT_EQUAL(false, ret);
1461  CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1462  CPPUNIT_ASSERT_EQUAL(logcount+1,
1463  ::RTC::RTC_logger.countLog("InPortPushConnector::read"));
1464 
1465  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1466  delete provider;
1467  }
1472  void test_setOnWrite(void)
1473  {
1474  }
1480  {
1481  }
1482 
1488 /*
1489  void test_write_and_read()
1490  {
1491  double bindValue;
1492  std::auto_ptr<RTC::InPort<double> > inPort(
1493  new RTC::InPort<double>("InPort", bindValue, 8));
1494 
1495  for (int i = 0; i < 100; ++i)
1496  {
1497  double writeValue = i * 3.14159265;
1498  CPPUNIT_ASSERT(inPort->write(writeValue));
1499 
1500  // write()で書き込んだ値が、read()で正しく読み出されるか?
1501  double readValue = inPort->read();
1502  CPPUNIT_ASSERT_EQUAL(writeValue, readValue);
1503  }
1504  }
1505 */
1506 
1512 /*
1513  void test_write_OnWrite()
1514  {
1515  double bindValue;
1516  std::auto_ptr<RTC::InPort<double> > inPort(
1517  new RTC::InPort<double>("InPort", bindValue, 8));
1518 
1519  OnWriteMock<double> onWrite;
1520  onWrite.m_value = 0;
1521  inPort->setOnWrite(&onWrite);
1522 
1523  // write()メソッドは成功するか?
1524  double writeValue = 3.14159265;
1525  CPPUNIT_ASSERT(inPort->write(writeValue));
1526 
1527  // あらかじめ設定されたOnWriteコールバックが正しく呼び出されたか?
1528  CPPUNIT_ASSERT_EQUAL(writeValue, onWrite.m_value);
1529  }
1530 */
1531 
1537 /*
1538  void test_write_OnWrite_full()
1539  {
1540  double bindValue;
1541  std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort(
1542  new RTC::InPort<double, FullBuffer>("InPort", bindValue, 8));
1543 
1544  OnWriteMock<double> onWrite;
1545  onWrite.m_value = 0;
1546  inPort->setOnWrite(&onWrite);
1547 
1548  // バッファフルによりwrite()メソッドは意図どおり失敗するか?
1549  double writeValue = 3.14159265;
1550  CPPUNIT_ASSERT(! inPort->write(writeValue));
1551 
1552  // あらかじめ設定されたOnWriteコールバックが正しく呼び出されたか?
1553  CPPUNIT_ASSERT_EQUAL(writeValue, onWrite.m_value);
1554  }
1555 */
1556 
1562 /*
1563  void test_write_OnOverflow()
1564  {
1565  // 常にフル状態であるバッファを用いてInPortオブジェクトを生成する double bindValue; std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort( new RTC::InPort<double, FullBuffer>("InPort", bindValue, 8)); OnOverflowMock<double> onOverflow; onOverflow.m_value = 0; inPort->setOnOverflow(&onOverflow); // バッファフルによりwrite()メソッドは意図どおり失敗するか? double writeValue = 3.14159265; CPPUNIT_ASSERT(! inPort->write(writeValue)); // OutPortに割り当てされたバッファがフルの場合に、あらかじめ設定されたOnOverflowコールバックが正しく呼び出されたか? CPPUNIT_ASSERT_EQUAL(writeValue, onOverflow.m_value); } */ /*! * @brief バッファフルでない時の、write()メソッドのOnOverflowコールバック呼出テスト * * - バッファフルでない場合、OnOverflowコールバックが意図どおり未呼出のままか? */ /* void test_write_OnOverflow_not_full() { double bindValue; std::auto_ptr<RTC::InPort<double> > inPort( new RTC::InPort<double>("InPort", bindValue, 8)); OnOverflowMock<double> onOverflow; onOverflow.m_value = 0; inPort->setOnOverflow(&onOverflow); // write()メソッドは成功するか? double writeValue = 3.14159265; CPPUNIT_ASSERT(inPort->write(writeValue)); // バッファフルでない場合、OnOverflowコールバックが意図どおり未呼出のままか? CPPUNIT_ASSERT_EQUAL((double) 0, onOverflow.m_value); } */ /*! * @brief write()メソッドのOnWriteConvertコールバック呼出テスト * * - 意図したとおり、OnWriteConvertコールバックで変換した値がバッファに書き込まれるか? */ /* void test_write_OnWriteConvert() { double bindValue; std::auto_ptr<RTC::InPort<double> > inPort( new RTC::InPort<double>("InPort", bindValue, 8)); double amplitude = 1.41421356; OnWriteConvertMock onWriteConvert(amplitude); inPort->setOnWriteConvert(&onWriteConvert); for (int i = 0; i < 100; ++i) { double writeValue = i * 3.14159265; CPPUNIT_ASSERT(inPort->write(writeValue)); double readValue = inPort->read(); // write()で書き込んだ値が、read()で正しく読み出されるか? double expectedValue = amplitude * writeValue; CPPUNIT_ASSERT_EQUAL(expectedValue, readValue); } } */ /*! * @brief write()メソッドのタイムアウト処理テスト * * - バッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトするか? * - バッファがフルの場合に、write()メソッドが意図どおり失敗するか? */ /* void test_write_timeout() { // 常にフル状態であるバッファを用いてInPortオブジェクトを生成する bool readBlock = false; bool writeBlock = true; // ブロッキングモードON int readTimeout = 0; int writeTimeout = WTIMEOUT_USEC; // タイムアウト値を指定する double bindValue; std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort( new RTC::InPort<double, FullBuffer>( "InPort", bindValue, 8, readBlock, writeBlock, readTimeout, writeTimeout)); timeval tm_pre; gettimeofday(&tm_pre, 0); for (int i = 0; i < 10; ++i) { double writeValue = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! inPort->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); } } */ }; }; // namespace InPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(InPort::InPortTests); #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 // InPort_cpp
1566  double bindValue;
1567  std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort(
1568  new RTC::InPort<double, FullBuffer>("InPort", bindValue, 8));
1569 
1570  OnOverflowMock<double> onOverflow;
1571  onOverflow.m_value = 0;
1572  inPort->setOnOverflow(&onOverflow);
1573 
1574  // バッファフルによりwrite()メソッドは意図どおり失敗するか?
1575  double writeValue = 3.14159265;
1576  CPPUNIT_ASSERT(! inPort->write(writeValue));
1577 
1578  // OutPortに割り当てされたバッファがフルの場合に、あらかじめ設定されたOnOverflowコールバックが正しく呼び出されたか?
1579  CPPUNIT_ASSERT_EQUAL(writeValue, onOverflow.m_value);
1580  }
1581 */
1582 
1588 /*
1589  void test_write_OnOverflow_not_full()
1590  {
1591  double bindValue;
1592  std::auto_ptr<RTC::InPort<double> > inPort(
1593  new RTC::InPort<double>("InPort", bindValue, 8));
1594 
1595  OnOverflowMock<double> onOverflow;
1596  onOverflow.m_value = 0;
1597  inPort->setOnOverflow(&onOverflow);
1598 
1599  // write()メソッドは成功するか?
1600  double writeValue = 3.14159265;
1601  CPPUNIT_ASSERT(inPort->write(writeValue));
1602 
1603  // バッファフルでない場合、OnOverflowコールバックが意図どおり未呼出のままか?
1604  CPPUNIT_ASSERT_EQUAL((double) 0, onOverflow.m_value);
1605  }
1606 */
1607 
1613 /*
1614  void test_write_OnWriteConvert()
1615  {
1616  double bindValue;
1617  std::auto_ptr<RTC::InPort<double> > inPort(
1618  new RTC::InPort<double>("InPort", bindValue, 8));
1619 
1620  double amplitude = 1.41421356;
1621  OnWriteConvertMock onWriteConvert(amplitude);
1622  inPort->setOnWriteConvert(&onWriteConvert);
1623 
1624  for (int i = 0; i < 100; ++i)
1625  {
1626  double writeValue = i * 3.14159265;
1627  CPPUNIT_ASSERT(inPort->write(writeValue));
1628 
1629  double readValue = inPort->read();
1630 
1631  // write()で書き込んだ値が、read()で正しく読み出されるか?
1632  double expectedValue = amplitude * writeValue;
1633  CPPUNIT_ASSERT_EQUAL(expectedValue, readValue);
1634  }
1635  }
1636 */
1637 
1644 /*
1645  void test_write_timeout()
1646  {
1647  // 常にフル状態であるバッファを用いてInPortオブジェクトを生成する bool readBlock = false; bool writeBlock = true; // ブロッキングモードON int readTimeout = 0; int writeTimeout = WTIMEOUT_USEC; // タイムアウト値を指定する double bindValue; std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort( new RTC::InPort<double, FullBuffer>( "InPort", bindValue, 8, readBlock, writeBlock, readTimeout, writeTimeout)); timeval tm_pre; gettimeofday(&tm_pre, 0); for (int i = 0; i < 10; ++i) { double writeValue = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! inPort->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); } } */ }; }; // namespace InPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(InPort::InPortTests); #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 // InPort_cpp
1648  bool readBlock = false;
1649  bool writeBlock = true; // ブロッキングモードON
1650  int readTimeout = 0;
1651  int writeTimeout = WTIMEOUT_USEC; // タイムアウト値を指定する double bindValue; std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort( new RTC::InPort<double, FullBuffer>( "InPort", bindValue, 8, readBlock, writeBlock, readTimeout, writeTimeout)); timeval tm_pre; gettimeofday(&tm_pre, 0); for (int i = 0; i < 10; ++i) { double writeValue = i * 3.14159265; // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか? CPPUNIT_ASSERT(! inPort->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); } } */ }; }; // namespace InPort /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(InPort::InPortTests); #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 // InPort_cpp
1652 
1653  double bindValue;
1654  std::auto_ptr<RTC::InPort<double, FullBuffer> > inPort(
1655  new RTC::InPort<double, FullBuffer>(
1656  "InPort", bindValue, 8, readBlock, writeBlock, readTimeout, writeTimeout));
1657 
1658  timeval tm_pre;
1659  gettimeofday(&tm_pre, 0);
1660 
1661  for (int i = 0; i < 10; ++i) {
1662 
1663  double writeValue = i * 3.14159265;
1664 
1665  // OutPortに割り当てられたバッファがフルの場合に、write()メソッドが意図どおり失敗するか?
1666  CPPUNIT_ASSERT(! inPort->write(writeValue));
1667 
1668  // OutPortに割り当てされたバッファがフルの場合に、指定した時間どおりにwrite()メソッドがタイムアウトしているか?
1669  timeval tm_cur;
1670  gettimeofday(&tm_cur, 0);
1671 
1672  timeval tm_diff;
1673  timersub(&tm_cur, &tm_pre, &tm_diff);
1674 
1675  double interval = (double) tm_diff.tv_sec
1676  + (double) tm_diff.tv_usec / USEC_PER_SEC;
1677 
1678  tm_pre = tm_cur;
1679 
1680  CPPUNIT_ASSERT_DOUBLES_EQUAL(
1681  (double) WTIMEOUT_USEC / USEC_PER_SEC, interval,
1682  0.1 * WTIMEOUT_USEC/USEC_PER_SEC);
1683  }
1684  }
1685 */
1686 
1687  };
1688 }; // namespace InPort
1689 
1690 /*
1691  * Register test suite
1692  */
1694 
1695 #ifdef LOCAL_MAIN
1696 int main(int argc, char* argv[])
1697 {
1698 
1699  FORMAT format = TEXT_OUT;
1700  int target = 0;
1701  std::string xsl;
1702  std::string ns;
1703  std::string fname;
1704  std::ofstream ofs;
1705 
1706  int i(1);
1707  while (i < argc)
1708  {
1709  std::string arg(argv[i]);
1710  std::string next_arg;
1711  if (i + 1 < argc) next_arg = argv[i + 1];
1712  else next_arg = "";
1713 
1714  if (arg == "--text") { format = TEXT_OUT; break; }
1715  if (arg == "--xml")
1716  {
1717  if (next_arg == "")
1718  {
1719  fname = argv[0];
1720  fname += ".xml";
1721  }
1722  else
1723  {
1724  fname = next_arg;
1725  }
1726  format = XML_OUT;
1727  ofs.open(fname.c_str());
1728  }
1729  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
1730  if ( arg == "--cerr" ) { target = 1; break; }
1731  if ( arg == "--xsl" )
1732  {
1733  if (next_arg == "") xsl = "default.xsl";
1734  else xsl = next_arg;
1735  }
1736  if ( arg == "--namespace" )
1737  {
1738  if (next_arg == "")
1739  {
1740  std::cerr << "no namespace specified" << std::endl;
1741  exit(1);
1742  }
1743  else
1744  {
1745  xsl = next_arg;
1746  }
1747  }
1748  ++i;
1749  }
1750  CppUnit::TextUi::TestRunner runner;
1751  if ( ns.empty() )
1752  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1753  else
1754  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1755  CppUnit::Outputter* outputter = 0;
1756  std::ostream* stream = target ? &std::cerr : &std::cout;
1757  switch ( format )
1758  {
1759  case TEXT_OUT :
1760  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
1761  break;
1762  case XML_OUT :
1763  std::cout << "XML_OUT" << std::endl;
1764  outputter = new CppUnit::XmlOutputter(&runner.result(),
1765  ofs, "shift_jis");
1766  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
1767  break;
1768  case COMPILER_OUT :
1769  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
1770  break;
1771  }
1772  runner.setOutputter(outputter);
1773  runner.run();
1774  return 0; // runner.run() ? 0 : 1;
1775 }
1776 #endif // MAIN
1777 #endif // InPort_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
::RTC::BufferStatus::Enum m_read_return_value
ConnectorListeners class.
virtual ~Logger(void)
Virtual destructor.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
InPortTests()
Constructor.
int main(int argc, char **argv)
void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data receive notification.
static Mutex mutex
The mutex of the pointer to the Manager.
Definition: Manager.h:1555
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer&#39;s pointer.
::OpenRTM::PortStatus put(const ::OpenRTM::CdrData &data)
coil::Properties & properties()
Get properties.
Definition: InPortBase.cpp:134
virtual ReturnCode length(size_t n)
Set the buffer length.
virtual DataType * wptr(long int n=0)
Get the writing pointer.
virtual void header(int level)
Message prefix appender function.
InPortConnector base class.
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)
Read data from the buffer.
CORBA Consumer class.
void setLogger(Logger *logger)
InPort template class.
OutPortConnector base class.
coil::Properties properties
Connection properties.
InPortProvider class.
virtual ~InPortProvider(void)
Destructor.
RT-Component.
LogStreamBuf m_logStreamBuf
void setConnector(RTC::OutPortConnector *connector)
std::vector< DataType > m_buffer
RTC::OutPortConsumer::ReturnCode put(const cdrMemoryStream &data)
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer&#39;s pointer.
InPortMock(const char *name, DataType &value, int bufsize=64, bool read_block=false, bool write_block=false, int read_timeout=0, int write_timeout=0)
Definition: InPortTests.cpp:99
ConnectorBase::ReturnCode InPortPushConnector_read_return_value
PortableServer::POA_ptr m_pPOA
log_streambuf template class
void publishInterfaceProfile(SDOPackage::NVList &properties)
Mutex class.
RT component logger class.
AbstractClass * Creator()
Creator template.
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
void init(coil::Properties &prop)
Initializing configuration.
void log(const std::string &msg)
OutPortConnector class.
virtual void setUp()
Test initialization.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
ConnectorListeners m_listeners
ConnectorDataListener listener.
Definition: InPortBase.h:870
coil::Properties get_m_properties()
::InPort::Logger RTC_logger
~InPortTests()
Destructor.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
Manager class.
Definition: Manager.h:80
virtual void operator()(const DataType &value)
Callback function.
::OpenRTM::PortStatus put(const ::OpenRTM::CdrData &data)
virtual ReturnCode reset()
Reset the buffer status.
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
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
void set_read_return_value(::RTC::BufferStatus::Enum value)
virtual const char * name()
Get port name.
Definition: InPort.h:195
PortCallback class.
OutPortConsumer class.
RTC::InPortConnector * createConnector_public(RTC::ConnectorProfile &cprof, coil::Properties &prop, RTC::InPortProvider *provider)
log_stream< char > LogStream
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
virtual const ConnectorInfo & profile()
Getting ConnectorInfo.
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
virtual ReturnCode read(cdrMemoryStream &data)
Reading data.
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
virtual ReturnCode advanceRptr(long int n=1)
Forward n reading pointers.
InPortProvider.
RTComponent manager class.
virtual bool isEmpty()
Check whether the data is newest.
Definition: InPort.h:276
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
void unsubscribeInterface(const SDOPackage::NVList &properties)
std::vector< std::string > m_log
Data convert callback abstract class on read()
Definition: PortCallback.h:385
std::vector< std::string > vstring
Definition: stringutil.h:37
void setOnReadConvert(OnReadConvert< DataType > *on_rconvert)
Set callback when data is readout to the InPort buffer.
Definition: InPort.h:533
InPortConnector * createConnector(ConnectorProfile &cprof, coil::Properties &prop, InPortProvider *provider)
InPortPushConnector creation.
Definition: InPortBase.cpp:902
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
void setLogger(Logger *logger)
void test_isNew(void)
isNew()メソッドのテスト
static Manager * manager
The pointer to the Manager.
Definition: Manager.h:1546
virtual CdrBufferBase * createBuffer(ConnectorInfo &info)
create buffer
Connector base class.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
Definition: BufferStatus.h:157
string inport
Definition: README_gen.py:90
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
void clearLog(void)
RTC::InPortBase::ConnectorList get_m_connectors()
BUFFERSTATUS_ENUM RingBufferMock(long int length=8)
::OpenRTM::InPortCdr_var m_objref
virtual ReturnCode advanceWptr(long int n=1)
Forward n writing pointers.
DATAPORTSTATUS_ENUM typedef std::vector< InPortConnector * > ConnectorList
Definition: InPortBase.h:73
virtual ReturnCode disconnect()
disconnect
int InPortPushConnector_read
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
Definition: stringutil.cpp:568
NameValue and NVList utility functions.
coil::vstring get_m_consumerTypes()
Callback abstract class on write()
Definition: PortCallback.h:192
virtual const char * name()
Getting Connector name.
CORBA sequence utility template functions.
Push type connector class.
void setDataFlowType(const char *dataflow_type)
Set the dataflow type.
virtual DataType operator()(const DataType &value)
Callback method.
virtual size_t length(void) const
Get the buffer length.
Manager()
Protected Constructor.
Definition: Manager.cpp:80
virtual void operator()()
Callback function.
void test_name(void)
name()メソッドのテスト
virtual size_t writable() const
Get a writable number.
virtual void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
bool setLevel(const char *level)
Set log level by string.
::RTC::BufferStatus::Enum ReturnCode
bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data receive notification.
prop
Organization::get_organization_property ();.
RTC::Port implementation for InPort.
void setInterfaceType(const char *interface_type)
Set the interface type.
CPPUNIT_TEST_SUITE_REGISTRATION(InPort::InPortTests)
void setLogger(Logger *logger)
virtual bool empty(void) const
Check on whether the buffer is empty.
void Destructor(AbstractClass *&obj)
Destructor template.
void init(coil::Properties &prop)
Initializing configuration.
Logger rtclog
Logger stream.
Class represents a set of properties.
Definition: Properties.h:101
void test_isEmpty(void)
isEmpty()メソッドのテスト
coil::Properties m_properties
Properties.
Definition: InPortBase.h:829
InPort template class.
Definition: InPort.h:89
void setConnector(RTC::InPortConnector *connector)
set Connector
virtual bool isNew()
Check whether the data is newest.
Definition: InPort.h:225
virtual bool publishInterface(SDOPackage::NVList &properties)
Publish interface information.
virtual ~InPortPushConnector()
Destructor.
Logger(const char *name="")
Constructor.
void set_readable_return_value(size_t value)
::OutPortBase::Logger logger
RTC::PortService_var m_objref
Object Reference of the Port.
Definition: PortBase.h:2079
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
OutPortConsumer abstract class.
RTComponent header.
void setOnRead(OnRead< DataType > *on_read)
Set callback when data is read from the InPort buffer.
Definition: InPort.h:505
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 size_t readable() const
Write data into the buffer.
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
void log(const std::string &msg)
void test_read(void)
read(),operator>>(DataType&),setOnRead(),setOnReadConvert()メソッドのテスト
static const char * m_levelString[]
Definition: SystemLogger.h:342
void init(coil::Properties &prop)
Initializing properties.
Definition: InPortBase.cpp:96
coil::vstring get_m_providerTypes()
BufferBase abstract class.
Definition: BufferBase.h:104
virtual ~RingBufferMock(void)
void test_setOnWrite(void)
setOnWrite()メソッドのテスト
std::string getDate(void)
Get the current formatted date/time string Get the current datetime described by specified format...
DATAPORTSTATUS_ENUM InPortProvider()
Constructor.
InPortConsumer class.
virtual DataType * rptr(long int n=0)
Get the reading pointer.
void setSubscriptionType(const char *subs_type)
Set the subscription type.
virtual bool full(void) const
Check on whether the buffer is full.
CORBA::ORB_ptr m_pORB
bool read()
Readout the value from DataPort.
Definition: InPort.h:378
bool subscribeInterface(const SDOPackage::NVList &properties)
Callback abstract class on read()
Definition: PortCallback.h:323
virtual void tearDown()
Test finalization.
RTC::CdrBufferBase * get_m_thebuffer()
virtual void init(const coil::Properties &prop)
Set the buffer.
bool initORB()
CORBA ORB initialization.
Definition: Manager.cpp:1073
void test_setOnUnderflow()
setOnUnderflow()メソッドのテスト


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58