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> 38 #include <rtm/idl/BasicDataTypeSkel.h> 39 #include <rtm/idl/DataPortSkel.h> 47 #define WTIMEOUT_USEC 1000000 48 #define USEC_PER_SEC 1000000 60 template <
class DataType>
111 void log(
const std::string& msg)
113 m_log.push_back(msg);
120 for (
int i = 0; i < (int) m_log.size(); ++i)
122 if (m_log[i] == msg) ++count;
158 if (m_logger != NULL)
160 m_logger->log(
"InPortCorbaCdrConsumerMock::init");
218 public virtual ::POA_OpenRTM::OutPortCdr,
219 public virtual PortableServer::RefCountServantBase
236 if (m_logger != NULL)
238 m_logger->log(
"OutPortCorbaCdrProviderMock::init");
245 virtual ::OpenRTM::PortStatus
get(::OpenRTM::CdrData_out
data)
247 return ::OpenRTM::PORT_OK;
328 template <
class DataType>
337 logger.
log(
"RingBufferMock::Constructor");
338 m_read_return_value = BUFFER_OK;
339 m_readable_return_value = 0;
353 m_read_return_value = value;
376 return ::RTC::BufferStatus::BUFFER_OK;
384 return ::RTC::BufferStatus::BUFFER_OK;
390 virtual DataType*
wptr(
long int n = 0)
400 return ::RTC::BufferStatus::BUFFER_OK;
408 return ::RTC::BufferStatus::BUFFER_OK;
415 long int sec = -1,
long int nsec = -1)
417 return ::RTC::BufferStatus::BUFFER_OK;
439 virtual DataType*
rptr(
long int n = 0)
449 return ::RTC::BufferStatus::BUFFER_OK;
457 return ::RTC::BufferStatus::BUFFER_OK;
463 virtual DataType&
get()
472 long int sec = -1,
long int nsec = -1)
474 if (m_logger != NULL)
476 m_logger->log(
"RingBufferMock::read");
479 return m_read_return_value;
487 return m_readable_return_value;
495 m_readable_return_value = value;
522 template <
class DataType>
549 cdrMemoryStream cdr(data);
550 CORBA::ULong inlen = cdr.bufSize();
553 cdr.get_octet_array (oct, (
int)inlen);
555 for(
int ic(0);ic<(int)inlen;++ic)
557 lval = lval+(int)(oct[ic]<<(ic*8));
559 std::stringstream ss;
561 if (m_logger != NULL)
563 m_logger->log(
"PublisherFlushMock::write");
564 m_logger->log(ss.str());
585 if (m_logger != NULL)
587 m_logger->log(
"PublisherFlushMock::activate");
589 logger.
log(
"PublisherFlushMock::activate");
599 if (m_logger != NULL)
601 m_logger->log(
"PublisherFlushMock::deactivate");
603 logger.
log(
"PublisherFlushMock::deactivate");
620 if (m_logger != NULL)
622 m_logger->log(
"PublisherFlushMock::setConsumer");
624 logger.
log(
"PublisherFlushMock::setConsumer");
634 if (m_logger != NULL)
636 m_logger->log(
"PublisherFlushMock::setBuffer");
639 m_logger->log(
"buffer NG");
643 m_logger->log(
"buffer OK");
646 logger.
log(
"PublisherFlushMock::setBuffer");
665 if (m_logger != NULL)
667 m_logger->log(
"PublisherFlushMock::setListener");
670 m_logger->log(
"listeners NG");
674 m_logger->log(
"listeners OK");
677 logger.
log(
"PublisherFlushMock::setListener");
734 OutPortPushConnector::OutPortPushConnector(
ConnectorInfo info,
739 m_consumer(consumer), m_publisher(0),
m_listeners(listeners), m_buffer(buffer)
782 RTC_logger.
log(
"OutPortPushConnector::write");
784 cdrMemoryStream cdr(data);
786 std::ostringstream os;
788 RTC_logger.
log(os.str());
823 return new ::OutPort::PublisherFlushMock();
844 m_runner(NULL), m_terminator(NULL)
882 std::vector<std::string> args(
coil::split(NULL,
" "));
884 args.insert(args.begin(),
"manager");
886 int argc(args.size());
889 m_pORB = CORBA::ORB_init(argc, argv);
891 CORBA::Object_var obj = m_pORB->resolve_initial_references(
"RootPOA");
892 PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(obj);
893 CORBA::PolicyList policies;
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))
904 m_pPOAManager = m_pPOA->the_POAManager();
908 RTC_ERROR((
"Exception: Caught unknown exception in initORB()." ));
1003 const int maxsize = 256;
1006 return std::string(buf);
1049 m_interfaceType.c_str());
1064 "dataport.interface_type",
1065 m_interfaceType.c_str()))
1083 m_portType = port_type;
1095 m_dataType = data_type;
1107 m_interfaceType = interface_type;
1119 m_dataflowType = dataflow_type;
1131 m_subscriptionType = subs_type;
1150 template <
class DataType>
1170 if (m_logger != NULL)
1172 m_logger->log(
"OnWriteMock::operator");
1191 template <
class DataType>
1201 : m_amplitude(amplitude)
1212 td.data = m_amplitude.data * value.data;
1213 if (m_logger != NULL)
1215 m_logger->log(
"OnWriteConvertMock::operator");
1236 :
public CppUnit::TestFixture
1239 CPPUNIT_TEST(test_write);
1248 CPPUNIT_TEST_SUITE_END();
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();
1299 RTC::TimedDouble td;
1309 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnWriteMock::operator"));
1310 ret = outport.
write();
1312 CPPUNIT_ASSERT_EQUAL(
false, ret);
1313 CPPUNIT_ASSERT_EQUAL(1,logger.
countLog(
"OnWriteMock::operator"));
1315 RTC::ConnectorProfile prof;
1320 CPPUNIT_ASSERT(0!= connector);
1324 RTC::TimedDouble amplitude;
1335 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnWriteConvertMock::operator"));
1337 ret = outport.
write();
1339 CPPUNIT_ASSERT_EQUAL(
true, ret);
1340 CPPUNIT_ASSERT_EQUAL(logcount+1,
1342 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnReadConvertMock::operator"));
1345 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnReadConvertMock::operator"));
1347 ret = outport.
write();
1349 CPPUNIT_ASSERT_EQUAL(
true, ret);
1350 CPPUNIT_ASSERT_EQUAL(logcount+1,
1352 CPPUNIT_ASSERT_EQUAL(1,logger.
countLog(
"OnWriteConvertMock::operator"));
1363 ret = outport.
write();
1365 CPPUNIT_ASSERT_EQUAL(
true, ret);
1366 CPPUNIT_ASSERT_EQUAL(logcount+1,
1368 CPPUNIT_ASSERT_EQUAL(writedatacount+1,
1416 RTC::OutPortPushConnector_write_return_value
1423 RTC::TimedDouble doublevalue;
1424 doublevalue.data = 55;
1426 ret = outport.
write(doublevalue);
1428 CPPUNIT_ASSERT_EQUAL(
true, ret);
1429 CPPUNIT_ASSERT_EQUAL(logcount+1,
1431 CPPUNIT_ASSERT_EQUAL(writedatacount+1,
1434 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&outport));
1445 RTC::TimedDouble bindValue;
1451 onWrite.m_value.data = 0;
1455 RTC::TimedDouble writeValue;
1456 writeValue.data = 3.14159265;
1457 CPPUNIT_ASSERT(outPort->
write(writeValue));
1460 CPPUNIT_ASSERT_EQUAL(writeValue.data, onWrite.m_value.data);
1462 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(outPort));
1473 RTC::TimedDouble bindValue;
1483 RTC::TimedDouble InbindValue;
1488 inPort->
init(dummy);
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;
1511 RTC::TimedDouble writeValue;
1512 writeValue.data = 3.14159265;
1513 for(
int ic(0);ic<8;++ic)
1515 outPort->
write(writeValue);
1517 CPPUNIT_ASSERT(! outPort->
write(writeValue));
1520 CPPUNIT_ASSERT_EQUAL(writeValue.data, onWrite.
m_value.data);
1533 RTC::TimedDouble bindValue;
1542 RTC::TimedDouble InbindValue;
1547 inPort->
init(dummy);
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;
1570 RTC::TimedDouble writeValue;
1571 writeValue.data = 3.14159265;
1572 for(
int ic(0);ic<8;++ic)
1574 outPort->
write(writeValue);
1576 CPPUNIT_ASSERT(! outPort->
write(writeValue));
1591 RTC::TimedDouble bindValue;
1601 RTC::TimedDouble InbindValue;
1606 inPort->
init(dummy);
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;
1628 RTC::TimedDouble writeValue;
1629 writeValue.data = 3.14159265;
1630 CPPUNIT_ASSERT(outPort->
write(writeValue));
1641 RTC::TimedDouble bindValue;
1645 RTC::ConnectorProfile prof;
1651 RTC::TimedDouble amplitude;
1652 amplitude.data = 1.41421356;
1656 for (
int i = 0; i < 100; ++i)
1658 RTC::TimedDouble writeValue;
1659 writeValue.data = i * 3.14159265;
1660 RTC::TimedDouble expectedValue;
1661 expectedValue.data = amplitude.data * writeValue.data;
1663 std::ostringstream os;
1664 os << expectedValue.data;
1667 CPPUNIT_ASSERT(outPort->
write(writeValue));
1668 CPPUNIT_ASSERT_EQUAL(logcount+1,
1673 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(outPort));
1688 RTC::TimedDouble bindValue;
1694 RTC::TimedDouble InbindValue;
1699 inPort->
init(dummy);
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;
1730 for(
int ic(0);ic<8;++ic)
1732 RTC::TimedDouble writeValue;
1733 writeValue.data = 3.14159265;
1734 outPort->
write(writeValue);
1736 for (
int i = 0; i < 10; ++i) {
1738 RTC::TimedDouble writeValue;
1739 writeValue.data = i * 3.14159265;
1742 CPPUNIT_ASSERT(! outPort->
write(writeValue));
1749 timersub(&tm_cur, &tm_pre, &tm_diff);
1751 double interval = (double) tm_diff.tv_sec
1756 CPPUNIT_ASSERT_DOUBLES_EQUAL(
1773 int main(
int argc,
char* argv[])
1786 std::string arg(argv[i]);
1787 std::string next_arg;
1788 if (i + 1 < argc) next_arg = argv[i + 1];
1791 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
1804 ofs.open(fname.c_str());
1806 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
1807 if ( arg ==
"--cerr" ) { target = 1;
break; }
1808 if ( arg ==
"--xsl" )
1810 if (next_arg ==
"") xsl =
"default.xsl";
1811 else xsl = next_arg;
1813 if ( arg ==
"--namespace" )
1817 std::cerr <<
"no namespace specified" << std::endl;
1827 CppUnit::TextUi::TestRunner runner;
1829 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1831 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1832 CppUnit::Outputter* outputter = 0;
1833 std::ostream* stream = target ? &std::cerr : &std::cout;
1837 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
1840 std::cout <<
"XML_OUT" << std::endl;
1841 outputter =
new CppUnit::XmlOutputter(&runner.result(),
1843 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
1846 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
1849 runner.setOutputter(outputter);
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.
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.
int main(int argc, char **argv)
static Mutex mutex
The mutex of the pointer to the Manager.
RTC::PublisherBase::ReturnCode activate()
activation
void setLogger(Logger *logger)
virtual void activate()
Connector activation.
void test_write_OnWriteConvert()
virtual void header(int level)
Message prefix appender function.
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
OutPortConnector base class.
void test_write_OnOverflow()
write()メソッドのOnOverflowコールバック呼出テスト
void setLogger(Logger *logger)
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
void setOnWriteConvert(OnWriteConvert< DataType > *on_wconvert)
Set OnWriteConvert callback.
Data convert callback abstract class on write()
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.
virtual size_t writable() const
Get a writable number.
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.
::RTC::BufferStatus::Enum m_read_return_value
std::vector< std::pair< std::string, std::string > > NVList
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)
ConnectorListeners m_listeners
ConnectorDataListener listener.
::InPort::Logger RTC_logger
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
virtual ReturnCode advanceRptr(long int n=1)
Forward n reading pointers.
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.
virtual bool empty(void) const
Check on whether the buffer is empty.
log_stream< char > LogStream
virtual DATAPORTSTATUS_ENUM ~OutPortProvider(void)
Destructor.
static Manager & instance()
Get instance of the manager.
OutPortConnector * createConnector(const ConnectorProfile &cprof, coil::Properties &prop, InPortConsumer *consumer)
OutPortPushConnector creation.
Enum
DataPortStatus return codes.
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.
static Manager * manager
The pointer to the Manager.
bool isActive()
If publisher is active state.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
BUFFERSTATUS_ENUM RingBufferMock(long int length=8)
void setLogger(Logger *logger)
void setDataType(const char *data_type)
Set the data type.
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
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.
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.
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()
virtual void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
virtual size_t length(void) const
Get the buffer length.
bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data send notification.
void setDataFlowType(const char *dataflow_type)
Set the data flow type.
virtual bool full(void) const
Check on whether the buffer is full.
OutPortMock(const char *name, DataType &value)
Manager()
Protected Constructor.
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
virtual ~OutPortCorbaCdrProviderMock(void)
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
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.
size_t m_readable_return_value
virtual size_t readable() const
Write data into the buffer.
void test_write_OnOverflow_not_full()
バッファフルでない時の、write()メソッドのOnOverflowコールバック呼出テスト
virtual bool publishInterface(SDOPackage::NVList &properties)
Publish interface information.
OutPortCorbaCdrProviderMock(void)
virtual bool write(DataType &value)
Write data.
Logger(const char *name="")
Constructor.
void setOnWrite(OnWrite< DataType > *on_write)
Set OnWrite callback.
::OutPortBase::Logger logger
InPortCorbaCdrConsumerMock(void)
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. ...
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[]
void init(coil::Properties &prop)
Initializing properties.
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.
virtual ~InPortCorbaCdrConsumerMock(void)
BufferBase abstract class.
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.
RTC::TimedDouble m_amplitude
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
void unsubscribeInterface(const SDOPackage::NVList &properties)
virtual void setBuffer(CdrBufferBase *buffer)=0
Setting outside buffer'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.
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.