22 #ifndef OutPortPushConnector_cpp 23 #define OutPortPushConnector_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> 67 const RTC::TimedLong&
data)
90 std::cout <<
"------------------------------" << std::endl;
91 std::cout <<
"Connector Listener: " <<
m_name << std::endl;
92 std::cout <<
"Profile::name: " << info.
name << std::endl;
93 std::cout <<
"------------------------------" << std::endl;
106 void log(
const std::string& msg)
108 m_log.push_back(msg);
114 for (
int i = 0; i < (int) m_log.size(); ++i)
116 if (m_log[i] == msg) ++count;
149 if (m_logger != NULL)
151 m_logger->log(
"InPortCorbaCdrConsumerMock::init");
226 cdrMemoryStream cdr(data);
227 CORBA::ULong inlen = cdr.bufSize();
231 std::stringstream ss;
233 if (m_logger != NULL)
235 m_logger->log(
"PublisherFlushMock::write");
236 m_logger->log(ss.str());
257 if (m_logger != NULL)
259 m_logger->log(
"PublisherFlushMock::activate");
261 logger.
log(
"PublisherFlushMock::activate");
271 if (m_logger != NULL)
273 m_logger->log(
"PublisherFlushMock::deactivate");
275 logger.
log(
"PublisherFlushMock::deactivate");
292 if (m_logger != NULL)
294 m_logger->log(
"PublisherFlushMock::setConsumer");
296 logger.
log(
"PublisherFlushMock::setConsumer");
306 if (m_logger != NULL)
308 m_logger->log(
"PublisherFlushMock::setBuffer");
311 m_logger->log(
"buffer NG");
315 m_logger->log(
"buffer OK");
318 logger.
log(
"PublisherFlushMock::setBuffer");
337 if (m_logger != NULL)
339 m_logger->log(
"PublisherFlushMock::setListener");
342 m_logger->log(
"listeners NG");
346 m_logger->log(
"listeners OK");
349 logger.
log(
"PublisherFlushMock::setListener");
400 cdrMemoryStream cdr(data);
401 CORBA::ULong inlen = cdr.bufSize();
405 std::stringstream ss;
408 if (m_logger != NULL)
410 m_logger->log(
"PublisherNewMock::write");
411 m_logger->log(ss.str());
432 if (m_logger != NULL)
434 m_logger->log(
"PublisherNewMock::activate");
436 logger.
log(
"PublisherNewMock::activate");
446 if (m_logger != NULL)
448 m_logger->log(
"PublisherNewMock::deactivate");
450 logger.
log(
"PublisherNewMock::deactivate");
469 if (m_logger != NULL)
471 m_logger->log(
"PublisherNewMock::setConsumer");
473 logger.
log(
"PublisherNewMock::setConsumer");
483 if (m_logger != NULL)
485 m_logger->log(
"PublisherNewMock::setBuffer");
488 m_logger->log(
"buffer NG");
492 m_logger->log(
"buffer OK");
495 logger.
log(
"PublisherNewMock::setBuffer");
514 if (m_logger != NULL)
516 m_logger->log(
"PublisherNewMock::setListener");
519 m_logger->log(
"listeners NG");
523 m_logger->log(
"listeners OK");
526 logger.
log(
"PublisherNewMock::setListener");
554 :
public CppUnit::TestFixture
558 CPPUNIT_TEST(test_OutPortPushConnector);
559 CPPUNIT_TEST(test_write);
560 CPPUNIT_TEST(test_disconnect_getBuffer);
563 CPPUNIT_TEST_SUITE_END();
581 m_pORB = CORBA::ORB_init(argc, argv);
582 m_pPOA = PortableServer::POA::_narrow(
583 m_pORB->resolve_initial_references(
"RootPOA"));
584 m_pPOA->the_POAManager()->activate();
664 RTC::ConnectorProfile prof;
678 prop << conn_prop.
getNode(
"dataport");
688 CPPUNIT_ASSERT_EQUAL(0,
689 logger.
countLog(
"InPortCorbaCdrConsumerMock::init"));
690 CPPUNIT_ASSERT_EQUAL(0,
691 PublisherNewMock::logger.countLog(
"PublisherNewMock::setBuffer"));
692 CPPUNIT_ASSERT_EQUAL(0,
693 PublisherNewMock::logger.countLog(
"buffer OK"));
694 CPPUNIT_ASSERT_EQUAL(0,
695 PublisherNewMock::logger.countLog(
"PublisherNewMock::setConsumer"));
697 CPPUNIT_ASSERT_EQUAL(1,
698 logger.
countLog(
"InPortCorbaCdrConsumerMock::init"));
699 CPPUNIT_ASSERT_EQUAL(1,
700 PublisherNewMock::logger.countLog(
"PublisherNewMock::setBuffer"));
701 CPPUNIT_ASSERT_EQUAL(1,
702 PublisherNewMock::logger.countLog(
"buffer OK"));
703 CPPUNIT_ASSERT_EQUAL(0,
704 PublisherNewMock::logger.countLog(
"buffer NG"));
705 CPPUNIT_ASSERT_EQUAL(1,
706 PublisherNewMock::logger.countLog(
"PublisherNewMock::setConsumer"));
718 prop << conn_prop.
getNode(
"dataport");
724 CPPUNIT_ASSERT_EQUAL(1,
725 logger.
countLog(
"InPortCorbaCdrConsumerMock::init"));
726 CPPUNIT_ASSERT_EQUAL(0,
727 PublisherFlushMock::logger.countLog(
"PublisherFlushMock::setBuffer"));
728 CPPUNIT_ASSERT_EQUAL(0,
729 PublisherFlushMock::logger.countLog(
"buffer OK"));
730 CPPUNIT_ASSERT_EQUAL(0,
731 PublisherFlushMock::logger.countLog(
"PublisherFlushMock::setConsumer"));
733 CPPUNIT_ASSERT_EQUAL(2,
734 logger.
countLog(
"InPortCorbaCdrConsumerMock::init"));
735 CPPUNIT_ASSERT_EQUAL(1,
736 PublisherFlushMock::logger.countLog(
"PublisherFlushMock::setBuffer"));
737 CPPUNIT_ASSERT_EQUAL(1,
738 PublisherFlushMock::logger.countLog(
"buffer OK"));
739 CPPUNIT_ASSERT_EQUAL(1,
740 PublisherFlushMock::logger.countLog(
"PublisherFlushMock::setConsumer"));
749 RTC::ConnectorProfile prof_err;
753 prop << conn_prop.
getNode(
"dataport");
756 prof_err.connector_id,
760 CPPUNIT_FAIL(
"The exception was not thrown. ");
762 catch(std::bad_alloc& e)
767 CPPUNIT_FAIL(
"The exception not intended was thrown .");
769 delete connector_err;
784 RTC::ConnectorProfile prof;
798 prop << conn_prop.
getNode(
"dataport");
809 CPPUNIT_ASSERT_EQUAL(0,
810 PublisherNewMock::logger.countLog(
"PublisherNewMock::write"));
811 CPPUNIT_ASSERT_EQUAL(0,
812 PublisherNewMock::logger.countLog(
"12345"));
819 ret = connector->
write(cdr);
822 CPPUNIT_ASSERT_EQUAL(1,
823 PublisherNewMock::logger.countLog(
"PublisherNewMock::write"));
824 CPPUNIT_ASSERT_EQUAL(1,
825 PublisherNewMock::logger.countLog(
"12345"));
842 RTC::ConnectorProfile prof;
856 prop << conn_prop.
getNode(
"dataport");
890 RTC::ConnectorProfile prof;
904 prop << conn_prop.
getNode(
"dataport");
915 CPPUNIT_ASSERT_EQUAL(0,
916 PublisherNewMock::logger.countLog(
"PublisherNewMock::activate"));
918 CPPUNIT_ASSERT_EQUAL(1,
919 PublisherNewMock::logger.countLog(
"PublisherNewMock::activate"));
923 CPPUNIT_ASSERT_EQUAL(0,
924 PublisherNewMock::logger.countLog(
"PublisherNewMock::deactivate"));
927 CPPUNIT_ASSERT_EQUAL(1,
928 PublisherNewMock::logger.countLog(
"PublisherNewMock::deactivate"));
942 int main(
int argc,
char* argv[])
955 std::string arg(argv[i]);
956 std::string next_arg;
957 if (i + 1 < argc) next_arg = argv[i + 1];
960 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
973 ofs.open(fname.c_str());
975 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
976 if ( arg ==
"--cerr" ) { target = 1;
break; }
977 if ( arg ==
"--xsl" )
979 if (next_arg ==
"") xsl =
"default.xsl";
982 if ( arg ==
"--namespace" )
986 std::cerr <<
"no namespace specified" << std::endl;
996 CppUnit::TextUi::TestRunner runner;
998 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
1000 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
1001 CppUnit::Outputter* outputter = 0;
1002 std::ostream* stream = target ? &std::cerr : &std::cout;
1006 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
1009 std::cout <<
"XML_OUT" << std::endl;
1010 outputter =
new CppUnit::XmlOutputter(&runner.result(),
1012 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
1015 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
1018 runner.setOutputter(outputter);
1023 #endif // InPort_cpp SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
ConnectorListeners class.
~OutPortPushConnectorTests()
Destructor.
InPortConsumer abstract class.
int main(int argc, char **argv)
void test_write()
write メソッドテスト
OutPortPushConnectorTests()
Constructor.
RTC::PublisherBase::ReturnCode write(const cdrMemoryStream &data, unsigned long sec, unsigned long usec)
Write data.
virtual void activate()=0
Connector activation.
OutPortConnector base class.
RTC::PublisherBase::ReturnCode setConsumer(RTC::InPortConsumer *consumer)
Store InPort consumer.
virtual void setUp()
Test initialization.
RTC::PublisherBase::ReturnCode setConsumer(RTC::InPortConsumer *consumer)
Store InPort consumer.
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
std::vector< std::string > m_log
AbstractClass * Creator()
Creator template.
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.
virtual CdrBufferBase * getBuffer()=0
Getting Buffer.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
PortableServer::POA_ptr m_pPOA
void test_activate_deactivate()
activate メソッドテスト
void addListener(ConnectorListener *listener, bool autoclean)
Add the listener.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
bool isActive()
If publisher is active state.
RTC::PublisherBase::ReturnCode activate()
activation
RTC::PublisherBase::ReturnCode deactivate()
deactivation
bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data send notification.
void setLogger(Logger *logger)
ConnectorDataListenerHolder connectorData_[CONNECTOR_DATA_LISTENER_NUM]
ConnectorDataListenerType listener array The ConnectorDataListenerType listener is stored...
virtual ReturnCode write(const cdrMemoryStream &data)=0
Destructor.
void init(coil::Properties &prop)
Initializing configuration.
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
void setLogger(Logger *logger)
void setLogger(Logger *logger)
ConnectorDataListenerT class.
RTC::PublisherBase::ReturnCode init(coil::Properties &prop)
Initializing configuration.
Push type connector class.
RTC::ConnectorListeners m_listeners
virtual void tearDown()
Test finalization.
virtual void operator()(const RTC::ConnectorInfo &info)
Virtual Callback method.
NameValue and NVList utility functions.
CORBA sequence utility template functions.
virtual ReturnCode disconnect()=0
Disconnect connection.
std::string name
Connection name.
void log(const std::string &msg)
RTC::PublisherBase::ReturnCode activate()
activation
void test_disconnect_getBuffer()
disconnect メソッドテスト
CPPUNIT_TEST_SUITE_REGISTRATION(OutPortPushConnector::OutPortPushConnectorTests)
::RTC::BufferStatus::Enum ReturnCode
RTC::PublisherBase::ReturnCode write(const cdrMemoryStream &data, unsigned long sec, unsigned long usec)
Write data.
prop
Organization::get_organization_property ();.
DataListener(const char *name)
RTC::Port implementation for InPort.
void Destructor(AbstractClass *&obj)
Destructor template.
RTC::PublisherBase::ReturnCode setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
Class represents a set of properties.
OutPortPushConnector class.
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
void test_OutPortPushConnector()
Constructor メソッドテスト
RTC::PublisherBase::ReturnCode init(coil::Properties &prop)
Initializing configuration.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
virtual ~InPortCorbaCdrConsumerMock(void)
bool isActive()
If publisher is active state.
RTC::PublisherBase::ReturnCode setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
::OutPortBase::Logger logger
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
RTC::PublisherBase::ReturnCode deactivate()
deactivation
Properties & getNode(const std::string &key)
Get node of properties.
def test_activate_deactivate(message, arg0, arg1, arg2)
Only activation and deactivation are repeated.
int countLog(const std::string &msg)
coil::vstring refToVstring(const CorbaRefSequence &objlist)
BufferBase abstract class.
ConnListener(const char *name)
RTC's Port administration class.
InPortCorbaCdrConsumerMock(void)
void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data send notification.
virtual void deactivate()=0
Connector deactivation.
PublisherBase::ReturnCode setBuffer(RTC::CdrBufferBase *buffer)
Setting buffer pointer.
RTC::PublisherBase::ReturnCode setBuffer(RTC::CdrBufferBase *buffer)
Setting buffer pointer.