22 #ifndef InPortPushConnector_cpp 23 #define InPortPushConnector_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)
111 m_log.push_back(msg);
117 for (
int i = 0; i < (int) m_log.size(); ++i)
119 if (m_log[i] == msg) ++count;
132 template <
class DataType>
141 logger.
log(
"RingBufferMock::Constructor");
142 m_read_return_value = BUFFER_OK;
155 m_read_return_value = value;
178 return ::RTC::BufferStatus::BUFFER_OK;
186 return ::RTC::BufferStatus::BUFFER_OK;
192 virtual DataType*
wptr(
long int n = 0)
202 return ::RTC::BufferStatus::BUFFER_OK;
210 return ::RTC::BufferStatus::BUFFER_OK;
217 long int sec = -1,
long int nsec = -1)
219 return ::RTC::BufferStatus::BUFFER_OK;
241 virtual DataType*
rptr(
long int n = 0)
251 return ::RTC::BufferStatus::BUFFER_OK;
259 return ::RTC::BufferStatus::BUFFER_OK;
265 virtual DataType&
get()
274 long int sec = -1,
long int nsec = -1)
276 if (m_logger != NULL)
278 m_logger->log(
"RingBufferMock::read");
281 return m_read_return_value;
315 template <
class DataType>
325 public virtual POA_OpenRTM::InPortCdr,
326 public virtual PortableServer::RefCountServantBase
343 if (m_logger != NULL)
345 m_logger->log(
"InPortCorbaCdrProviderMock::setBuffer");
352 ::OpenRTM::PortStatus
put(const ::OpenRTM::CdrData&
data)
353 throw (CORBA::SystemException)
355 return ::OpenRTM::PORT_OK;
363 if (m_logger != NULL)
365 m_logger->log(
"InPortCorbaCdrProviderMock::init");
429 :
public CppUnit::TestFixture
433 CPPUNIT_TEST(test_InPortPushConnector);
434 CPPUNIT_TEST(test_read);
435 CPPUNIT_TEST(test_disconnect);
437 CPPUNIT_TEST_SUITE_END();
455 m_pORB = CORBA::ORB_init(argc, argv);
456 m_pPOA = PortableServer::POA::_narrow(
457 m_pORB->resolve_initial_references(
"RootPOA"));
458 m_pPOA->the_POAManager()->activate();
529 addFactory(
"ring_buffer_mock",
530 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
531 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
533 RTC::ConnectorProfile prof;
536 "ring_buffer_mock"));
542 prop << conn_prop.
getNode(
"dataport");
552 CPPUNIT_ASSERT_EQUAL(0,
553 logger.
countLog(
"InPortCorbaCdrProviderMock::init"));
554 CPPUNIT_ASSERT_EQUAL(0,
555 logger.
countLog(
"InPortCorbaCdrProviderMock::setBuffer"));
556 CPPUNIT_ASSERT_EQUAL(0,
559 CPPUNIT_ASSERT_EQUAL(1,
560 logger.
countLog(
"InPortCorbaCdrProviderMock::init"));
561 CPPUNIT_ASSERT_EQUAL(1,
562 logger.
countLog(
"InPortCorbaCdrProviderMock::setBuffer"));
563 CPPUNIT_ASSERT_EQUAL(1,
572 RTC::ConnectorProfile prof_err;
577 prop << conn_prop.
getNode(
"dataport");
580 prof_err.connector_id,
584 CPPUNIT_FAIL(
"The exception was not thrown. ");
586 catch(std::bad_alloc& e)
591 CPPUNIT_FAIL(
"The exception not intended was thrown .");
593 delete connector_err;
605 RTC::ConnectorProfile prof;
608 "ring_buffer_mock"));
614 prop << conn_prop.
getNode(
"dataport");
626 CPPUNIT_ASSERT_EQUAL(0,
628 connector->
read(cdr);
629 CPPUNIT_ASSERT_EQUAL(1,
634 ret = connector->
read(cdr);
638 ret = connector->
read(cdr);
642 ret = connector->
read(cdr);
646 ret = connector->
read(cdr);
661 addFactory(
"ring_buffer_mock",
662 coil::Creator<RTC::CdrBufferBase, CdrRingBufferMock>,
663 coil::Destructor<RTC::CdrBufferBase, CdrRingBufferMock>);
665 RTC::ConnectorProfile prof;
668 "ring_buffer_mock"));
674 prop << conn_prop.
getNode(
"dataport");
704 int main(
int argc,
char* argv[])
717 std::string arg(argv[i]);
718 std::string next_arg;
719 if (i + 1 < argc) next_arg = argv[i + 1];
722 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
735 ofs.open(fname.c_str());
737 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
738 if ( arg ==
"--cerr" ) { target = 1;
break; }
739 if ( arg ==
"--xsl" )
741 if (next_arg ==
"") xsl =
"default.xsl";
744 if ( arg ==
"--namespace" )
748 std::cerr <<
"no namespace specified" << std::endl;
758 CppUnit::TextUi::TestRunner runner;
760 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
762 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
763 CppUnit::Outputter* outputter = 0;
764 std::ostream* stream = target ? &std::cerr : &std::cout;
768 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
771 std::cout <<
"XML_OUT" << std::endl;
772 outputter =
new CppUnit::XmlOutputter(&runner.result(),
774 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
777 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
780 runner.setOutputter(outputter);
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
InPortPushConnector class.
ConnectorListeners class.
int main(int argc, char **argv)
::RTC::BufferStatus::Enum m_read_return_value
InPortConnector base class.
InPortPushConnectorTests()
Constructor.
virtual void operator()(const RTC::ConnectorInfo &info)
Virtual Callback method.
virtual ReturnCode read(cdrMemoryStream &data)=0
Destructor.
virtual ReturnCode reset()
Reset the buffer status.
int countLog(const std::string &msg)
void addListener(ConnectorDataListener *listener, bool autoclean)
Add the listener.
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.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void setBuffer(RTC::BufferBase< cdrMemoryStream > *buffer)
Setting outside buffer's pointer.
InPortCorbaCdrProviderMock(void)
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
void test_InPortPushConnector()
Constructor メソッドテスト
void addListener(ConnectorListener *listener, bool autoclean)
Add the listener.
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
virtual size_t writable() const
Get a writable number.
Enum
DataPortStatus return codes.
void setLogger(Logger *logger)
virtual void init(const coil::Properties &prop)
Set the buffer.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
RTComponent manager class.
PortableServer::POA_ptr m_pPOA
std::vector< DataType > m_buffer
virtual void setUp()
Test initialization.
virtual ReturnCode disconnect()=0
Disconnect connection.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
virtual bool empty(void) const
Check on whether the buffer is empty.
ConnectorDataListenerHolder connectorData_[CONNECTOR_DATA_LISTENER_NUM]
ConnectorDataListenerType listener array The ConnectorDataListenerType listener is stored...
void test_read()
read メソッドテスト
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
std::vector< std::string > m_log
ConnectorDataListenerT class.
virtual ~InPortCorbaCdrProviderMock(void)
NameValue and NVList utility functions.
CORBA sequence utility template functions.
Push type connector class.
std::string name
Connection name.
void log(const std::string &msg)
~InPortPushConnectorTests()
Destructor.
::RTC::BufferStatus::Enum ReturnCode
void init(coil::Properties &prop)
Initializing configuration.
prop
Organization::get_organization_property ();.
virtual ~RingBufferMock(void)
RTC::Port implementation for InPort.
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
void setConnector(RTC::InPortConnector *connector)
set Connector
Class represents a set of properties.
BUFFERSTATUS_ENUM RingBufferMock(long int length=8)
virtual DataType * rptr(long int n=0)
Get the reading pointer.
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
void set_read_return_value(::RTC::BufferStatus::Enum value)
void setLogger(Logger *logger)
virtual size_t readable() const
Write data into the buffer.
void unsubscribeInterface(const SDOPackage::NVList &properties)
virtual bool full(void) const
Check on whether the buffer is full.
bool subscribeInterface(const SDOPackage::NVList &properties)
virtual size_t length(void) const
Get the buffer length.
::OutPortBase::Logger logger
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
virtual void tearDown()
Test finalization.
void test_disconnect()
disconnect メソッドテスト
Properties & getNode(const std::string &key)
Get node of properties.
virtual ReturnCode length(size_t n)
Set the buffer length.
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)
Read data from the buffer.
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
DataListener(const char *name)
coil::vstring refToVstring(const CorbaRefSequence &objlist)
BufferBase abstract class.
virtual ReturnCode advanceWptr(long int n=1)
Forward n writing pointers.
ConnListener(const char *name)
RTC's Port administration class.
::OpenRTM::PortStatus put(const ::OpenRTM::CdrData &data)
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
virtual DataType * wptr(long int n=0)
Get the writing pointer.
RTC::ConnectorListeners m_listeners
virtual ReturnCode advanceRptr(long int n=1)
Forward n reading pointers.
CPPUNIT_TEST_SUITE_REGISTRATION(InPortPushConnector::InPortPushConnectorTests)