OutPortBaseTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log: OutPortBaseTests.cpp,v $
14  * Revision 1.2 2008/02/21 07:36:39 arafune
15  * Some tests were added.
16  *
17  * Revision 1.1 2007/12/20 07:50:17 arafune
18  * *** empty log message ***
19  *
20  * Revision 1.1 2006/12/02 18:55:54 n-ando
21  * *** empty log message ***
22  *
23  *
24  */
25 
26 #ifndef OutPortBase_cpp
27 #define OutPortBase_cpp
28 
29 #include <cppunit/ui/text/TestRunner.h>
30 #include <cppunit/TextOutputter.h>
31 #include <cppunit/extensions/TestFactoryRegistry.h>
32 #include <cppunit/extensions/HelperMacros.h>
33 #include <cppunit/TestAssert.h>
34 
35 #include <rtm/idl/BasicDataTypeSkel.h>
36 #include <rtm/idl/DataPortSkel.h>
37 #include <rtm/Typename.h>
38 #include <rtm/PublisherBase.h>
39 #include <rtm/OutPortBase.h>
40 #include <rtm/InPort.h>
41 #include <rtm/CorbaConsumer.h>
42 #include <rtm/InPortConsumer.h>
43 #include <rtm/OutPort.h>
44 #include <rtm/OutPortConnector.h>
45 #include <rtm/PortAdmin.h>
46 #include <rtm/PublisherBase.h>
47 #include <rtm/PublisherFlush.h>
48 #include <rtm/PublisherNew.h>
49 #include <rtm/PublisherPeriodic.h>
50 #include <rtm/SystemLogger.h>
52 #include <rtm/OutPortProvider.h>
54 #include <rtm/ConnectorListener.h>
55 
56 // ConnectorDataListenerType count
57 #define cdl_len 10
58 // ConnectorListenerType count
59 #define cl_len 7
60 
65 namespace OutPortBase
66 {
67 
68  // ConnectorDataListenerType
69  static const char* str_cdl[] =
70  {
71  "ON_BUFFER_WRITE",
72  "ON_BUFFER_FULL",
73  "ON_BUFFER_WRITE_TIMEOUT",
74  "ON_BUFFER_OVERWRITE",
75  "ON_BUFFER_READ",
76  "ON_SEND",
77  "ON_RECEIVED",
78  "ON_RECEIVER_FULL",
79  "ON_RECEIVER_TIMEOUT",
80  "ON_RECEIVER_ERROR"
81  };
82 
83  // ConnectorListenerType
84  static const char* str_cl[] =
85  {
86  "ON_BUFFER_EMPTY",
87  "ON_BUFFER_READ_TIMEOUT",
88  "ON_SENDER_EMPTY",
89  "ON_SENDER_TIMEOUT",
90  "ON_SENDER_ERROR",
91  "ON_CONNECT",
92  "ON_DISCONNECT"
93  };
94 
95  static int cdl_count;
96  static int cl_count;
97 
99  : public RTC::ConnectorDataListenerT<RTC::TimedLong>
100  {
101  public:
102  DataListener(const char* name) : m_name(name)
103  {
104  ++cdl_count;
105  }
106  virtual ~DataListener()
107  {
108  --cdl_count;
109  }
110 
111  virtual void operator()(const RTC::ConnectorInfo& info,
112  const RTC::TimedLong& data)
113  {
114  std::cout << "------------------------------" << std::endl;
115  std::cout << "Data Listener: " << m_name << std::endl;
116  std::cout << "Profile::name: " << info.name << std::endl;
117  std::cout << "------------------------------" << std::endl;
118  };
119  std::string m_name;
120  };
121 
122 
124  : public RTC::ConnectorListener
125  {
126  public:
127  ConnListener(const char* name) : m_name(name)
128  {
129  ++cl_count;
130  }
131  virtual ~ConnListener()
132  {
133  --cl_count;
134  }
135 
136  virtual void operator()(const RTC::ConnectorInfo& info)
137  {
138  std::cout << "------------------------------" << std::endl;
139  std::cout << "Connector Listener: " << m_name << std::endl;
140  std::cout << "Profile::name: " << info.name << std::endl;
141  std::cout << "------------------------------" << std::endl;
142  };
143  std::string m_name;
144  };
145 
152  : public RTC::PublisherBase
153  {
154  public:
155  PublisherA(std::string& footPrints) : m_footPrints(footPrints) {};
156  virtual ~PublisherA() {
157  m_footPrints += "a";
158  }
159 
160  void update() { m_footPrints += "A"; }
161 
162  std::string& m_footPrints;
163  // std::string m_footPrints;
164  };
171  : public RTC::PublisherBase
172  {
173  public:
174  std::string& m_footPrints;
175  // std::string m_footPrints;
176  PublisherB(std::string& footPrints) : m_footPrints(footPrints) {};
177  virtual ~PublisherB() {
178  m_footPrints += "b";
179  }
180  void update() { m_footPrints += "B"; }
181  };
188  : public RTC::PublisherBase
189  {
190  public:
191  std::string& m_footPrints;
192  // std::string m_footPrints;
193  PublisherC(std::string& footPrints) : m_footPrints(footPrints) {};
194  virtual ~PublisherC() {
195  m_footPrints += "c";
196  }
197  void update() { m_footPrints += "C"; }
198  };
205  : public RTC::PublisherBase
206  {
207  public:
208  std::string& m_footPrints;
209  // std::string m_footPrints;
210  PublisherD(std::string& footPrints) : m_footPrints(footPrints) {};
211  virtual ~PublisherD() {
212  m_footPrints += "d";
213  }
214  void update() { m_footPrints += "D"; }
215  };
221  class Logger
222  {
223  public:
224  void log(const std::string& msg)
225  {
226  m_log.push_back(msg);
227  }
228 
229  int countLog(const std::string& msg)
230  {
231  int count = 0;
232  for (int i = 0; i < (int) m_log.size(); ++i)
233  {
234  if (m_log[i] == msg) ++count;
235  }
236  return count;
237  }
238 
239  void clearLog(void)
240  {
241  m_log.clear();
242  }
243  private:
244  std::vector<std::string> m_log;
245  };
251  template <class DataType>
253  : public RTC::BufferBase<DataType>
254  {
255  public:
257  RingBufferMock(long int length = 8)
258  {
259  m_logger = NULL;
260  logger.log("RingBufferMock::Constructor");
261  m_read_return_value = BUFFER_OK;
262  }
263  virtual ~RingBufferMock(void)
264  {
265  }
266 
267 
273  {
274  m_read_return_value = value;
275  }
280  virtual void init(const coil::Properties& prop)
281  {
282  }
287  virtual size_t length(void) const
288  {
289  return 0;
290  }
295  virtual ReturnCode length(size_t n)
296  {
297  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
298  }
303  virtual ReturnCode reset()
304  {
305  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
306  }
311  virtual DataType* wptr(long int n = 0)
312  {
313  return &m_data;
314  }
319  virtual ReturnCode advanceWptr(long int n = 1)
320  {
321  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
322  }
327  virtual ReturnCode put(const DataType& value)
328  {
329  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
330  }
335  virtual ReturnCode write(const DataType& value,
336  long int sec = -1, long int nsec = -1)
337  {
338  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
339  }
344  virtual size_t writable() const
345  {
346  return 0;
347  }
352  virtual bool full(void) const
353  {
354  return true;
355  }
360  virtual DataType* rptr(long int n = 0)
361  {
362  return &m_data;
363  }
368  virtual ReturnCode advanceRptr(long int n = 1)
369  {
370  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
371  }
376  virtual ReturnCode get(DataType& value)
377  {
378  return ::RTC::BufferStatus::BUFFER_OK; //BUFFER_OK;
379  }
384  virtual DataType& get()
385  {
386  return m_data;
387  }
392  virtual ReturnCode read(DataType& value,
393  long int sec = -1, long int nsec = -1)
394  {
395  if (m_logger != NULL)
396  {
397  m_logger->log("RingBufferMock::read");
398  }
399  logger.log("RingBufferMock::read");
400  return m_read_return_value; //BUFFER_OK;
401  }
406  virtual size_t readable() const
407  {
408  return 0;
409  }
414  virtual bool empty(void) const
415  {
416  return true;
417  }
423  {
424  m_logger = logger;
425  }
426 
427  static Logger logger;
428  private:
429  DataType m_data;
430  std::vector<DataType> m_buffer;
433  };
434  template <class DataType>
443  : public RTC::OutPortBase
444  {
445  public:
450  OutPortBaseMock(const char* name, const char* data_type)
451  : RTC::OutPortBase(name , data_type)
452  {
453  }
458  {
459  return m_properties;
460  }
464  RTC::OutPortProvider* createProvider_public(RTC::ConnectorProfile& cprof,
466  {
467  return createProvider(cprof, prop);
468  }
472  RTC::InPortConsumer* createCondumer_public(RTC::ConnectorProfile& cprof,
474  {
475  return createConsumer(cprof, prop);
476  }
480  RTC::OutPortConnector* createConnector_public(const RTC::ConnectorProfile& cprof,
483  {
484  return createConnector(cprof,prop,provider);
485  }
489  virtual RTC::ReturnCode_t
490  publishInterfaces_public(RTC::ConnectorProfile& connector_profile)
491  {
492  return publishInterfaces(connector_profile);
493  }
497  virtual RTC::ReturnCode_t
498  subscribeInterfaces_public(RTC::ConnectorProfile& connector_profile)
499  {
500  return subscribeInterfaces(connector_profile);
501  }
507  {
508  return m_consumerTypes;
509  }
515  {
516  return m_providerTypes;
517  }
522  {
523  initConsumers();
524  }
529  {
530  initProviders();
531  }
537  {
538  return m_connectors;
539  }
545  bool write()
546  {
547  return true;
548  }
549 
550 
551  };
557  template <class DataType>
559  : public RTC::InPortBase
560  {
561  public:
562  InPortMock(const char* name, DataType& value)
563  : InPortBase(name,toTypename<DataType>()) {}
567  virtual RTC::ReturnCode_t
568  publishInterfaces_public(RTC::ConnectorProfile& connector_profile)
569  {
570  return publishInterfaces(connector_profile);
571  }
575  virtual RTC::ReturnCode_t
576  subscribeInterfaces_public(RTC::ConnectorProfile& connector_profile)
577  {
578  return subscribeInterfaces(connector_profile);
579  }
583  bool read()
584  {
585  return true;
586  }
587 
588  };
589 
596  : public RTC::InPortConsumer,
597  public RTC::CorbaConsumer< ::OpenRTM::InPortCdr >
598  {
599 
600  public:
602  {
603  m_logger = NULL;
604  }
606  {
607  }
613  {
614  if (m_logger != NULL)
615  {
616  m_logger->log("InPortCorbaCdrConsumerMock::init");
617  }
618  }
623  RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
624  {
625  return PORT_OK;
626  }
632  {
633  return;
634  }
635 
640  bool subscribeInterface(const SDOPackage::NVList& properties)
641  {
642 
643  return true;;
644  }
645 
650  void unsubscribeInterface(const SDOPackage::NVList& properties)
651  {
652  }
653 
654  bool subscribeFromIor(const SDOPackage::NVList& properties)
655  {
656 
657  return true;;
658  }
659  bool subscribeFromRef(const SDOPackage::NVList& properties)
660  {
661 
662  return true;;
663  }
664  bool unsubscribeFromIor(const SDOPackage::NVList& properties)
665  {
666 
667  return true;;
668  }
669  bool unsubscribeFromRef(const SDOPackage::NVList& properties)
670  {
671 
672  return true;;
673  }
674 
680  {
681  m_logger = logger;
682  }
683  private:
685 
686  };
693  : public RTC::OutPortProvider,
694  public virtual ::POA_OpenRTM::OutPortCdr,
695  public virtual PortableServer::RefCountServantBase
696  {
697 
698  public:
700  {
701  setInterfaceType("corba_cdr");
702  m_logger = NULL;
703  }
705  {
706  }
712  {
713  if (m_logger != NULL)
714  {
715  m_logger->log("OutPortCorbaCdrProviderMock::init");
716  }
717  }
718 
724  {
725  if (m_logger != NULL)
726  {
727  m_logger->log("OutPortCorbaCdrProviderMock::setBuffer");
728  }
729  }
730 
732  RTC::ConnectorListeners* listeners)
733  {
734  // m_profile = info;
735  // m_listeners = listeners;
736  }
738  {
739  // m_connector = connector;
740  }
741 
746  virtual ::OpenRTM::PortStatus get(::OpenRTM::CdrData_out data)
747  {
748  return ::OpenRTM::PORT_OK;
749  }
754  RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream& data)
755  {
756  return PORT_OK;
757  }
763  {
764  return;
765  }
766 
771  bool subscribeInterface(const SDOPackage::NVList& properties)
772  {
773 
774  return true;;
775  }
776 
781  void unsubscribeInterface(const SDOPackage::NVList& properties)
782  {
783  }
789  {
790  return true;
791  }
792 
798  {
799  m_logger = logger;
800  }
801  private:
803 
804  };
805 };
806 namespace RTC
807 {
814 };
815 namespace OutPortBase
816 {
823  : public CppUnit::TestFixture
824  {
825  CPPUNIT_TEST_SUITE(OutPortBaseTests);
826 
827  CPPUNIT_TEST(test_constructor);
828  CPPUNIT_TEST(test_initConsumers);
829  CPPUNIT_TEST(test_initConsumers2);//Consumers are not registered in Factory.
830  CPPUNIT_TEST(test_initProviders);
831  CPPUNIT_TEST(test_initProviders2);//Providers are not registered in Factory.
832  CPPUNIT_TEST(test_init_properties);
833  CPPUNIT_TEST(test_name);
834  CPPUNIT_TEST(test_connectors_getConnectorXX);
835  CPPUNIT_TEST(test_activateInterfaces_deactivateInterfaces);
836  CPPUNIT_TEST(test_publishInterfaces);
837  CPPUNIT_TEST(test_publishInterfaces2);//dataport.dataflow_type is "push"
838  CPPUNIT_TEST(test_publishInterfaces3);//dataport.dataflow_type is "else"
839  CPPUNIT_TEST(test_publishInterfaces4);//Provider is deleted.
840  CPPUNIT_TEST(test_publishInterfaces5);
841  CPPUNIT_TEST(test_subscribeInterfaces);
842  CPPUNIT_TEST(test_subscribeInterfaces2);//dataport.dataflow_type is "pull"
843  CPPUNIT_TEST(test_subscribeInterfaces3);//dataport.dataflow_type is "else"
844  CPPUNIT_TEST(test_subscribeInterfaces4);//Consumer is deleted.
845  CPPUNIT_TEST(test_subscribeInterfaces5);
846  CPPUNIT_TEST(test_ConnectorListener);
847 
848  CPPUNIT_TEST_SUITE_END();
849 
850  private:
851  CORBA::ORB_ptr m_pORB;
852  PortableServer::POA_ptr m_pPOA;
854  DataListener *m_datalisteners[cdl_len];
855  ConnListener *m_connlisteners[cl_len];
856 
857  public:
859 
864  : rtclog("The unit test for OutPortBase")
865  {
866  int argc(0);
867  char** argv(NULL);
868  m_pORB = CORBA::ORB_init(argc, argv);
869  m_pPOA = PortableServer::POA::_narrow(
870  m_pORB->resolve_initial_references("RootPOA"));
871  m_pPOA->the_POAManager()->activate();
872  rtclog.setLevel("PARANOID");
873  }
874 
879  {
880  }
881 
885  virtual void setUp()
886  {
887  //既に "corba_cdr" で登録されている場合は削除する。
888  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
889  {
890  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
891  }
892  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
894  addFactory("corba_cdr",
899 
900  //既に "corba_cdr" で登録されている場合は削除する。
901  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
902  {
903  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
904  }
905  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
907  addFactory("corba_cdr",
912 
913 
914  //既に "subscription_type" 登録されている場合は削除する。
915  if( RTC::PublisherFactory::instance().hasFactory("new") )
916  {
917  RTC::PublisherFactory::instance().removeFactory("new");
918  }
920  instance().addFactory("new",
924  ::RTC::PublisherNew>);
925 
926  if( RTC::PublisherFactory::instance().hasFactory("periodic") )
927  {
928  RTC::PublisherFactory::instance().removeFactory("periodic");
929  }
931  instance().addFactory("periodic",
936 
937  if( RTC::PublisherFactory::instance().hasFactory("flush") )
938  {
939  RTC::PublisherFactory::instance().removeFactory("flush");
940  }
942  instance().addFactory("flush",
947  }
948 
952  virtual void tearDown()
953  {
954  }
955 
961  {
962  //既に "corba_cdr" で登録されている場合は削除する。
963  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
964  {
965  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
966  }
967  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
969  addFactory("corba_cdr",
974 
975  //既に "corba_cdr" で登録されている場合は削除する。
976  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
977  {
978  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
979  }
980  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
982  addFactory("corba_cdr",
987 
988 
989  //既に "subscription_type" 登録されている場合は削除する。
990  if( RTC::PublisherFactory::instance().hasFactory("new") )
991  {
992  RTC::PublisherFactory::instance().removeFactory("new");
993  }
994  if( RTC::PublisherFactory::instance().hasFactory("periodic") )
995  {
996  RTC::PublisherFactory::instance().removeFactory("periodic");
997  }
998  if( RTC::PublisherFactory::instance().hasFactory("flush") )
999  {
1000  RTC::PublisherFactory::instance().removeFactory("flush");
1001  }
1002 
1003  {
1004  OutPortBaseMock outPort("OutPortBaseTest",
1005  toTypename<RTC::TimedFloat>());
1006 
1007  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1008  portAdmin.registerPort(outPort);
1009 
1010  RTC::PortProfile profile = outPort.getPortProfile();
1011  coil::Properties prop = NVUtil::toProperties(profile.properties);
1012  CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"),
1013  prop["port.port_type"] );
1014  CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
1015  prop["dataport.data_type"] );
1016  CPPUNIT_ASSERT_EQUAL(std::string(""),
1017  prop["dataport.subscription_type"]);
1018 
1019  portAdmin.deletePort(outPort);
1020  }
1022  instance().addFactory("flush",
1026  ::RTC::PublisherFlush>);
1027  {
1028  OutPortBaseMock outPort("OutPortBaseTest",
1029  toTypename<RTC::TimedFloat>());
1030 
1031  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1032  portAdmin.registerPort(outPort);
1033 
1034  RTC::PortProfile profile = outPort.getPortProfile();
1035  coil::Properties prop = NVUtil::toProperties(profile.properties);
1036  CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"),
1037  prop["port.port_type"] );
1038  CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
1039  prop["dataport.data_type"] );
1040  CPPUNIT_ASSERT_EQUAL(std::string("flush"),
1041  prop["dataport.subscription_type"]);
1042 
1043  portAdmin.deletePort(outPort);
1044  }
1045 
1047  instance().addFactory("new",
1049  ::RTC::PublisherNew>,
1051  ::RTC::PublisherNew>);
1052  {
1053  OutPortBaseMock outPort("OutPortBaseTest",
1054  toTypename<RTC::TimedFloat>());
1055 
1056  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1057  portAdmin.registerPort(outPort);
1058 
1059  RTC::PortProfile profile = outPort.getPortProfile();
1060  coil::Properties prop = NVUtil::toProperties(profile.properties);
1061  CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"),
1062  prop["port.port_type"] );
1063  CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
1064  prop["dataport.data_type"] );
1065  CPPUNIT_ASSERT_EQUAL(std::string("flush,new"),
1066  prop["dataport.subscription_type"]);
1067 
1068  portAdmin.deletePort(outPort);
1069  }
1071  instance().addFactory("periodic",
1076  {
1077  OutPortBaseMock outPort("OutPortBaseTest",
1078  toTypename<RTC::TimedFloat>());
1079 
1080  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1081  portAdmin.registerPort(outPort);
1082 
1083  RTC::PortProfile profile = outPort.getPortProfile();
1084  coil::Properties prop = NVUtil::toProperties(profile.properties);
1085  CPPUNIT_ASSERT_EQUAL(std::string("DataOutPort"),
1086  prop["port.port_type"] );
1087  CPPUNIT_ASSERT_EQUAL(std::string(toTypename<RTC::TimedFloat>()),
1088  prop["dataport.data_type"] );
1089  CPPUNIT_ASSERT_EQUAL(std::string("flush,new,periodic"),
1090  prop["dataport.subscription_type"]);
1091 
1092  portAdmin.deletePort(outPort);
1093  }
1094  }
1100  {
1101  //既に "corba_cdr" で登録されている場合は削除する。
1102  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1103  {
1104  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1105  }
1106 
1107  //既に "corba_cdr" で登録されている場合は削除する。
1108  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1109  {
1110  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1111  }
1112 
1113  OutPortBaseMock outPort("OutPortBaseTest",
1114  toTypename<RTC::TimedFloat>());
1115 
1116  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1117  portAdmin.registerPort(outPort);
1118 
1119  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
1121  addFactory("corba_cdr",
1126  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1128  addFactory("corba_cdr",
1133 
1134  RTC::PortProfile profile = outPort.getPortProfile();
1135  coil::Properties prop = NVUtil::toProperties(profile.properties);
1136  CPPUNIT_ASSERT_EQUAL(std::string(""),
1137  prop["dataport.dataflow_type"]);
1138  CPPUNIT_ASSERT_EQUAL(std::string(""),
1139  prop["dataport.interface_type"]);
1140 
1141  coil::vstring cstr = outPort.get_m_consumerTypes();
1142  CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
1143 
1144  outPort.initConsumers_public();
1145 
1146  profile = outPort.getPortProfile();
1147  prop = NVUtil::toProperties(profile.properties);
1148 
1149  //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string("push"), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initConsumers()メソッドのテスト * */ void test_initConsumers2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initConsumers_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string("pull"), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1150  CPPUNIT_ASSERT_EQUAL(std::string("push"),
1151  prop["dataport.dataflow_type"]);
1152  CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
1153  prop["dataport.interface_type"]);
1154 
1155  //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initConsumers()メソッドのテスト * */ void test_initConsumers2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initConsumers_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string("pull"), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1156  cstr = outPort.get_m_consumerTypes();
1157  CPPUNIT_ASSERT((size_t)0!= cstr.size());
1158  CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
1159  cstr[0]);
1160 
1161  portAdmin.deletePort(outPort);
1162  }
1168  {
1169  //既に "corba_cdr" で登録されている場合は削除する。
1170  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1171  {
1172  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1173  }
1174 
1175  //既に "corba_cdr" で登録されている場合は削除する。
1176  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1177  {
1178  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1179  }
1180 
1181  OutPortBaseMock outPort("OutPortBaseTest",
1182  toTypename<RTC::TimedFloat>());
1183 
1184  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1185  portAdmin.registerPort(outPort);
1186 
1187  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1189  addFactory("corba_cdr",
1194 
1195  RTC::PortProfile profile = outPort.getPortProfile();
1196  coil::Properties prop = NVUtil::toProperties(profile.properties);
1197  CPPUNIT_ASSERT_EQUAL(std::string(""),
1198  prop["dataport.dataflow_type"]);
1199  CPPUNIT_ASSERT_EQUAL(std::string(""),
1200  prop["dataport.interface_type"]);
1201 
1202  coil::vstring cstr = outPort.get_m_consumerTypes();
1203  CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
1204 
1205  outPort.initConsumers_public();
1206 
1207  profile = outPort.getPortProfile();
1208  prop = NVUtil::toProperties(profile.properties);
1209 
1210  //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string("pull"), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1211  CPPUNIT_ASSERT_EQUAL(std::string(""),
1212  prop["dataport.dataflow_type"]);
1213  CPPUNIT_ASSERT_EQUAL(std::string(""),
1214  prop["dataport.interface_type"]);
1215 
1216  //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_consumerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string("pull"), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1217  cstr = outPort.get_m_consumerTypes();
1218  CPPUNIT_ASSERT((size_t)0== cstr.size());
1219 
1220  portAdmin.deletePort(outPort);
1221  }
1227  {
1228  //既に "corba_cdr" で登録されている場合は削除する。
1229  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1230  {
1231  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1232  }
1233 
1234  //既に "corba_cdr" で登録されている場合は削除する。
1235  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1236  {
1237  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1238  }
1239 
1240  OutPortBaseMock outPort("OutPortBaseTest",
1241  toTypename<RTC::TimedFloat>());
1242 
1243  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1244  portAdmin.registerPort(outPort);
1245 
1246  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
1248  addFactory("corba_cdr",
1253  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1255  addFactory("corba_cdr",
1260 
1261  RTC::PortProfile profile = outPort.getPortProfile();
1262  coil::Properties prop = NVUtil::toProperties(profile.properties);
1263  CPPUNIT_ASSERT_EQUAL(std::string(""),
1264  prop["dataport.dataflow_type"]);
1265  CPPUNIT_ASSERT_EQUAL(std::string(""),
1266  prop["dataport.interface_type"]);
1267 
1268  coil::vstring cstr = outPort.get_m_providerTypes();
1269  CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
1270 
1271  outPort.initProviders_public();
1272 
1273  profile = outPort.getPortProfile();
1274  prop = NVUtil::toProperties(profile.properties);
1275 
1276  //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string("pull"), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1277  CPPUNIT_ASSERT_EQUAL(std::string("pull"),
1278  prop["dataport.dataflow_type"]);
1279  CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
1280  prop["dataport.interface_type"]);
1281 
1282  //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0!= cstr.size()); CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"), cstr[0]); portAdmin.deletePort(outPort); } /*! * @brief initProviders()メソッドのテスト * */ void test_initProviders2() { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); RTC::PortProfile profile = outPort.getPortProfile(); coil::Properties prop = NVUtil::toProperties(profile.properties); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); coil::vstring cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size()); outPort.initProviders_public(); profile = outPort.getPortProfile(); prop = NVUtil::toProperties(profile.properties); //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1283  cstr = outPort.get_m_providerTypes();
1284  CPPUNIT_ASSERT((size_t)0!= cstr.size());
1285  CPPUNIT_ASSERT_EQUAL(std::string("corba_cdr"),
1286  cstr[0]);
1287 
1288  portAdmin.deletePort(outPort);
1289  }
1295  {
1296  //既に "corba_cdr" で登録されている場合は削除する。
1297  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1298  {
1299  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1300  }
1301 
1302  //既に "corba_cdr" で登録されている場合は削除する。
1303  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1304  {
1305  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1306  }
1307 
1308  OutPortBaseMock outPort("OutPortBaseTest",
1309  toTypename<RTC::TimedFloat>());
1310 
1311  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1312  portAdmin.registerPort(outPort);
1313 
1314  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
1316  addFactory("corba_cdr",
1321 
1322  RTC::PortProfile profile = outPort.getPortProfile();
1323  coil::Properties prop = NVUtil::toProperties(profile.properties);
1324  CPPUNIT_ASSERT_EQUAL(std::string(""),
1325  prop["dataport.dataflow_type"]);
1326  CPPUNIT_ASSERT_EQUAL(std::string(""),
1327  prop["dataport.interface_type"]);
1328 
1329  coil::vstring cstr = outPort.get_m_providerTypes();
1330  CPPUNIT_ASSERT_EQUAL((size_t)0, cstr.size());
1331 
1332  outPort.initProviders_public();
1333 
1334  profile = outPort.getPortProfile();
1335  prop = NVUtil::toProperties(profile.properties);
1336 
1337  //getPortProfileのpropertiesに以下が追加される CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(std::string(""), prop["dataport.interface_type"]); //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1338  CPPUNIT_ASSERT_EQUAL(std::string(""),
1339  prop["dataport.dataflow_type"]);
1340  CPPUNIT_ASSERT_EQUAL(std::string(""),
1341  prop["dataport.interface_type"]);
1342 
1343  //ProviderTypes,ConsumerTypesが取得される cstr = outPort.get_m_providerTypes(); CPPUNIT_ASSERT((size_t)0== cstr.size()); portAdmin.deletePort(outPort); } /*! * @brief init(),properties()メソッドのテスト * */ void test_init_properties() { OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); coil::Properties prop; prop["dataport.interface_type"] = "corba_cdr"; prop["dataport.dataflow_type"] = "pull"; prop["dataport.subscription_type"] = "new"; RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); outPort.init(prop); coil::Properties prop2 = outPort.get_m_properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); prop2 = outPort.properties(); CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size()); CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"], prop2["dataport.interface_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"], prop2["dataport.dataflow_type"]); CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"], prop2["dataport.subscription_type"]); portAdmin.deletePort(outPort); } /*! * @brief name()メソッドのテスト * * - ポート名を正しく取得できるか? */ void test_name() { OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName())); portAdmin.deletePort(outPort); } /*! * @brief connectors(),getConnectorProfiles()メソッドのテスト * */ void test_connectors_getConnectorXX(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "pull","pull","pull","pull"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // //connectors() // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); coil::Properties prop(outPort.properties()); coil::Properties conn_prop; NVUtil::copyToProperties(conn_prop, prof.properties); prop << conn_prop.getNode("dataport"); // marge ConnectorProfile RTC::OutPortProvider* provider(outPort.createProvider_public(prof, prop)); outPort.createConnector_public(prof,prop,provider); std::vector<RTC::OutPortConnector*> objs = outPort.connectors(); CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size()); CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id())); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name())); } // //getConnectorProfiles() // RTC::ConnectorInfoList list = outPort.getConnectorProfiles(); CPPUNIT_ASSERT_EQUAL((size_t)10, list.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id)); CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name)); CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size()); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], list[ic].properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], list[ic].properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], list[ic].properties["subscription_type"]); } // //getConnectorIds() // coil::vstring ids = outPort.getConnectorIds(); CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]); } // //getConnectorNames() // coil::vstring names = outPort.getConnectorNames(); CPPUNIT_ASSERT_EQUAL((size_t)10, names.size()); for(int ic(0);ic<10;++ic) { CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]); } // // getConnectorById() // RTC::OutPortConnector* oc = outPort.getConnectorById("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorById("id0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorById("id1"); CPPUNIT_ASSERT(oc != 0); // // getConnectorByName() // oc = outPort.getConnectorByName("unknown"); CPPUNIT_ASSERT(oc == 0); oc = outPort.getConnectorByName("foo0"); CPPUNIT_ASSERT(oc != 0); oc = outPort.getConnectorByName("foo1"); CPPUNIT_ASSERT(oc != 0); // //getConnectorProfileById() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileById("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileById("bar",prof); CPPUNIT_ASSERT(!ret); } // //getConnectorProfileByName() // for(int ic(0);ic<10;++ic) { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(), prof); CPPUNIT_ASSERT(ret); CPPUNIT_ASSERT_EQUAL(vstrinterface[ic], prof.properties["interface_type"]); CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic], prof.properties["dataflow_type"]); CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic], prof.properties["subscription_type"]); } { RTC::ConnectorInfo prof; bool ret = outPort.getConnectorProfileByName("foo",prof); CPPUNIT_ASSERT(!ret); ret = outPort.getConnectorProfileByName("bar",prof); CPPUNIT_ASSERT(!ret); } // //publishInterfaces() // { RTC::ConnectorProfile outprof; bool ret = outPort.publishInterfaces_public(outprof); CPPUNIT_ASSERT(ret); { const char* value; try { NVUtil::find(outprof.properties, "dataport.data_type") >>= value; CPPUNIT_FAIL("dataport.data_type fialure."); } catch(std::string ex) { } catch(...) { CPPUNIT_FAIL("dataport.data_type failure."); } } } portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief activateInterfaces(),deactivateInterfaces()メソッドのテスト * */ void test_activateInterfaces_deactivateInterfaces(void) { RTC::TimedDouble inbindValue; InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue); OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile inprof; inprof.ports.length(1); inprof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(inprof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); inprof.connector_id = "id0"; inprof.name = CORBA::string_dup("bar"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); inPort.publishInterfaces_public(inprof); //std::cout<<NVUtil::toString(inprof.properties)<<std::endl; std::string vstrid[10] = {"id0","id1","id2","id3","id4", "id5","id6","id7","id8","id9"}; std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4", "foo5","foo6","foo7","foo8","foo9"}; std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr","corba_cdr","corba_cdr", "corba_cdr"}; std::string vstrdataflow[10] = {"push","push","push", "push","push","push", "push","push","push","push"}; std::string vstrsubscription[10] = {"flush","flush","flush", "flush","flush","flush", "flush","flush","flush","flush"}; // // for(int ic(0);ic<10;++ic) { RTC::ConnectorProfile prof; prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", vstrinterface[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", vstrdataflow[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", vstrsubscription[ic].c_str())); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.corba_cdr.inport_ior", NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str())); prof.connector_id = vstrid[ic].c_str(); prof.name = CORBA::string_dup(vstrname[ic].c_str()); outPort.subscribeInterfaces_public(prof); } int logcnt; logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate"); outPort.activateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::activate")); logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate"); outPort.deactivateInterfaces(); CPPUNIT_ASSERT_EQUAL(logcnt+10, ::RTC::logger.countLog("OutPortPushConnector::deactivate")); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces2(void) { // //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1344  cstr = outPort.get_m_providerTypes();
1345  CPPUNIT_ASSERT((size_t)0== cstr.size());
1346 
1347  portAdmin.deletePort(outPort);
1348  }
1354  {
1355  OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>());
1356 
1358  prop["dataport.interface_type"] = "corba_cdr";
1359  prop["dataport.dataflow_type"] = "pull";
1360  prop["dataport.subscription_type"] = "new";
1361 
1362  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1363  portAdmin.registerPort(outPort);
1364 
1365  outPort.init(prop);
1366 
1367  coil::Properties prop2 = outPort.get_m_properties();
1368  CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size());
1369 
1370  CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"],
1371  prop2["dataport.interface_type"]);
1372  CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"],
1373  prop2["dataport.dataflow_type"]);
1374  CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"],
1375  prop2["dataport.subscription_type"]);
1376 
1377  prop2 = outPort.properties();
1378  CPPUNIT_ASSERT_EQUAL(prop.size(), prop2.size());
1379 
1380  CPPUNIT_ASSERT_EQUAL(prop["dataport.interface_type"],
1381  prop2["dataport.interface_type"]);
1382  CPPUNIT_ASSERT_EQUAL(prop["dataport.dataflow_type"],
1383  prop2["dataport.dataflow_type"]);
1384  CPPUNIT_ASSERT_EQUAL(prop["dataport.subscription_type"],
1385  prop2["dataport.subscription_type"]);
1386 
1387  portAdmin.deletePort(outPort);
1388  }
1394  void test_name()
1395  {
1396  OutPortBaseMock outPort("Hello, World!", toTypename<RTC::TimedDouble>());
1397 
1398  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1399  portAdmin.registerPort(outPort);
1400 
1401  CPPUNIT_ASSERT_EQUAL(std::string("unknown.Hello, World!"), std::string(outPort.getName()));
1402  portAdmin.deletePort(outPort);
1403  }
1404 
1410  {
1411  RTC::TimedDouble inbindValue;
1412  InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue);
1413 
1414  OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedDouble>());
1415 
1416  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1417  portAdmin.registerPort(outPort);
1418  portAdmin.registerPort(inPort);
1419 
1420  RTC::ConnectorProfile inprof;
1421  inprof.ports.length(1);
1422  inprof.ports[0] = outPort.get_port_profile()->port_ref;
1423  CORBA_SeqUtil::push_back(inprof.properties,
1424  NVUtil::newNV("dataport.interface_type",
1425  "corba_cdr"));
1426  CORBA_SeqUtil::push_back(inprof.properties,
1427  NVUtil::newNV("dataport.dataflow_type",
1428  "push"));
1429  CORBA_SeqUtil::push_back(inprof.properties,
1430  NVUtil::newNV("dataport.subscription_type",
1431  "flush"));
1432  inprof.connector_id = "id0";
1433  inprof.name = CORBA::string_dup("bar");
1434 
1435  coil::Properties dummy;
1436  inPort.init(dummy);
1437  outPort.init(dummy);
1438 
1439  inPort.publishInterfaces_public(inprof);
1440 
1441  std::string vstrid[10] = {"id0","id1","id2","id3","id4",
1442  "id5","id6","id7","id8","id9"};
1443  std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4",
1444  "foo5","foo6","foo7","foo8","foo9"};
1445 
1446  std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr",
1447  "corba_cdr","corba_cdr","corba_cdr",
1448  "corba_cdr","corba_cdr","corba_cdr",
1449  "corba_cdr"};
1450  std::string vstrdataflow[10] = {"push","push","push",
1451  "push","push","push",
1452  "pull","pull","pull","pull"};
1453 
1454  std::string vstrsubscription[10] = {"flush","flush","flush",
1455  "flush","flush","flush",
1456  "flush","flush","flush","flush"};
1457 
1458  //
1459  //connectors()
1460  //
1461  for(int ic(0);ic<10;++ic)
1462  {
1463  RTC::ConnectorProfile prof;
1464  prof.ports.length(1);
1465  prof.ports[0] = outPort.get_port_profile()->port_ref;
1466  CORBA_SeqUtil::push_back(prof.properties,
1467  NVUtil::newNV("dataport.interface_type",
1468  vstrinterface[ic].c_str()));
1469  CORBA_SeqUtil::push_back(prof.properties,
1470  NVUtil::newNV("dataport.dataflow_type",
1471  vstrdataflow[ic].c_str()));
1472  CORBA_SeqUtil::push_back(prof.properties,
1473  NVUtil::newNV("dataport.subscription_type",
1474  vstrsubscription[ic].c_str()));
1475  CORBA_SeqUtil::push_back(prof.properties,
1476  NVUtil::newNV("dataport.corba_cdr.inport_ior",
1477  NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str()));
1478  prof.connector_id = vstrid[ic].c_str();
1479  prof.name = CORBA::string_dup(vstrname[ic].c_str());
1480 
1481 
1482  coil::Properties prop(outPort.properties());
1483  coil::Properties conn_prop;
1484  NVUtil::copyToProperties(conn_prop, prof.properties);
1485  prop << conn_prop.getNode("dataport"); // marge ConnectorProfile
1487  outPort.createConnector_public(prof,prop,provider);
1488 
1489  std::vector<RTC::OutPortConnector*> objs = outPort.connectors();
1490 
1491  CPPUNIT_ASSERT_EQUAL((size_t)(ic+1), objs.size());
1492  CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(objs[ic]->id()));
1493  CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(objs[ic]->name()));
1494  }
1495 
1496  //
1497  //getConnectorProfiles()
1498  //
1500  CPPUNIT_ASSERT_EQUAL((size_t)10, list.size());
1501  for(int ic(0);ic<10;++ic)
1502  {
1503  CPPUNIT_ASSERT_EQUAL(vstrid[ic], std::string(list[ic].id));
1504  CPPUNIT_ASSERT_EQUAL(vstrname[ic], std::string(list[ic].name));
1505  CPPUNIT_ASSERT_EQUAL((size_t)1, list[ic].ports.size());
1506 
1507  CPPUNIT_ASSERT_EQUAL(vstrinterface[ic],
1508  list[ic].properties["interface_type"]);
1509  CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic],
1510  list[ic].properties["dataflow_type"]);
1511  CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic],
1512  list[ic].properties["subscription_type"]);
1513 
1514  }
1515 
1516  //
1517  //getConnectorIds()
1518  //
1519  coil::vstring ids = outPort.getConnectorIds();
1520  CPPUNIT_ASSERT_EQUAL((size_t)10, ids.size());
1521  for(int ic(0);ic<10;++ic)
1522  {
1523  CPPUNIT_ASSERT_EQUAL(vstrid[ic], ids[ic]);
1524  }
1525 
1526  //
1527  //getConnectorNames()
1528  //
1529  coil::vstring names = outPort.getConnectorNames();
1530  CPPUNIT_ASSERT_EQUAL((size_t)10, names.size());
1531  for(int ic(0);ic<10;++ic)
1532  {
1533  CPPUNIT_ASSERT_EQUAL(vstrname[ic], names[ic]);
1534  }
1535 
1536  //
1537  // getConnectorById()
1538  //
1539  RTC::OutPortConnector* oc = outPort.getConnectorById("unknown");
1540  CPPUNIT_ASSERT(oc == 0);
1541  oc = outPort.getConnectorById("id0");
1542  CPPUNIT_ASSERT(oc != 0);
1543  oc = outPort.getConnectorById("id1");
1544  CPPUNIT_ASSERT(oc != 0);
1545 
1546  //
1547  // getConnectorByName()
1548  //
1549  oc = outPort.getConnectorByName("unknown");
1550  CPPUNIT_ASSERT(oc == 0);
1551  oc = outPort.getConnectorByName("foo0");
1552  CPPUNIT_ASSERT(oc != 0);
1553  oc = outPort.getConnectorByName("foo1");
1554  CPPUNIT_ASSERT(oc != 0);
1555 
1556  //
1557  //getConnectorProfileById()
1558  //
1559  for(int ic(0);ic<10;++ic)
1560  {
1561 
1562  RTC::ConnectorInfo prof;
1563  bool ret = outPort.getConnectorProfileById(vstrid[ic].c_str(),prof);
1564  CPPUNIT_ASSERT(ret);
1565  CPPUNIT_ASSERT_EQUAL(vstrinterface[ic],
1566  prof.properties["interface_type"]);
1567  CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic],
1568  prof.properties["dataflow_type"]);
1569  CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic],
1570  prof.properties["subscription_type"]);
1571  }
1572  {
1573  RTC::ConnectorInfo prof;
1574  bool ret = outPort.getConnectorProfileById("foo",prof);
1575  CPPUNIT_ASSERT(!ret);
1576  ret = outPort.getConnectorProfileById("bar",prof);
1577  CPPUNIT_ASSERT(!ret);
1578  }
1579 
1580  //
1581  //getConnectorProfileByName()
1582  //
1583  for(int ic(0);ic<10;++ic)
1584  {
1585  RTC::ConnectorInfo prof;
1586  bool ret = outPort.getConnectorProfileByName(vstrname[ic].c_str(),
1587  prof);
1588  CPPUNIT_ASSERT(ret);
1589  CPPUNIT_ASSERT_EQUAL(vstrinterface[ic],
1590  prof.properties["interface_type"]);
1591  CPPUNIT_ASSERT_EQUAL(vstrdataflow[ic],
1592  prof.properties["dataflow_type"]);
1593  CPPUNIT_ASSERT_EQUAL(vstrsubscription[ic],
1594  prof.properties["subscription_type"]);
1595  }
1596  {
1597  RTC::ConnectorInfo prof;
1598  bool ret = outPort.getConnectorProfileByName("foo",prof);
1599  CPPUNIT_ASSERT(!ret);
1600  ret = outPort.getConnectorProfileByName("bar",prof);
1601  CPPUNIT_ASSERT(!ret);
1602  }
1603 
1604  //
1605  //publishInterfaces()
1606  //
1607  {
1608  RTC::ConnectorProfile outprof;
1609  bool ret = outPort.publishInterfaces_public(outprof);
1610  CPPUNIT_ASSERT(ret);
1611  {
1612  const char* value;
1613  try {
1614  NVUtil::find(outprof.properties, "dataport.data_type") >>= value;
1615  CPPUNIT_FAIL("dataport.data_type fialure.");
1616  }
1617  catch(std::string ex) {
1618  }
1619  catch(...) {
1620  CPPUNIT_FAIL("dataport.data_type failure.");
1621  }
1622  }
1623  }
1624  portAdmin.deletePort(outPort);
1625  portAdmin.deletePort(inPort);
1626  }
1627 
1633  {
1634  RTC::TimedDouble inbindValue;
1635  InPortMock<RTC::TimedDouble> inPort("in:OutPortBaseTest",inbindValue);
1636 
1637  OutPortBaseMock outPort("out:OutPortBaseTest", toTypename<RTC::TimedDouble>());
1638 
1639  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1640  portAdmin.registerPort(outPort);
1641  portAdmin.registerPort(inPort);
1642 
1643  RTC::ConnectorProfile inprof;
1644  inprof.ports.length(1);
1645  inprof.ports[0] = outPort.get_port_profile()->port_ref;
1646  CORBA_SeqUtil::push_back(inprof.properties,
1647  NVUtil::newNV("dataport.interface_type",
1648  "corba_cdr"));
1649  CORBA_SeqUtil::push_back(inprof.properties,
1650  NVUtil::newNV("dataport.dataflow_type",
1651  "push"));
1652  CORBA_SeqUtil::push_back(inprof.properties,
1653  NVUtil::newNV("dataport.subscription_type",
1654  "flush"));
1655  inprof.connector_id = "id0";
1656  inprof.name = CORBA::string_dup("bar");
1657  coil::Properties dummy;
1658  inPort.init(dummy);
1659  outPort.init(dummy);
1660  inPort.publishInterfaces_public(inprof);
1661  //std::cout<<NVUtil::toString(inprof.properties)<<std::endl;
1662 
1663  std::string vstrid[10] = {"id0","id1","id2","id3","id4",
1664  "id5","id6","id7","id8","id9"};
1665  std::string vstrname[10] = {"foo0","foo1","foo2","foo3","foo4",
1666  "foo5","foo6","foo7","foo8","foo9"};
1667 
1668  std::string vstrinterface[10] = {"corba_cdr","corba_cdr","corba_cdr",
1669  "corba_cdr","corba_cdr","corba_cdr",
1670  "corba_cdr","corba_cdr","corba_cdr",
1671  "corba_cdr"};
1672  std::string vstrdataflow[10] = {"push","push","push",
1673  "push","push","push",
1674  "push","push","push","push"};
1675 
1676  std::string vstrsubscription[10] = {"flush","flush","flush",
1677  "flush","flush","flush",
1678  "flush","flush","flush","flush"};
1679  //
1680  //
1681  for(int ic(0);ic<10;++ic)
1682  {
1683  RTC::ConnectorProfile prof;
1684  prof.ports.length(1);
1685  prof.ports[0] = outPort.get_port_profile()->port_ref;
1686  CORBA_SeqUtil::push_back(prof.properties,
1687  NVUtil::newNV("dataport.interface_type",
1688  vstrinterface[ic].c_str()));
1689  CORBA_SeqUtil::push_back(prof.properties,
1690  NVUtil::newNV("dataport.dataflow_type",
1691  vstrdataflow[ic].c_str()));
1692  CORBA_SeqUtil::push_back(prof.properties,
1693  NVUtil::newNV("dataport.subscription_type",
1694  vstrsubscription[ic].c_str()));
1695  CORBA_SeqUtil::push_back(prof.properties,
1696  NVUtil::newNV("dataport.corba_cdr.inport_ior",
1697  NVUtil::toString(inprof.properties,"dataport.corba_cdr.inport_ior").c_str()));
1698  prof.connector_id = vstrid[ic].c_str();
1699  prof.name = CORBA::string_dup(vstrname[ic].c_str());
1700 
1701 
1702  outPort.subscribeInterfaces_public(prof);
1703 
1704  }
1705  int logcnt;
1706  logcnt = ::RTC::logger.countLog("OutPortPushConnector::activate");
1707  outPort.activateInterfaces();
1708  CPPUNIT_ASSERT_EQUAL(logcnt+10,
1709  ::RTC::logger.countLog("OutPortPushConnector::activate"));
1710 
1711 
1712  logcnt = ::RTC::logger.countLog("OutPortPushConnector::deactivate");
1713  outPort.deactivateInterfaces();
1714  CPPUNIT_ASSERT_EQUAL(logcnt+10,
1715  ::RTC::logger.countLog("OutPortPushConnector::deactivate"));
1716 
1717  portAdmin.deletePort(outPort);
1718  portAdmin.deletePort(inPort);
1719 
1720  }
1726  {
1727  //既に "corba_cdr" で登録されている場合は削除する。
1728  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1729  {
1730  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1731  }
1732  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1734  addFactory("corba_cdr",
1739 
1740  //既に "corba_cdr" で登録されている場合は削除する。
1741  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1742  {
1743  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1744  }
1745  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
1747  addFactory("corba_cdr",
1752 
1753 
1754  OutPortBaseMock outPort("OutPortBaseTest",
1755  toTypename<RTC::TimedFloat>());
1756 
1757  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1758  portAdmin.registerPort(outPort);
1759  RTC::ConnectorProfile prof;
1760  prof.connector_id = "id0";
1761  prof.name = CORBA::string_dup("OutPortBaseTest0");
1762  prof.ports.length(1);
1763  prof.ports[0] = outPort.get_port_profile()->port_ref;
1764  CORBA_SeqUtil::push_back(prof.properties,
1765  NVUtil::newNV("dataport.interface_type",
1766  "corba_cdr"));
1767  CORBA_SeqUtil::push_back(prof.properties,
1768  NVUtil::newNV("dataport.dataflow_type",
1769  "pull"));
1770  CORBA_SeqUtil::push_back(prof.properties,
1771  NVUtil::newNV("dataport.subscription_type",
1772  "new"));
1773  coil::Properties dummy;
1774  outPort.init(dummy);
1775 
1777  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1778  retcode = outPort.publishInterfaces_public(prof);
1779  CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size());
1780  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
1781 
1782  prof.connector_id = "id1";
1783  prof.name = CORBA::string_dup("OutPortBaseTest1");
1784  retcode = outPort.publishInterfaces_public(prof);
1785  CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size());
1786  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
1787 
1788  portAdmin.deletePort(outPort);
1789  }
1795  {
1796  //
1797  //dataport.dataflow_typeがpushでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces3(void) { // //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1798  //
1799 
1800  //既に "corba_cdr" で登録されている場合は削除する。
1801  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1802  {
1803  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1804  }
1805  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1807  addFactory("corba_cdr",
1812 
1813  //既に "corba_cdr" で登録されている場合は削除する。
1814  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1815  {
1816  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1817  }
1818  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
1820  addFactory("corba_cdr",
1825 
1826 
1827  OutPortBaseMock outPort("OutPortBaseTest",
1828  toTypename<RTC::TimedFloat>());
1829 
1830  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1831  portAdmin.registerPort(outPort);
1832  RTC::ConnectorProfile prof;
1833  prof.connector_id = "id0";
1834  prof.name = CORBA::string_dup("OutPortBaseTest0");
1835  prof.ports.length(1);
1836  prof.ports[0] = outPort.get_port_profile()->port_ref;
1837  CORBA_SeqUtil::push_back(prof.properties,
1838  NVUtil::newNV("dataport.interface_type",
1839  "corba_cdr"));
1840  CORBA_SeqUtil::push_back(prof.properties,
1841  NVUtil::newNV("dataport.dataflow_type",
1842  "push"));
1843  CORBA_SeqUtil::push_back(prof.properties,
1844  NVUtil::newNV("dataport.subscription_type",
1845  "new"));
1846  coil::Properties dummy;
1847  outPort.init(dummy);
1848 
1850  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1851  retcode = outPort.publishInterfaces_public(prof);
1852  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1853  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
1854 
1855  portAdmin.deletePort(outPort);
1856  }
1862  {
1863  //
1864  //dataport.dataflow_typeがelseでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces4(void) { // //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1865  //
1866 
1867  //既に "corba_cdr" で登録されている場合は削除する。
1868  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1869  {
1870  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1871  }
1872  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1874  addFactory("corba_cdr",
1879 
1880  //既に "corba_cdr" で登録されている場合は削除する。
1881  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1882  {
1883  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1884  }
1885  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
1887  addFactory("corba_cdr",
1892 
1893 
1894  OutPortBaseMock outPort("OutPortBaseTest",
1895  toTypename<RTC::TimedFloat>());
1896 
1897  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1898  portAdmin.registerPort(outPort);
1899  RTC::ConnectorProfile prof;
1900  prof.connector_id = "id0";
1901  prof.name = CORBA::string_dup("OutPortBaseTest0");
1902  prof.ports.length(1);
1903  prof.ports[0] = outPort.get_port_profile()->port_ref;
1904  CORBA_SeqUtil::push_back(prof.properties,
1905  NVUtil::newNV("dataport.interface_type",
1906  "corba_cdr"));
1907  CORBA_SeqUtil::push_back(prof.properties,
1908  NVUtil::newNV("dataport.dataflow_type",
1909  "else"));
1910  CORBA_SeqUtil::push_back(prof.properties,
1911  NVUtil::newNV("dataport.subscription_type",
1912  "new"));
1913  coil::Properties dummy;
1914  outPort.init(dummy);
1915 
1917  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1918  retcode = outPort.publishInterfaces_public(prof);
1919  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1920  CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
1921 
1922  portAdmin.deletePort(outPort);
1923  }
1929  {
1930  //
1931  //ProviderなしでpublisherInterfaceをコール // //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief publishInterfaces()メソッドのテスト * */ void test_publishInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.publishInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); prof.connector_id = "id1"; prof.name = CORBA::string_dup("OutPortBaseTest1"); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces2(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "pull")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces3(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "else")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces4(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode); portAdmin.deletePort(outPort); } /*! * @brief subscribeInterfaces()メソッドのテスト * */ void test_subscribeInterfaces5(void) { //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") ) { RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。 RTC::OutPortProviderFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>, ::coil::Destructor< ::RTC::OutPortProvider, OutPortCorbaCdrProviderMock>); //既に "corba_cdr" で登録されている場合は削除する。 if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") ) { RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr"); } //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。 RTC::InPortConsumerFactory::instance(). addFactory("corba_cdr", ::coil::Creator< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>, ::coil::Destructor< ::RTC::InPortConsumer, InPortCorbaCdrConsumerMock>); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedFloat>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); RTC::ConnectorProfile prof; prof.connector_id = "id0"; prof.name = CORBA::string_dup("OutPortBaseTest0"); prof.ports.length(1); prof.ports[0] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "new")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.OutPortBaseTests", "bad_alloc")); coil::Properties dummy; outPort.init(dummy); RTC::ReturnCode_t retcode; CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); retcode = outPort.subscribeInterfaces_public(prof); CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size()); CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode); portAdmin.deletePort(outPort); } /*! * @brief addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト * */ void test_ConnectorListener(void) { RTC::TimedLong tdl; InPortMock<RTC::TimedLong> inPort("InPort", tdl); OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>()); RTC::PortAdmin portAdmin(m_pORB,m_pPOA); portAdmin.registerPort(outPort); portAdmin.registerPort(inPort); RTC::ConnectorProfile prof; prof.ports.length(2); prof.ports[0] = inPort.get_port_profile()->port_ref; prof.ports[1] = outPort.get_port_profile()->port_ref; CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.interface_type", "corba_cdr")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.dataflow_type", "push")); CORBA_SeqUtil::push_back(prof.properties, NVUtil::newNV("dataport.subscription_type", "flush")); prof.connector_id = "id0"; prof.name = CORBA::string_dup("test"); coil::Properties dummy; inPort.init(dummy); outPort.init(dummy); //ConnectorDataListeners settting for (int i(0); i<cdl_len; ++i) { m_datalisteners[i] = new DataListener(str_cdl[i]); } //ConnectorListeners settting for (int i(0); i<cl_len; ++i) { m_connlisteners[i] = new ConnListener(str_cl[i]); } // addConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.addConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i], true); } // addConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.addConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i], true); } // Listener add count check CPPUNIT_ASSERT_EQUAL(10, cdl_count); CPPUNIT_ASSERT_EQUAL(7, cl_count); inPort.publishInterfaces_public(prof); outPort.subscribeInterfaces_public(prof); // connect() RTC::ReturnCode_t ret; ret = outPort.connect(prof); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); // isLittleEndian() bool bret = outPort.isLittleEndian(); CPPUNIT_ASSERT( bret ); outPort.activateInterfaces(); outPort.deactivateInterfaces(); ret = outPort.disconnect_all(); CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret); portAdmin.deletePort(outPort); portAdmin.deletePort(inPort); // removeConnectorDataListener() for (int i(0); i<cdl_len; ++i) { outPort.removeConnectorDataListener((RTC::ConnectorDataListenerType)i, m_datalisteners[i]); } // removeConnectorListener() for (int i(0); i<cl_len; ++i) { outPort.removeConnectorListener((RTC::ConnectorListenerType)i, m_connlisteners[i]); } // Listener remove count check CPPUNIT_ASSERT_EQUAL(0, cdl_count); CPPUNIT_ASSERT_EQUAL(0, cl_count); } }; }; // namespace OutPortBase /*! * @brief Mock RTC */ namespace RTC { /*! * * Mock OutPortPushConnector * */ /*! * * */ OutPortPushConnector::OutPortPushConnector(ConnectorInfo info, InPortConsumer* consumer, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } m_publisher = createPublisher(info); m_publisher->init(info.properties); m_publisher->setListener(m_profile, &m_listeners); onConnect(); } /*! * * */ OutPortPushConnector::~OutPortPushConnector() { onDisconnect(); disconnect(); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::disconnect() { if (m_publisher != 0) { PublisherFactory& pfactory(PublisherFactory::instance()); pfactory.deleteObject(m_publisher); } m_publisher = 0; return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPushConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::activate() { RTC::logger.log("OutPortPushConnector::activate"); } /*! * * */ void OutPortPushConnector::deactivate() { RTC::logger.log("OutPortPushConnector::deactivate"); } /*! * * */ ConnectorBase::ReturnCode OutPortPushConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info) { return new PublisherFlush(); } /*! * * */ CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info) { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ void OutPortPushConnector::onConnect() { m_listeners.connector_[ON_CONNECT].notify(m_profile); } /*! * * */ void OutPortPushConnector::onDisconnect() { m_listeners.connector_[ON_DISCONNECT].notify(m_profile); } /*! * * Mock OutPortPullConnector * */ /*! * * */ OutPortPullConnector::OutPortPullConnector(ConnectorInfo info, OutPortProvider* provider, ConnectorListeners& listeners, CdrBufferBase* buffer) : OutPortConnector(info), m_provider(provider), m_listeners(listeners), m_buffer(buffer) { if(info.properties["OutPortBaseTests"]=="bad_alloc") { throw std::bad_alloc(); } } /*! * * */ OutPortPullConnector::~OutPortPullConnector() { } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::write(const cdrMemoryStream& data) { return PORT_OK; } /*! * * */ CdrBufferBase* OutPortPullConnector::getBuffer() { return new ::OutPortBase::CdrRingBufferMock(); } /*! * * */ ConnectorBase::ReturnCode OutPortPullConnector::disconnect() { return PORT_OK; } }; /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // OutPortBase_cpp
1932  //
1933 
1934  //既に "corba_cdr" で登録されている場合は削除する。
1935  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1936  {
1937  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1938  }
1939 
1940  //既に "corba_cdr" で登録されている場合は削除する。
1941  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
1942  {
1943  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
1944  }
1945  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
1947  addFactory("corba_cdr",
1952 
1953 
1954  OutPortBaseMock outPort("OutPortBaseTest",
1955  toTypename<RTC::TimedFloat>());
1956 
1957  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
1958  portAdmin.registerPort(outPort);
1959  RTC::ConnectorProfile prof;
1960  prof.connector_id = "id0";
1961  prof.name = CORBA::string_dup("OutPortBaseTest0");
1962  prof.ports.length(1);
1963  prof.ports[0] = outPort.get_port_profile()->port_ref;
1964  CORBA_SeqUtil::push_back(prof.properties,
1965  NVUtil::newNV("dataport.interface_type",
1966  "corba_cdr"));
1967  CORBA_SeqUtil::push_back(prof.properties,
1968  NVUtil::newNV("dataport.dataflow_type",
1969  "pull"));
1970  CORBA_SeqUtil::push_back(prof.properties,
1971  NVUtil::newNV("dataport.subscription_type",
1972  "new"));
1973  coil::Properties dummy;
1974  outPort.init(dummy);
1975 
1977  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1978  retcode = outPort.publishInterfaces_public(prof);
1979  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
1980  CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
1981 
1982 
1983  portAdmin.deletePort(outPort);
1984  }
1990  {
1991  //既に "corba_cdr" で登録されている場合は削除する。
1992  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
1993  {
1994  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
1995  }
1996  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
1998  addFactory("corba_cdr",
2003 
2004  //既に "corba_cdr" で登録されている場合は削除する。
2005  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
2006  {
2007  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
2008  }
2009  //"corba_cdr" に InPortCorbaCdrProviderMock を登録する。
2011  addFactory("corba_cdr",
2016 
2017 
2018  OutPortBaseMock outPort("OutPortBaseTest",
2019  toTypename<RTC::TimedFloat>());
2020 
2021  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2022  portAdmin.registerPort(outPort);
2023  RTC::ConnectorProfile prof;
2024  prof.connector_id = "id0";
2025  prof.name = CORBA::string_dup("OutPortBaseTest0");
2026  prof.ports.length(1);
2027  prof.ports[0] = outPort.get_port_profile()->port_ref;
2028  CORBA_SeqUtil::push_back(prof.properties,
2029  NVUtil::newNV("dataport.interface_type",
2030  "corba_cdr"));
2031  CORBA_SeqUtil::push_back(prof.properties,
2032  NVUtil::newNV("dataport.dataflow_type",
2033  "pull"));
2034  CORBA_SeqUtil::push_back(prof.properties,
2035  NVUtil::newNV("dataport.subscription_type",
2036  "new"));
2037  CORBA_SeqUtil::push_back(prof.properties,
2038  NVUtil::newNV("dataport.OutPortBaseTests",
2039  "bad_alloc"));
2040  coil::Properties dummy;
2041  outPort.init(dummy);
2042 
2044  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2045  retcode = outPort.publishInterfaces_public(prof);
2046  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2047  CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
2048 
2049  portAdmin.deletePort(outPort);
2050  }
2056  {
2057  //既に "corba_cdr" で登録されている場合は削除する。
2058  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
2059  {
2060  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
2061  }
2062  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
2064  addFactory("corba_cdr",
2069 
2070  //既に "corba_cdr" で登録されている場合は削除する。
2071  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
2072  {
2073  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
2074  }
2075  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
2077  addFactory("corba_cdr",
2082 
2083 
2084  OutPortBaseMock outPort("OutPortBaseTest",
2085  toTypename<RTC::TimedFloat>());
2086 
2087  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2088  portAdmin.registerPort(outPort);
2089 
2090  RTC::ConnectorProfile prof;
2091  prof.connector_id = "id0";
2092  prof.name = CORBA::string_dup("OutPortBaseTest0");
2093  prof.ports.length(1);
2094  prof.ports[0] = outPort.get_port_profile()->port_ref;
2095  CORBA_SeqUtil::push_back(prof.properties,
2096  NVUtil::newNV("dataport.interface_type",
2097  "corba_cdr"));
2098  CORBA_SeqUtil::push_back(prof.properties,
2099  NVUtil::newNV("dataport.dataflow_type",
2100  "push"));
2101  CORBA_SeqUtil::push_back(prof.properties,
2102  NVUtil::newNV("dataport.subscription_type",
2103  "new"));
2104  coil::Properties dummy;
2105  outPort.init(dummy);
2106 
2108  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2109  retcode = outPort.subscribeInterfaces_public(prof);
2110  CPPUNIT_ASSERT_EQUAL(1,(int)outPort.get_m_connectors().size());
2111  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
2112 
2113  prof.connector_id = "id1";
2114  prof.name = CORBA::string_dup("OutPortBaseTest1");
2115  retcode = outPort.subscribeInterfaces_public(prof);
2116  CPPUNIT_ASSERT_EQUAL(2,(int)outPort.get_m_connectors().size());
2117  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK,retcode);
2118 
2119  portAdmin.deletePort(outPort);
2120  }
2126  {
2127  //既に "corba_cdr" で登録されている場合は削除する。
2128  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
2129  {
2130  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
2131  }
2132  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
2134  addFactory("corba_cdr",
2139 
2140  //既に "corba_cdr" で登録されている場合は削除する。
2141  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
2142  {
2143  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
2144  }
2145  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
2147  addFactory("corba_cdr",
2152 
2153 
2154  OutPortBaseMock outPort("OutPortBaseTest",
2155  toTypename<RTC::TimedFloat>());
2156 
2157  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2158  portAdmin.registerPort(outPort);
2159 
2160  RTC::ConnectorProfile prof;
2161  prof.connector_id = "id0";
2162  prof.name = CORBA::string_dup("OutPortBaseTest0");
2163  prof.ports.length(1);
2164  prof.ports[0] = outPort.get_port_profile()->port_ref;
2165  CORBA_SeqUtil::push_back(prof.properties,
2166  NVUtil::newNV("dataport.interface_type",
2167  "corba_cdr"));
2168  CORBA_SeqUtil::push_back(prof.properties,
2169  NVUtil::newNV("dataport.dataflow_type",
2170  "pull"));
2171  CORBA_SeqUtil::push_back(prof.properties,
2172  NVUtil::newNV("dataport.subscription_type",
2173  "new"));
2175  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2176  retcode = outPort.subscribeInterfaces_public(prof);
2177  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2178  CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
2179 
2180  portAdmin.deletePort(outPort);
2181  }
2187  {
2188  //既に "corba_cdr" で登録されている場合は削除する。
2189  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
2190  {
2191  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
2192  }
2193  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
2195  addFactory("corba_cdr",
2200 
2201  //既に "corba_cdr" で登録されている場合は削除する。
2202  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
2203  {
2204  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
2205  }
2206  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
2208  addFactory("corba_cdr",
2213 
2214 
2215  OutPortBaseMock outPort("OutPortBaseTest",
2216  toTypename<RTC::TimedFloat>());
2217 
2218  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2219  portAdmin.registerPort(outPort);
2220 
2221  RTC::ConnectorProfile prof;
2222  prof.connector_id = "id0";
2223  prof.name = CORBA::string_dup("OutPortBaseTest0");
2224  prof.ports.length(1);
2225  prof.ports[0] = outPort.get_port_profile()->port_ref;
2226  CORBA_SeqUtil::push_back(prof.properties,
2227  NVUtil::newNV("dataport.interface_type",
2228  "corba_cdr"));
2229  CORBA_SeqUtil::push_back(prof.properties,
2230  NVUtil::newNV("dataport.dataflow_type",
2231  "else"));
2232  CORBA_SeqUtil::push_back(prof.properties,
2233  NVUtil::newNV("dataport.subscription_type",
2234  "new"));
2236  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2237  retcode = outPort.subscribeInterfaces_public(prof);
2238  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2239  CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
2240 
2241  portAdmin.deletePort(outPort);
2242  }
2248  {
2249  //既に "corba_cdr" で登録されている場合は削除する。
2250  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
2251  {
2252  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
2253  }
2254  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
2256  addFactory("corba_cdr",
2261 
2262  //既に "corba_cdr" で登録されている場合は削除する。
2263  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
2264  {
2265  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
2266  }
2267 
2268 
2269  OutPortBaseMock outPort("OutPortBaseTest",
2270  toTypename<RTC::TimedFloat>());
2271 
2272  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2273  portAdmin.registerPort(outPort);
2274 
2275  RTC::ConnectorProfile prof;
2276  prof.connector_id = "id0";
2277  prof.name = CORBA::string_dup("OutPortBaseTest0");
2278  prof.ports.length(1);
2279  prof.ports[0] = outPort.get_port_profile()->port_ref;
2280  CORBA_SeqUtil::push_back(prof.properties,
2281  NVUtil::newNV("dataport.interface_type",
2282  "corba_cdr"));
2283  CORBA_SeqUtil::push_back(prof.properties,
2284  NVUtil::newNV("dataport.dataflow_type",
2285  "push"));
2286  CORBA_SeqUtil::push_back(prof.properties,
2287  NVUtil::newNV("dataport.subscription_type",
2288  "new"));
2290  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2291  retcode = outPort.subscribeInterfaces_public(prof);
2292  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2293  CPPUNIT_ASSERT_EQUAL(RTC::BAD_PARAMETER,retcode);
2294 
2295  portAdmin.deletePort(outPort);
2296  }
2302  {
2303  //既に "corba_cdr" で登録されている場合は削除する。
2304  if( RTC::OutPortProviderFactory::instance().hasFactory("corba_cdr") )
2305  {
2306  RTC::OutPortProviderFactory::instance().removeFactory("corba_cdr");
2307  }
2308  //"corba_cdr" に OutPortCorbaCdrProviderMock を登録する。
2310  addFactory("corba_cdr",
2315 
2316  //既に "corba_cdr" で登録されている場合は削除する。
2317  if( RTC::InPortConsumerFactory::instance().hasFactory("corba_cdr") )
2318  {
2319  RTC::InPortConsumerFactory::instance().removeFactory("corba_cdr");
2320  }
2321  //"corba_cdr" に InPortCorbaCdrConsumerMock を登録する。
2323  addFactory("corba_cdr",
2328 
2329 
2330  OutPortBaseMock outPort("OutPortBaseTest",
2331  toTypename<RTC::TimedFloat>());
2332 
2333  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2334  portAdmin.registerPort(outPort);
2335 
2336  RTC::ConnectorProfile prof;
2337  prof.connector_id = "id0";
2338  prof.name = CORBA::string_dup("OutPortBaseTest0");
2339  prof.ports.length(1);
2340  prof.ports[0] = outPort.get_port_profile()->port_ref;
2341  CORBA_SeqUtil::push_back(prof.properties,
2342  NVUtil::newNV("dataport.interface_type",
2343  "corba_cdr"));
2344  CORBA_SeqUtil::push_back(prof.properties,
2345  NVUtil::newNV("dataport.dataflow_type",
2346  "push"));
2347  CORBA_SeqUtil::push_back(prof.properties,
2348  NVUtil::newNV("dataport.subscription_type",
2349  "new"));
2350  CORBA_SeqUtil::push_back(prof.properties,
2351  NVUtil::newNV("dataport.OutPortBaseTests",
2352  "bad_alloc"));
2353  coil::Properties dummy;
2354  outPort.init(dummy);
2355 
2357  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2358  retcode = outPort.subscribeInterfaces_public(prof);
2359  CPPUNIT_ASSERT_EQUAL(0,(int)outPort.get_m_connectors().size());
2360  CPPUNIT_ASSERT_EQUAL(RTC::RTC_ERROR,retcode);
2361 
2362  portAdmin.deletePort(outPort);
2363  }
2364 
2370  {
2371  RTC::TimedLong tdl;
2372  InPortMock<RTC::TimedLong> inPort("InPort", tdl);
2373 
2374  OutPortBaseMock outPort("OutPortBaseTest", toTypename<RTC::TimedLong>());
2375 
2376  RTC::PortAdmin portAdmin(m_pORB,m_pPOA);
2377  portAdmin.registerPort(outPort);
2378  portAdmin.registerPort(inPort);
2379 
2380  RTC::ConnectorProfile prof;
2381  prof.ports.length(2);
2382  prof.ports[0] = inPort.get_port_profile()->port_ref;
2383  prof.ports[1] = outPort.get_port_profile()->port_ref;
2384  CORBA_SeqUtil::push_back(prof.properties,
2385  NVUtil::newNV("dataport.interface_type",
2386  "corba_cdr"));
2387  CORBA_SeqUtil::push_back(prof.properties,
2388  NVUtil::newNV("dataport.dataflow_type",
2389  "push"));
2390  CORBA_SeqUtil::push_back(prof.properties,
2391  NVUtil::newNV("dataport.subscription_type",
2392  "flush"));
2393  prof.connector_id = "id0";
2394  prof.name = CORBA::string_dup("test");
2395  coil::Properties dummy;
2396  inPort.init(dummy);
2397  outPort.init(dummy);
2398 
2399  //ConnectorDataListeners settting
2400  for (int i(0); i<cdl_len; ++i)
2401  {
2402  m_datalisteners[i] = new DataListener(str_cdl[i]);
2403  }
2404 
2405  //ConnectorListeners settting
2406  for (int i(0); i<cl_len; ++i)
2407  {
2408  m_connlisteners[i] = new ConnListener(str_cl[i]);
2409  }
2410 
2411  // addConnectorDataListener()
2412  for (int i(0); i<cdl_len; ++i)
2413  {
2415  m_datalisteners[i], true);
2416  }
2417 
2418  // addConnectorListener()
2419  for (int i(0); i<cl_len; ++i)
2420  {
2422  m_connlisteners[i], true);
2423  }
2424 
2425  // Listener add count check
2426  CPPUNIT_ASSERT_EQUAL(10, cdl_count);
2427  CPPUNIT_ASSERT_EQUAL(7, cl_count);
2428 
2429  inPort.publishInterfaces_public(prof);
2430  outPort.subscribeInterfaces_public(prof);
2431 
2432  // connect()
2434  ret = outPort.connect(prof);
2435  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
2436 
2437  // isLittleEndian()
2438  bool bret = outPort.isLittleEndian();
2439  CPPUNIT_ASSERT( bret );
2440 
2441  outPort.activateInterfaces();
2442  outPort.deactivateInterfaces();
2443 
2444  ret = outPort.disconnect_all();
2445  CPPUNIT_ASSERT_EQUAL(RTC::RTC_OK, ret);
2446 
2447  portAdmin.deletePort(outPort);
2448  portAdmin.deletePort(inPort);
2449 
2450  // removeConnectorDataListener()
2451  for (int i(0); i<cdl_len; ++i)
2452  {
2454  m_datalisteners[i]);
2455  }
2456 
2457  // removeConnectorListener()
2458  for (int i(0); i<cl_len; ++i)
2459  {
2461  m_connlisteners[i]);
2462  }
2463 
2464  // Listener remove count check
2465  CPPUNIT_ASSERT_EQUAL(0, cdl_count);
2466  CPPUNIT_ASSERT_EQUAL(0, cl_count);
2467  }
2468 
2469  };
2470 }; // namespace OutPortBase
2471 
2472 
2476 namespace RTC
2477 {
2487  OutPortPushConnector::OutPortPushConnector(ConnectorInfo info,
2488  InPortConsumer* consumer,
2489  ConnectorListeners& listeners,
2490  CdrBufferBase* buffer)
2491  : OutPortConnector(info),
2492  m_consumer(consumer), m_publisher(0), m_listeners(listeners), m_buffer(buffer)
2493  {
2494  if(info.properties["OutPortBaseTests"]=="bad_alloc")
2495  {
2496  throw std::bad_alloc();
2497  }
2498  m_publisher = createPublisher(info);
2499  m_publisher->init(info.properties);
2500  m_publisher->setListener(m_profile, &m_listeners);
2501  onConnect();
2502  }
2507  OutPortPushConnector::~OutPortPushConnector()
2508  {
2509  onDisconnect();
2510  disconnect();
2511  }
2516  ConnectorBase::ReturnCode OutPortPushConnector::disconnect()
2517  {
2518  if (m_publisher != 0)
2519  {
2520  PublisherFactory& pfactory(PublisherFactory::instance());
2521  pfactory.deleteObject(m_publisher);
2522  }
2523  m_publisher = 0;
2524  return PORT_OK;
2525  }
2530  CdrBufferBase* OutPortPushConnector::getBuffer()
2531  {
2533  }
2538  void OutPortPushConnector::activate()
2539  {
2540  RTC::logger.log("OutPortPushConnector::activate");
2541  }
2546  void OutPortPushConnector::deactivate()
2547  {
2548  RTC::logger.log("OutPortPushConnector::deactivate");
2549  }
2555  OutPortPushConnector::write(const cdrMemoryStream& data)
2556  {
2557  return PORT_OK;
2558  }
2563  PublisherBase* OutPortPushConnector::createPublisher(ConnectorInfo& info)
2564  {
2565  return new PublisherFlush();
2566  }
2571  CdrBufferBase* OutPortPushConnector::createBuffer(ConnectorInfo& info)
2572  {
2574 
2575  }
2580  void OutPortPushConnector::onConnect()
2581  {
2582  m_listeners.connector_[ON_CONNECT].notify(m_profile);
2583  }
2588  void OutPortPushConnector::onDisconnect()
2589  {
2590  m_listeners.connector_[ON_DISCONNECT].notify(m_profile);
2591  }
2592 
2602  OutPortPullConnector::OutPortPullConnector(ConnectorInfo info,
2604  ConnectorListeners& listeners,
2605  CdrBufferBase* buffer)
2606  : OutPortConnector(info), m_provider(provider), m_listeners(listeners),
2607  m_buffer(buffer)
2608 
2609  {
2610  if(info.properties["OutPortBaseTests"]=="bad_alloc")
2611  {
2612  throw std::bad_alloc();
2613  }
2614  }
2619  OutPortPullConnector::~OutPortPullConnector()
2620  {
2621  }
2627  OutPortPullConnector::write(const cdrMemoryStream& data)
2628  {
2629  return PORT_OK;
2630  }
2635  CdrBufferBase* OutPortPullConnector::getBuffer()
2636  {
2638  }
2643  ConnectorBase::ReturnCode OutPortPullConnector::disconnect()
2644  {
2645  return PORT_OK;
2646  }
2647 };
2648 
2649 
2650 /*
2651  * Register test suite
2652  */
2654 
2655 #ifdef LOCAL_MAIN
2656 int main(int argc, char* argv[])
2657 {
2658 
2659  FORMAT format = TEXT_OUT;
2660  int target = 0;
2661  std::string xsl;
2662  std::string ns;
2663  std::string fname;
2664  std::ofstream ofs;
2665 
2666  int i(1);
2667  while (i < argc)
2668  {
2669  std::string arg(argv[i]);
2670  std::string next_arg;
2671  if (i + 1 < argc) next_arg = argv[i + 1];
2672  else next_arg = "";
2673 
2674  if (arg == "--text") { format = TEXT_OUT; break; }
2675  if (arg == "--xml")
2676  {
2677  if (next_arg == "")
2678  {
2679  fname = argv[0];
2680  fname += ".xml";
2681  }
2682  else
2683  {
2684  fname = next_arg;
2685  }
2686  format = XML_OUT;
2687  ofs.open(fname.c_str());
2688  }
2689  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
2690  if ( arg == "--cerr" ) { target = 1; break; }
2691  if ( arg == "--xsl" )
2692  {
2693  if (next_arg == "") xsl = "default.xsl";
2694  else xsl = next_arg;
2695  }
2696  if ( arg == "--namespace" )
2697  {
2698  if (next_arg == "")
2699  {
2700  std::cerr << "no namespace specified" << std::endl;
2701  exit(1);
2702  }
2703  else
2704  {
2705  xsl = next_arg;
2706  }
2707  }
2708  ++i;
2709  }
2710  CppUnit::TextUi::TestRunner runner;
2711  if ( ns.empty() )
2712  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
2713  else
2714  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
2715  CppUnit::Outputter* outputter = 0;
2716  std::ostream* stream = target ? &std::cerr : &std::cout;
2717  switch ( format )
2718  {
2719  case TEXT_OUT :
2720  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
2721  break;
2722  case XML_OUT :
2723  std::cout << "XML_OUT" << std::endl;
2724  outputter = new CppUnit::XmlOutputter(&runner.result(),
2725  ofs, "shift_jis");
2726  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
2727  break;
2728  case COMPILER_OUT :
2729  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
2730  break;
2731  }
2732  runner.setOutputter(outputter);
2733  runner.run();
2734  return 0; // runner.run() ? 0 : 1;
2735 }
2736 #endif // MAIN
2737 #endif // OutPortBase_cpp
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
Definition: NVUtil.h:79
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=-1)
Read data from the buffer.
virtual RTC::ReturnCode_t publishInterfaces_public(RTC::ConnectorProfile &connector_profile)
OutPortConnector * getConnectorById(const char *id)
Getting ConnectorProfile by ID.
ConnectorListeners class.
InPortConsumer abstract class.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
void test_subscribeInterfaces3(void)
subscribeInterfaces()メソッドのテスト
int main(int argc, char **argv)
void setLogger(Logger *logger)
ConnectorInfoList getConnectorProfiles()
ConnectorProfile list.
virtual ReturnCode length(size_t n)
Set the buffer length.
void addConnectorDataListener(ConnectorDataListenerType listener_type, ConnectorDataListener *listener, bool autoclean=true)
Adding BufferDataListener type listener.
BufferBase< cdrMemoryStream > CdrBufferBase
Definition: CdrBufferBase.h:30
PortableServer::POA_ptr m_pPOA
BUFFERSTATUS_ENUM RingBufferMock(long int length=8)
CORBA Consumer class.
InPort template class.
OutPortConnector base class.
coil::Properties properties
Connection properties.
coil::vstring getConnectorNames()
Connector name list.
RT-Component.
void test_publishInterfaces2(void)
publishInterfaces()メソッドのテスト
coil::vstring getConnectorIds()
ConnectorId list.
void test_subscribeInterfaces2(void)
subscribeInterfaces()メソッドのテスト
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=-1)
Write data into the buffer.
OutPortConnector * getConnectorByName(const char *name)
Getting Connector by name.
void setListener(RTC::ConnectorInfo &info, RTC::ConnectorListeners *listeners)
Set the listener.
bool unsubscribeFromRef(const SDOPackage::NVList &properties)
PublisherA(std::string &footPrints)
virtual void setUp()
Test initialization.
void test_initConsumers()
initConsumers()メソッドのテスト
ConnectorListener class.
void test_initConsumers2()
initConsumers()メソッドのテスト
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
Send data to the destination port.
void addConnectorListener(ConnectorListenerType callback_type, ConnectorListener *listener, bool autoclean=true)
Adding ConnectorListener type listener.
virtual RTC::ReturnCode_t publishInterfaces_public(RTC::ConnectorProfile &connector_profile)
void test_activateInterfaces_deactivateInterfaces(void)
activateInterfaces(),deactivateInterfaces()メソッドのテスト
void test_subscribeInterfaces5(void)
subscribeInterfaces()メソッドのテスト
RT component logger class.
void unsubscribeInterface(const SDOPackage::NVList &properties)
AbstractClass * Creator()
Creator template.
ReturnCode_t
Definition: doil.h:53
bool subscribeInterface(const SDOPackage::NVList &properties)
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
virtual void init(const coil::Properties &prop)
Set the buffer.
void log(const std::string &msg)
RTC::InPortConsumer * createCondumer_public(RTC::ConnectorProfile &cprof, coil::Properties &prop)
OutPortConnector class.
void test_subscribeInterfaces4(void)
subscribeInterfaces()メソッドのテスト
void test_initProviders()
initProviders()メソッドのテスト
void init(coil::Properties &prop)
Initializing configuration.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void unsubscribeInterface(const SDOPackage::NVList &properties)
Unsubscribe the data send notification.
OutPort class.
#define cdl_len
void removeConnectorListener(ConnectorListenerType callback_type, ConnectorListener *listener)
Removing BufferDataListener type listener.
static const char * str_cl[]
RTC::ConnectorListeners m_listeners
void test_publishInterfaces4(void)
publishInterfaces()メソッドのテスト
bool unsubscribeFromIor(const SDOPackage::NVList &properties)
static const char * str_cdl[]
std::vector< ConnectorInfo > ConnectorInfoList
virtual RTC::ReturnCode_t subscribeInterfaces_public(RTC::ConnectorProfile &connector_profile)
Typename function.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
void test_initProviders2()
initProviders()メソッドのテスト
bool isLittleEndian()
return it whether endian setting.
virtual RTC::ReturnCode_t subscribeInterfaces_public(RTC::ConnectorProfile &connector_profile)
Enum
DataPortStatus return codes.
Definition: BufferStatus.h:84
virtual size_t writable() const
Get a writable number.
#define cl_len
OutPortBaseMock(const char *name, const char *data_type)
PortAdmin class.
Definition: PortAdmin.h:52
bool subscribeInterface(const SDOPackage::NVList &properties)
Subscribe the data send notification.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
std::vector< std::string > vstring
Definition: stringutil.h:37
ConnectorDataListenerType
The types of ConnectorDataListener.
PublisherFlush class.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
Definition: BufferStatus.h:157
RingBufferMock< cdrMemoryStream > CdrRingBufferMock
void setBuffer(RTC::CdrBufferBase *buffer)
Setting outside buffer&#39;s pointer.
bool subscribeFromIor(const SDOPackage::NVList &properties)
void removeConnectorDataListener(ConnectorDataListenerType listener_type, ConnectorDataListener *listener)
Removing BufferDataListener type listener.
def bret
7 送受信データ比較
Definition: ConnectTest.py:377
void test_name()
name()メソッドのテスト
RTC::InPortConsumer::ReturnCode put(const cdrMemoryStream &data)
PublisherPeriodic class.
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
Definition: NVUtil.cpp:137
std::string toString(const SDOPackage::NVList &nv, const char *name)
Get NVList of specifid name as string.
Definition: NVUtil.cpp:282
virtual DataType * wptr(long int n=0)
Get the writing pointer.
void test_ConnectorListener(void)
addConnectorDataListener(), removeConnectorDataListener(), addConnectorListener(), removeConnectorListener(), isLittleEndian(), connect() メソッドのテスト
ConnectorDataListenerT class.
void registerPort(PortBase &port)
Regsiter the Port.
Definition: PortAdmin.cpp:239
DataListener(const char *name)
const CORBA::Any & find(const SDOPackage::NVList &nv, const char *name)
Return the value specified by name from NVList.
Definition: NVUtil.cpp:212
virtual ReturnCode advanceWptr(long int n=1)
Forward n writing pointers.
bool getConnectorProfileById(const char *id, ConnectorInfo &prof)
Getting ConnectorProfile by name.
::RTC::BufferStatus::Enum m_read_return_value
Push type connector class.
PublisherB(std::string &footPrints)
PublisherPeriodic class.
OutPortProvider class.
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
Output base class.
Definition: OutPortBase.h:230
PublisherC(std::string &footPrints)
std::string name
Connection name.
coil::Properties get_m_properties()
void init(coil::Properties &prop)
Initializing properties.
static int cl_count
virtual bool empty(void) const
Check on whether the buffer is empty.
void publishInterfaceProfile(SDOPackage::NVList &properties)
Publish InterfaceProfile information.
Logger class.
Definition: SystemLogger.h:99
Port for InPort.
Definition: InPortBase.h:67
virtual ReturnCode_t connect(ConnectorProfile &connector_profile)
[CORBA interface] Connect the Port
OutPortProvider.
virtual ReturnCode advanceRptr(long int n=1)
Forward n reading pointers.
void setConnector(RTC::OutPortConnector *connector)
set Connector
bool setLevel(const char *level)
Set log level by string.
::RTC::BufferStatus::Enum ReturnCode
PublisherFlush class.
prop
Organization::get_organization_property ();.
virtual PortProfile * get_port_profile()
[CORBA interface] Get the PortProfile of the Port
Definition: PortBase.cpp:100
Publisher base class.
const char * toTypename()
Definition: Typename.h:252
void test_publishInterfaces(void)
publishInterfaces()メソッドのテスト
void test_publishInterfaces3(void)
publishInterfaces()メソッドのテスト
coil::Properties toProperties(const SDOPackage::NVList &nv)
Transform NVList to the properties.
Definition: NVUtil.cpp:180
InPortBase base class.
virtual DataType * rptr(long int n=0)
Get the reading pointer.
void Destructor(AbstractClass *&obj)
Destructor template.
ConnectorListenerType
The types of ConnectorListener.
Class represents a set of properties.
Definition: Properties.h:101
std::vector< DataType > m_buffer
int size(void) const
Get the number of Properties.
Definition: Properties.cpp:432
virtual void operator()(const RTC::ConnectorInfo &info, const RTC::TimedLong &data)
Virtual Callback method.
void test_init_properties()
init(),properties()メソッドのテスト
OutPortPull type connector class.
int countLog(const std::string &msg)
Base class of Publisher.
Definition: PublisherBase.h:63
virtual void activateInterfaces()
Activate all Port interfaces.
bool getConnectorProfileByName(const char *name, ConnectorInfo &prof)
Getting ConnectorProfile by name.
RTC::OutPortConnector * createConnector_public(const RTC::ConnectorProfile &cprof, coil::Properties &prop, RTC::OutPortProvider *provider)
void test_publishInterfaces5(void)
publishInterfaces()メソッドのテスト
void init(coil::Properties &prop)
Initializing configuration.
virtual size_t readable() const
Write data into the buffer.
virtual bool full(void) const
Check on whether the buffer is full.
CPPUNIT_TEST_SUITE_REGISTRATION(OutPortBase::OutPortBaseTests)
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.
std::vector< ConnectorBase * > ConnectorList
coil::GlobalFactory< PublisherBase > PublisherFactory
PublisherNew class.
Definition: PublisherNew.h:69
void deletePort(PortBase &port)
Unregister the Port registration.
Definition: PortAdmin.cpp:297
bool subscribeFromRef(const SDOPackage::NVList &properties)
virtual void operator()(const RTC::ConnectorInfo &info)
Virtual Callback method.
void init(coil::Properties &prop)
Initializing properties.
Definition: InPortBase.cpp:96
virtual ReturnCode_t disconnect_all()
[CORBA interface] Disconnect the All Ports
Definition: PortBase.cpp:454
const std::vector< OutPortConnector * > & connectors()
Connector list.
void test_constructor()
コンスラクタのテスト
bool publishInterface(SDOPackage::NVList &prop)
Publish interface information.
BufferBase abstract class.
Definition: BufferBase.h:104
InPortMock(const char *name, DataType &value)
virtual ReturnCode reset()
Reset the buffer status.
virtual void tearDown()
Test finalization.
virtual void deactivateInterfaces()
Deactivate all Port interfaces.
InPortConsumer class.
void test_connectors_getConnectorXX(void)
connectors(),getConnectorProfiles()メソッドのテスト
connector listener class
ConnListener(const char *name)
PublisherNew class.
RTC&#39;s Port administration class.
void test_subscribeInterfaces(void)
subscribeInterfaces()メソッドのテスト
std::vector< std::string > m_log
PublisherD(std::string &footPrints)
bool read()
It is a virtual method that is called from RTObject_impl::readAll(). This method reads out data from ...
const char * getName() const
Get the name of this Port.
Definition: PortBase.cpp:504
coil::Properties & properties()
Get properties.
RTC::OutPortProvider * createProvider_public(RTC::ConnectorProfile &cprof, coil::Properties &prop)
void set_read_return_value(::RTC::BufferStatus::Enum value)
static int cdl_count
const PortProfile & getPortProfile() const
Get the PortProfile of the Port.
Definition: PortBase.cpp:119


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:43