22 #ifndef InPortPullConnector_cpp 23 #define InPortPullConnector_cpp 25 #include <cppunit/ui/text/TestRunner.h> 26 #include <cppunit/TextOutputter.h> 27 #include <cppunit/extensions/TestFactoryRegistry.h> 28 #include <cppunit/extensions/HelperMacros.h> 29 #include <cppunit/TestAssert.h> 31 #include <coil/Properties.h> 33 #include <rtm/idl/BasicDataTypeSkel.h> 34 #include <rtm/idl/DataPortSkel.h> 70 const RTC::TimedLong&
data)
93 std::cout <<
"------------------------------" << std::endl;
94 std::cout <<
"Connector Listener: " <<
m_name << std::endl;
95 std::cout <<
"Profile::name: " << info.
name << std::endl;
96 std::cout <<
"------------------------------" << std::endl;
109 void log(
const std::string& msg)
112 m_log.push_back(msg);
118 for (
int i = 0; i < (int) m_log.size(); ++i)
120 if (m_log[i] == msg) ++count;
133 template <
class DataType>
142 logger.
log(
"RingBufferMock::Constructor");
143 m_read_return_value = BUFFER_OK;
144 m_write_return_value = BUFFER_OK;
157 m_read_return_value = value;
165 m_write_return_value = value;
188 return ::RTC::BufferStatus::BUFFER_OK;
196 return ::RTC::BufferStatus::BUFFER_OK;
202 virtual DataType*
wptr(
long int n = 0)
212 return ::RTC::BufferStatus::BUFFER_OK;
220 return ::RTC::BufferStatus::BUFFER_OK;
227 long int sec = -1,
long int nsec = -1)
229 if (m_logger != NULL)
231 m_logger->log(
"RingBufferMock::write");
234 return m_write_return_value;
256 virtual DataType*
rptr(
long int n = 0)
266 return ::RTC::BufferStatus::BUFFER_OK;
274 return ::RTC::BufferStatus::BUFFER_OK;
280 virtual DataType&
get()
289 long int sec = -1,
long int nsec = -1)
291 if (m_logger != NULL)
293 m_logger->log(
"RingBufferMock::read");
296 return m_read_return_value;
332 template <
class DataType>
360 if (m_logger != NULL)
362 m_logger->log(
"OutPortCorbaCdrConsumerMock::setBuffer");
369 ::OpenRTM::PortStatus
put(const ::OpenRTM::CdrData&
data)
370 throw (CORBA::SystemException)
372 return ::OpenRTM::PORT_OK;
380 if (m_logger != NULL)
382 m_logger->log(
"OutPortCorbaCdrConsumerMock::init");
425 if (m_logger != NULL)
427 m_logger->log(
"OutPortCorbaCdrConsumerMock::get");
456 :
public CppUnit::TestFixture
460 CPPUNIT_TEST(test_InPortPullConnector);
461 CPPUNIT_TEST(test_read);
462 CPPUNIT_TEST(test_disconnect);
463 CPPUNIT_TEST_SUITE_END();
481 m_pORB = CORBA::ORB_init(argc, argv);
482 m_pPOA = PortableServer::POA::_narrow(
483 m_pORB->resolve_initial_references(
"RootPOA"));
484 m_pPOA->the_POAManager()->activate();
552 addFactory(
"ring_buffer_mock",
553 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
554 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
556 RTC::ConnectorProfile prof;
559 "ring_buffer_mock"));
565 prop << conn_prop.
getNode(
"dataport");
575 CPPUNIT_ASSERT_EQUAL(0,
576 logger.
countLog(
"OutPortCorbaCdrConsumerMock::setBuffer"));
577 CPPUNIT_ASSERT_EQUAL(0,
580 CPPUNIT_ASSERT_EQUAL(1,
581 logger.
countLog(
"OutPortCorbaCdrConsumerMock::setBuffer"));
582 CPPUNIT_ASSERT_EQUAL(1,
591 RTC::ConnectorProfile prof_err;
596 prop << conn_prop.
getNode(
"dataport");
599 prof_err.connector_id,
603 CPPUNIT_FAIL(
"The exception was not thrown. ");
605 catch(std::bad_alloc& e)
610 CPPUNIT_FAIL(
"The exception not intended was thrown .");
613 delete connector_err;
625 RTC::ConnectorProfile prof;
628 "ring_buffer_mock"));
634 prop << conn_prop.
getNode(
"dataport");
647 CPPUNIT_ASSERT_EQUAL(0,
648 logger.
countLog(
"OutPortCorbaCdrConsumerMock::get"));
649 ret = connector->
read(cdr);
651 CPPUNIT_ASSERT_EQUAL(1,
652 logger.
countLog(
"OutPortCorbaCdrConsumerMock::get"));
655 ret = connector->
read(cdr);
670 addFactory(
"ring_buffer_mock",
671 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
672 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
674 RTC::ConnectorProfile prof;
677 "ring_buffer_mock"));
683 prop << conn_prop.
getNode(
"dataport");
711 int main(
int argc,
char* argv[])
724 std::string arg(argv[i]);
725 std::string next_arg;
726 if (i + 1 < argc) next_arg = argv[i + 1];
729 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
742 ofs.open(fname.c_str());
744 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
745 if ( arg ==
"--cerr" ) { target = 1;
break; }
746 if ( arg ==
"--xsl" )
748 if (next_arg ==
"") xsl =
"default.xsl";
751 if ( arg ==
"--namespace" )
755 std::cerr <<
"no namespace specified" << std::endl;
765 CppUnit::TextUi::TestRunner runner;
767 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
769 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
770 CppUnit::Outputter* outputter = 0;
771 std::ostream* stream = target ? &std::cerr : &std::cout;
775 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
778 std::cout <<
"XML_OUT" << std::endl;
779 outputter =
new CppUnit::XmlOutputter(&runner.result(),
781 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
784 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
787 runner.setOutputter(outputter);
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
ConnectorListeners class.
virtual size_t readable() const
Write data into the buffer.
virtual DataType * wptr(long int n=0)
Get the writing pointer.
int main(int argc, char **argv)
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
virtual DataType * rptr(long int n=0)
Get the reading pointer.
InPortConnector base class.
virtual ReturnCode read(cdrMemoryStream &data)=0
Destructor.
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
void test_read()
read メソッドテスト
DataListener(const char *name)
::RTC::BufferStatus::Enum m_read_return_value
virtual void init(const coil::Properties &prop)
Set the buffer.
void test_InPortPullConnector()
Constructor メソッドテスト
virtual ReturnCode advanceWptr(long int n=1)
Forward n writing pointers.
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)
Read data from the buffer.
ConnListener(const char *name)
void addListener(ConnectorDataListener *listener, bool autoclean)
Add the listener.
CPPUNIT_TEST_SUITE_REGISTRATION(InPortPullConnector::InPortPullConnectorTests)
std::vector< std::pair< std::string, std::string > > NVList
void log(const std::string &msg)
ConnectorListenerHolder connector_[CONNECTOR_LISTENER_NUM]
ConnectorListenerType listener array The ConnectorListenerType listener is stored.
InPortPullConnector class.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
virtual void setUp()
Test initialization.
RTC::ConnectorListeners m_listeners
void test_disconnect()
disconnect メソッドテスト
virtual bool full(void) const
Check on whether the buffer is full.
void addListener(ConnectorListener *listener, bool autoclean)
Add the listener.
virtual ~OutPortCorbaCdrConsumerMock(void)
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
::RTC::BufferStatus::Enum m_write_return_value
InPortPullConnectorTests()
Constructor.
Enum
DataPortStatus return codes.
RTComponent manager class.
void log(const std::string &msg)
void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data receive notification.
std::vector< DataType > m_buffer
void setLogger(Logger *logger)
virtual ReturnCode disconnect()=0
Disconnect connection.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
ConnectorDataListenerHolder connectorData_[CONNECTOR_DATA_LISTENER_NUM]
ConnectorDataListenerType listener array The ConnectorDataListenerType listener is stored...
void set_write_return_value(::RTC::BufferStatus::Enum value)
virtual bool empty(void) const
Check on whether the buffer is empty.
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
ConnectorDataListenerT class.
::OpenRTM::PortStatus put(const ::OpenRTM::CdrData &data)
virtual size_t writable() const
Get a writable number.
NameValue and NVList utility functions.
OutPortCorbaCdrConsumerMock(void)
bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data receive notification.
CORBA sequence utility template functions.
std::string name
Connection name.
BUFFERSTATUS_ENUM RingBufferMock(long int length=8)
~InPortPullConnectorTests()
Destructor.
int countLog(const std::string &msg)
std::vector< std::string > m_log
::RTC::BufferStatus::Enum ReturnCode
prop
Organization::get_organization_property ();.
virtual ~RingBufferMock(void)
RTC::Port implementation for InPort.
PortableServer::POA_ptr m_pPOA
Class represents a set of properties.
virtual ReturnCode reset()
Reset the buffer status.
void set_read_return_value(::RTC::BufferStatus::Enum value)
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
virtual size_t length(void) const
Get the buffer length.
void init(coil::Properties &prop)
Initializing configuration.
InPortPull type connector class.
::OutPortBase::Logger logger
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
OutPortConsumer abstract class.
Properties & getNode(const std::string &key)
Get node of properties.
RTC::OutPortConsumer::ReturnCode put(const cdrMemoryStream &data)
coil::vstring refToVstring(const CorbaRefSequence &objlist)
BufferBase abstract class.
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer's pointer.
virtual void tearDown()
Test finalization.
RTC's Port administration class.
virtual void operator()(const RTC::ConnectorInfo &info)
Virtual Callback method.
void publishInterfaceProfile(SDOPackage::NVList &properties)
virtual ReturnCode length(size_t n)
Set the buffer length.
virtual ReturnCode advanceRptr(long int n=1)
Forward n reading pointers.
void setLogger(Logger *logger)