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> 47 #include <rtm/idl/BasicDataTypeSkel.h> 48 #include <rtm/idl/DataPortSkel.h> 59 #include <coil/Guard.h> 60 #include <coil/Mutex.h> 61 #include <rtm/idl/RTCSkel.h> 65 #include <coil/UUID.h> 69 #include <coil/Logger.h> 77 #define WTIMEOUT_USEC 1000000 78 #define USEC_PER_SEC 1000000 90 template <
class DataType>
101 bool read_block =
false,
bool write_block =
false,
102 int read_timeout = 0,
int write_timeout = 0)
174 void log(
const std::string& msg)
176 m_log.push_back(msg);
182 for (
int i = 0; i < (int) m_log.size(); ++i)
184 if (m_log[i] == msg) ++count;
203 public virtual POA_OpenRTM::InPortCdr,
204 public virtual PortableServer::RefCountServantBase
212 setInterfaceType(
"corba_cdr");
218 std::vector<std::string> args(
coil::split(
"-ORBendPoint giop:tcp:2809",
" "));
220 args.insert(args.begin(),
"manager");
222 int argc(args.size());
225 CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
230 orb->object_to_string(
m_objref.in())));
238 PortableServer::ObjectId_var oid;
239 oid = _default_POA()->servant_to_id(
this);
240 _default_POA()->deactivate_object(oid);
248 if (m_logger != NULL)
250 m_logger->log(
"InPortCorbaCdrProviderMock::setBuffer");
268 ::OpenRTM::PortStatus
put(const ::OpenRTM::CdrData&
data)
269 throw (CORBA::SystemException)
271 return ::OpenRTM::PORT_OK;
279 if (m_logger != NULL)
281 m_logger->log(
"InPortCorbaCdrProviderMock::init");
361 if (m_logger != NULL)
363 m_logger->log(
"OutPortCorbaCdrConsumerMock::setBuffer");
381 ::OpenRTM::PortStatus
put(const ::OpenRTM::CdrData&
data)
382 throw (CORBA::SystemException)
384 return ::OpenRTM::PORT_OK;
392 if (m_logger != NULL)
394 m_logger->log(
"OutPortCorbaCdrConsumerMock::init");
458 template <
class DataType>
467 logger.
log(
"RingBufferMock::Constructor");
468 m_read_return_value = BUFFER_OK;
469 m_readable_return_value = 0;
483 m_read_return_value = value;
506 return ::RTC::BufferStatus::BUFFER_OK;
514 return ::RTC::BufferStatus::BUFFER_OK;
520 virtual DataType*
wptr(
long int n = 0)
530 return ::RTC::BufferStatus::BUFFER_OK;
538 return ::RTC::BufferStatus::BUFFER_OK;
545 long int sec = -1,
long int nsec = -1)
547 return ::RTC::BufferStatus::BUFFER_OK;
569 virtual DataType*
rptr(
long int n = 0)
579 return ::RTC::BufferStatus::BUFFER_OK;
587 return ::RTC::BufferStatus::BUFFER_OK;
593 virtual DataType&
get()
602 long int sec = -1,
long int nsec = -1)
604 if (m_logger != NULL)
606 m_logger->log(
"RingBufferMock::read");
609 return m_read_return_value;
617 return m_readable_return_value;
625 m_readable_return_value = value;
652 template <
class DataType>
673 InPortPushConnector::InPortPushConnector(
ConnectorInfo profile,
681 InPortPushConnector_read = 0;
682 InPortPushConnector_read_return_value = PORT_OK;
683 if(profile.
properties[
"InPortBaseTests"]==
"bad_alloc")
685 throw std::bad_alloc();
711 RTC_logger.
log(
"InPortPushConnector::read");
743 m_runner(NULL), m_terminator(NULL)
781 std::vector<std::string> args(
coil::split(NULL,
" "));
783 args.insert(args.begin(),
"manager");
785 int argc(args.size());
788 m_pORB = CORBA::ORB_init(argc, argv);
790 CORBA::Object_var obj = m_pORB->resolve_initial_references(
"RootPOA");
791 PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(obj);
792 CORBA::PolicyList policies;
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))
803 m_pPOAManager = m_pPOA->the_POAManager();
807 RTC_ERROR((
"Exception: Caught unknown exception in initORB()." ));
902 const int maxsize = 256;
905 return std::string(buf);
1016 template <
class DataType>
1035 if (m_logger != NULL)
1037 m_logger->log(
"OnReadMock::operator");
1057 template <
class DataType>
1075 if (m_logger != NULL)
1077 m_logger->log(
"OnReadConvertMock::operator");
1106 template <
class DataType>
1151 :
public CppUnit::TestFixture
1155 CPPUNIT_TEST(test_name);
1156 CPPUNIT_TEST(test_isNew);
1157 CPPUNIT_TEST(test_isEmpty);
1158 CPPUNIT_TEST(test_read);
1172 CPPUNIT_TEST_SUITE_END();
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();
1215 addFactory(
"corba_cdr",
1228 addFactory(
"corba_cdr",
1241 addFactory(
"ring_buffer",
1242 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
1243 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
1261 CPPUNIT_ASSERT_EQUAL(std::string(
"test_name0"),
1262 std::string(inport.
name()));
1264 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1279 CPPUNIT_ASSERT_EQUAL(
false, inport.
isNew());
1281 RTC::ConnectorProfile prof;
1286 CPPUNIT_ASSERT(0!= connector);
1288 CPPUNIT_ASSERT_EQUAL(
false, inport.
isNew());
1295 CPPUNIT_ASSERT(0!= pbuffer);
1297 CPPUNIT_ASSERT_EQUAL(
false, inport.
isNew());
1298 pbuffer->set_readable_return_value((
size_t)5);
1300 CPPUNIT_ASSERT_EQUAL(
true, inport.
isNew());
1303 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1318 CPPUNIT_ASSERT_EQUAL(
true, inport.
isEmpty());
1320 RTC::ConnectorProfile prof;
1325 CPPUNIT_ASSERT(0!= connector);
1328 CPPUNIT_ASSERT_EQUAL(
true, inport.
isEmpty());
1335 CPPUNIT_ASSERT(0!= pbuffer);
1337 CPPUNIT_ASSERT_EQUAL(
true, inport.
isEmpty());
1338 pbuffer->set_readable_return_value((
size_t)5);
1341 CPPUNIT_ASSERT_EQUAL(
false, inport.
isEmpty());
1344 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1365 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnReadMock::operator"));
1366 ret = inport.
read();
1368 CPPUNIT_ASSERT_EQUAL(
false, ret);
1369 CPPUNIT_ASSERT_EQUAL((CORBA::Long)123, tl.data);
1370 CPPUNIT_ASSERT_EQUAL(1,logger.
countLog(
"OnReadMock::operator"));
1372 RTC::ConnectorProfile prof;
1377 CPPUNIT_ASSERT(0!= connector);
1387 inport.operator>>(tl_);
1388 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl_.data);
1391 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnReadConvertMock::operator"));
1393 ret = inport.
read();
1395 CPPUNIT_ASSERT_EQUAL(
true, ret);
1396 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1397 CPPUNIT_ASSERT_EQUAL(logcount+1,
1399 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnReadConvertMock::operator"));
1402 CPPUNIT_ASSERT_EQUAL(0,logger.
countLog(
"OnReadConvertMock::operator"));
1404 ret = inport.
read();
1406 CPPUNIT_ASSERT_EQUAL(
true, ret);
1407 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1408 CPPUNIT_ASSERT_EQUAL(logcount+1,
1410 CPPUNIT_ASSERT_EQUAL(1,logger.
countLog(
"OnReadConvertMock::operator"));
1420 ret = inport.
read();
1422 CPPUNIT_ASSERT_EQUAL(
true, ret);
1423 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1424 CPPUNIT_ASSERT_EQUAL(logcount+1,
1429 RTC::InPortPushConnector_read_return_value
1432 ret = inport.
read();
1434 CPPUNIT_ASSERT_EQUAL(
false, ret);
1435 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1436 CPPUNIT_ASSERT_EQUAL(logcount+1,
1442 RTC::InPortPushConnector_read_return_value
1445 ret = inport.
read();
1447 CPPUNIT_ASSERT_EQUAL(
false, ret);
1448 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1449 CPPUNIT_ASSERT_EQUAL(logcount+1,
1455 RTC::InPortPushConnector_read_return_value
1458 ret = inport.
read();
1460 CPPUNIT_ASSERT_EQUAL(
false, ret);
1461 CPPUNIT_ASSERT_EQUAL((CORBA::Long)777, tl.data);
1462 CPPUNIT_ASSERT_EQUAL(logcount+1,
1465 m_pPOA->deactivate_object(*m_pPOA->servant_to_id(&inport));
1696 int main(
int argc,
char* argv[])
1709 std::string arg(argv[i]);
1710 std::string next_arg;
1711 if (i + 1 < argc) next_arg = argv[i + 1];
1714 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
1727 ofs.open(fname.c_str());
1729 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
1730 if ( arg ==
"--cerr" ) { target = 1;
break; }
1731 if ( arg ==
"--xsl" )
1733 if (next_arg ==
"") xsl =
"default.xsl";
1734 else xsl = next_arg;
1736 if ( arg ==
"--namespace" )
1740 std::cerr <<
"no namespace specified" << std::endl;
1750 CppUnit::TextUi::TestRunner runner;
1752 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1754 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1755 CppUnit::Outputter* outputter = 0;
1756 std::ostream* stream = target ? &std::cerr : &std::cout;
1760 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
1763 std::cout <<
"XML_OUT" << std::endl;
1764 outputter =
new CppUnit::XmlOutputter(&runner.result(),
1766 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
1769 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
1772 runner.setOutputter(outputter);
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.
size_t m_readable_return_value
void setLogger(Logger *logger)
::RTC::BufferStatus::Enum m_read_return_value
ConnectorListeners class.
virtual ~Logger(void)
Virtual destructor.
#define RTC_ERROR(fmt)
Error log output macro.
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.
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer's pointer.
::OpenRTM::PortStatus put(const ::OpenRTM::CdrData &data)
coil::Properties & properties()
Get properties.
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.
void setLogger(Logger *logger)
OutPortConnector base class.
coil::Properties properties
Connection properties.
virtual ~InPortProvider(void)
Destructor.
LogStreamBuf m_logStreamBuf
void setConnector(RTC::OutPortConnector *connector)
std::vector< DataType > m_buffer
RTC::OutPortConsumer::ReturnCode put(const cdrMemoryStream &data)
virtual ~OutPortCorbaCdrConsumerMock(void)
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer'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)
ConnectorBase::ReturnCode InPortPushConnector_read_return_value
PortableServer::POA_ptr m_pPOA
log_streambuf template class
virtual ~InPortCorbaCdrProviderMock(void)
void publishInterfaceProfile(SDOPackage::NVList &properties)
RT component logger class.
AbstractClass * Creator()
Creator template.
virtual bool full(void) const
Check on whether the buffer is full.
std::vector< std::pair< std::string, std::string > > NVList
void init(coil::Properties &prop)
Initializing configuration.
void log(const std::string &msg)
virtual void setUp()
Test initialization.
virtual size_t length(void) const
Get the buffer length.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
ConnectorListeners m_listeners
ConnectorDataListener listener.
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.
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.
void set_read_return_value(::RTC::BufferStatus::Enum value)
virtual const char * name()
Get port name.
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.
static Manager & instance()
Get instance of the manager.
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
virtual const ConnectorInfo & profile()
Getting ConnectorInfo.
Enum
DataPortStatus return codes.
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.
RTComponent manager class.
virtual bool isEmpty()
Check whether the data is newest.
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()
std::vector< std::string > vstring
void setOnReadConvert(OnReadConvert< DataType > *on_rconvert)
Set callback when data is readout to the InPort buffer.
InPortCorbaCdrProviderMock(void)
InPortConnector * createConnector(ConnectorProfile &cprof, coil::Properties &prop, InPortProvider *provider)
InPortPushConnector creation.
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
void setLogger(Logger *logger)
void test_isNew(void)
isNew()メソッドのテスト
static Manager * manager
The pointer to the Manager.
virtual CdrBufferBase * createBuffer(ConnectorInfo &info)
create buffer
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
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
virtual ReturnCode disconnect()
disconnect
int InPortPushConnector_read
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
NameValue and NVList utility functions.
coil::vstring get_m_consumerTypes()
Callback abstract class on write()
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.
Manager()
Protected Constructor.
virtual void operator()()
Callback function.
virtual size_t readable() const
Write data into the buffer.
void test_name(void)
name()メソッドのテスト
void setLogger(Logger *logger)
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)
void Destructor(AbstractClass *&obj)
Destructor template.
void init(coil::Properties &prop)
Initializing configuration.
Logger rtclog
Logger stream.
Class represents a set of properties.
void test_isEmpty(void)
isEmpty()メソッドのテスト
coil::Properties m_properties
Properties.
void setConnector(RTC::InPortConnector *connector)
set Connector
virtual bool isNew()
Check whether the data is newest.
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.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
OutPortConsumer abstract class.
void setOnRead(OnRead< DataType > *on_read)
Set callback when data is read from the InPort buffer.
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 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[]
void init(coil::Properties &prop)
Initializing properties.
coil::vstring get_m_providerTypes()
BufferBase abstract class.
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.
virtual DataType * rptr(long int n=0)
Get the reading pointer.
void setSubscriptionType(const char *subs_type)
Set the subscription type.
virtual bool empty(void) const
Check on whether the buffer is empty.
bool read()
Readout the value from DataPort.
bool subscribeInterface(const SDOPackage::NVList &properties)
virtual size_t writable() const
Get a writable number.
Callback abstract class on read()
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.
void test_setOnUnderflow()
setOnUnderflow()メソッドのテスト
OutPortCorbaCdrConsumerMock(void)