38 #ifndef CORBA_SeqUtil_cpp 39 #define CORBA_SeqUtil_cpp 41 #include <cppunit/ui/text/TestRunner.h> 42 #include <cppunit/TextOutputter.h> 43 #include <cppunit/extensions/TestFactoryRegistry.h> 44 #include <cppunit/extensions/HelperMacros.h> 45 #include <cppunit/TestAssert.h> 51 #include "SeqUtilTestsSkel.h" 63 void log(
const std::string& msg)
71 for (
int i = 0; i < (int)
m_log.size(); ++i)
73 if (
m_log[i] == msg) ++count;
113 :
public CppUnit::TestFixture
117 CPPUNIT_TEST(test_for_each);
118 CPPUNIT_TEST(test_find);
119 CPPUNIT_TEST(test_push_back);
120 CPPUNIT_TEST(test_push_back_list);
121 CPPUNIT_TEST(test_insert);
122 CPPUNIT_TEST(test_front);
123 CPPUNIT_TEST(test_back);
124 CPPUNIT_TEST(test_erase);
125 CPPUNIT_TEST(test_erase_if);
126 CPPUNIT_TEST(test_clear);
127 CPPUNIT_TEST(test_refToVstring);
129 CPPUNIT_TEST_SUITE_END();
134 CORBA::Short
st, rst;
174 : _receivedNameValues(receivedNameValues) {}
177 _receivedNameValues.push_back(nv);
199 nvShort.name =
"short";
200 nvShort.value <<= (CORBA::Short) 123;
204 nvLong.name =
"long";
205 nvLong.value <<= (CORBA::Long) 123456;
209 nvFloat.name =
"float";
210 nvFloat.value <<= (CORBA::Float) 987.654;
214 nvDouble.name =
"double";
215 nvDouble.value <<= (CORBA::Double) 987654.321987;
216 nvlist[3] = nvDouble;
219 vector<NameValue> receivedNameValues;
223 CPPUNIT_ASSERT_EQUAL(4, (
int) receivedNameValues.size());
224 CPPUNIT_ASSERT_EQUAL((
string) nvlist[0].name, (
string) receivedNameValues[0].name);
225 CPPUNIT_ASSERT_EQUAL((
string) nvlist[1].name, (
string) receivedNameValues[1].name);
226 CPPUNIT_ASSERT_EQUAL((
string) nvlist[2].name, (
string) receivedNameValues[2].name);
227 CPPUNIT_ASSERT_EQUAL((
string) nvlist[3].name, (
string) receivedNameValues[3].name);
229 CORBA::Short expectedShort, actualShort;
230 nvlist[0].value >>= expectedShort;
231 receivedNameValues[0].value >>= actualShort;
232 CPPUNIT_ASSERT_EQUAL(expectedShort, actualShort);
234 CORBA::Long expectedLong, actualLong;
235 nvlist[1].value >>= expectedLong;
236 receivedNameValues[1].value >>= actualLong;
237 CPPUNIT_ASSERT_EQUAL(expectedLong, actualLong);
239 CORBA::Float expectedFloat, actualFloat;
240 nvlist[2].value >>= expectedFloat;
241 receivedNameValues[2].value >>= actualFloat;
242 CPPUNIT_ASSERT_EQUAL(expectedFloat, actualFloat);
244 CORBA::Double expectedDouble, actualDouble;
245 nvlist[3].value >>= expectedDouble;
246 receivedNameValues[3].value >>= actualDouble;
247 CPPUNIT_ASSERT_EQUAL(expectedDouble, actualDouble);
259 return _name == string(nv.name);
279 nvShort.name =
"short";
280 nvShort.value <<= (CORBA::Short) 123;
284 nvLong.name =
"long";
285 nvLong.value <<= (CORBA::Long) 123456;
289 nvFloat.name =
"float";
290 nvFloat.value <<= (CORBA::Float) 987.654;
294 nvDouble.name =
"double";
295 nvDouble.value <<= (CORBA::Double) 987654.321987;
296 nvlist[3] = nvDouble;
324 nvShort.name =
"short";
325 nvShort.value <<= (CORBA::Short) 123;
327 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 1, nvlist.length());
331 nvLong.name =
"long";
332 nvLong.value <<= (CORBA::Long) 123456;
334 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 2, nvlist.length());
338 nvFloat.name =
"float";
339 nvFloat.value <<= (CORBA::Float) 987.654;
341 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 3, nvlist.length());
345 nvDouble.name =
"double";
346 nvDouble.value <<= (CORBA::Double) 987654.321987;
348 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 4, nvlist.length());
351 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist[0].name);
352 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist[1].name);
353 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist[2].name);
354 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist[3].name);
356 CORBA::Short actualShort;
357 nvlist[0].value >>= actualShort;
358 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort);
360 CORBA::Long actualLong;
361 nvlist[1].value >>= actualLong;
362 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong);
364 CORBA::Float actualFloat;
365 nvlist[2].value >>= actualFloat;
366 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat);
368 CORBA::Double actualDouble;
369 nvlist[3].value >>= actualDouble;
370 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble);
387 nvShort.name =
"short";
388 nvShort.value <<= (CORBA::Short) 123;
389 nvlist1[0] = nvShort;
392 nvLong.name =
"long";
393 nvLong.value <<= (CORBA::Long) 123456;
401 nvFloat.name =
"float";
402 nvFloat.value <<= (CORBA::Float) 987.654;
403 nvlist2[0] = nvFloat;
406 nvDouble.name =
"double";
407 nvDouble.value <<= (CORBA::Double) 987654.321987;
408 nvlist2[1] = nvDouble;
414 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist1[0].name);
415 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist1[1].name);
416 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist1[2].name);
417 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist1[3].name);
419 CORBA::Short actualShort;
420 nvlist1[0].value >>= actualShort;
421 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort);
423 CORBA::Long actualLong;
424 nvlist1[1].value >>= actualLong;
425 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong);
427 CORBA::Float actualFloat;
428 nvlist1[2].value >>= actualFloat;
429 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat);
431 CORBA::Double actualDouble;
432 nvlist1[3].value >>= actualDouble;
433 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble);
452 nvLong.name =
"long";
453 nvLong.value <<= (CORBA::Long) 123456;
458 nvShort.name =
"short";
459 nvShort.value <<= (CORBA::Short) 123;
464 nvDouble.name =
"double";
465 nvDouble.value <<= (CORBA::Double) 987654.321987;
470 nvFloat.name =
"float";
471 nvFloat.value <<= (CORBA::Float) 987.654;
475 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist[0].name);
476 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist[1].name);
477 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist[2].name);
478 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist[3].name);
480 CORBA::Short actualShort;
481 nvlist[0].value >>= actualShort;
482 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort);
484 CORBA::Long actualLong;
485 nvlist[1].value >>= actualLong;
486 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong);
488 CORBA::Float actualFloat;
489 nvlist[2].value >>= actualFloat;
490 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat);
492 CORBA::Double actualDouble;
493 nvlist[3].value >>= actualDouble;
494 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble);
510 CORBA_SeqUtil::front<NVList, NameValue>(nvlistEmpty);
511 CPPUNIT_FAIL(
"Exception must be thrown.");
521 nvShort.name =
"short";
522 nvShort.value <<= (CORBA::Short) 123;
526 nvLong.name =
"long";
527 nvLong.value <<= (CORBA::Long) 123456;
531 nvFloat.name =
"float";
532 nvFloat.value <<= (CORBA::Float) 987.654;
536 nvDouble.name =
"double";
537 nvDouble.value <<= (CORBA::Double) 987654.321987;
538 nvlist[3] = nvDouble;
541 NameValue nvFront = CORBA_SeqUtil::front<NVList, NameValue>(nvlist);
543 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvFront.name);
545 CORBA::Short actualValue;
546 nvFront.value >>= actualValue;
547 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualValue);
563 CORBA_SeqUtil::back<NVList, NameValue>(nvlistEmpty);
564 CPPUNIT_FAIL(
"Exception must be thrown.");
574 nvShort.name =
"short";
575 nvShort.value <<= (CORBA::Short) 123;
579 nvLong.name =
"long";
580 nvLong.value <<= (CORBA::Long) 123456;
584 nvFloat.name =
"float";
585 nvFloat.value <<= (CORBA::Float) 987.654;
589 nvDouble.name =
"double";
590 nvDouble.value <<= (CORBA::Double) 987654.321987;
591 nvlist[3] = nvDouble;
594 NameValue nvBack = CORBA_SeqUtil::back<NVList, NameValue>(nvlist);
596 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvBack.name);
598 CORBA::Double actualValue;
599 nvBack.value >>= actualValue;
600 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualValue);
615 NVList nvlist1, nvlist2, nvlist3;
621 nvShort.name =
"short";
622 nvShort.value <<= (CORBA::Short) 123;
623 nvlist1[0] = nvShort;
624 nvlist2[0] = nvShort;
625 nvlist3[0] = nvShort;
628 nvLong.name =
"long";
629 nvLong.value <<= (CORBA::Long) 123456;
635 nvFloat.name =
"float";
636 nvFloat.value <<= (CORBA::Float) 987.654;
637 nvlist1[2] = nvFloat;
638 nvlist2[2] = nvFloat;
639 nvlist3[2] = nvFloat;
642 nvDouble.name =
"double";
643 nvDouble.value <<= (CORBA::Double) 987654.321987;
644 nvlist1[3] = nvDouble;
645 nvlist2[3] = nvDouble;
646 nvlist3[3] = nvDouble;
650 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 3, nvlist1.length());
651 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist1[0].name);
652 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist1[1].name);
653 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist1[2].name);
655 CORBA::Long actualLong1;
656 nvlist1[0].value >>= actualLong1;
657 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong1);
659 CORBA::Float actualFloat1;
660 nvlist1[1].value >>= actualFloat1;
661 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat1);
663 CORBA::Double actualDouble1;
664 nvlist1[2].value >>= actualDouble1;
665 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble1);
669 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 3, nvlist2.length());
670 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist2[0].name);
671 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist2[1].name);
672 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist2[2].name);
674 CORBA::Short actualShort2;
675 nvlist2[0].value >>= actualShort2;
676 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort2);
678 CORBA::Float actualFloat2;
679 nvlist2[1].value >>= actualFloat2;
680 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat2);
682 CORBA::Double actualDouble2;
683 nvlist2[2].value >>= actualDouble2;
684 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble2);
688 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 3, nvlist3.length());
689 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist3[0].name);
690 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist3[1].name);
691 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist3[2].name);
693 CORBA::Short actualShort3;
694 nvlist3[0].value >>= actualShort3;
695 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort3);
697 CORBA::Long actualLong3;
698 nvlist3[1].value >>= actualLong3;
699 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong3);
701 CORBA::Float actualFloat3;
702 nvlist3[2].value >>= actualFloat3;
703 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat3);
716 return _name == std::string(nv.name);
737 nvShort.name =
"short";
738 nvShort.value <<= (CORBA::Short) 123;
739 nvlist1[0] = nvShort;
740 nvlist2[0] = nvShort;
743 nvLong.name =
"long";
744 nvLong.value <<= (CORBA::Long) 123456;
749 nvFloat.name =
"float";
750 nvFloat.value <<= (CORBA::Float) 987.654;
751 nvlist1[2] = nvFloat;
752 nvlist2[2] = nvFloat;
755 nvDouble.name =
"double";
756 nvDouble.value <<= (CORBA::Double) 987654.321987;
757 nvlist1[3] = nvDouble;
758 nvlist2[3] = nvDouble;
763 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist1[0].name);
764 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist1[1].name);
765 CPPUNIT_ASSERT_EQUAL((
string)
"float", (
string) nvlist1[2].name);
766 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist1[3].name);
768 CORBA::Short actualShort1;
769 nvlist1[0].value >>= actualShort1;
770 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort1);
772 CORBA::Long actualLong1;
773 nvlist1[1].value >>= actualLong1;
774 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong1);
776 CORBA::Float actualFloat1;
777 nvlist1[2].value >>= actualFloat1;
778 CPPUNIT_ASSERT_EQUAL((CORBA::Float) 987.654, actualFloat1);
780 CORBA::Double actualDouble1;
781 nvlist1[3].value >>= actualDouble1;
782 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble1);
787 CPPUNIT_ASSERT_EQUAL((
string)
"short", (
string) nvlist2[0].name);
788 CPPUNIT_ASSERT_EQUAL((
string)
"long", (
string) nvlist2[1].name);
789 CPPUNIT_ASSERT_EQUAL((
string)
"double", (
string) nvlist2[2].name);
791 CORBA::Short actualShort2;
792 nvlist2[0].value >>= actualShort2;
793 CPPUNIT_ASSERT_EQUAL((CORBA::Short) 123, actualShort2);
795 CORBA::Long actualLong2;
796 nvlist2[1].value >>= actualLong2;
797 CPPUNIT_ASSERT_EQUAL((CORBA::Long) 123456, actualLong2);
799 CORBA::Double actualDouble2;
800 nvlist2[2].value >>= actualDouble2;
801 CPPUNIT_ASSERT_EQUAL((CORBA::Double) 987654.321987, actualDouble2);
818 nvShort.name =
"short";
819 nvShort.value <<= (CORBA::Short) 123;
823 nvLong.name =
"long";
824 nvLong.value <<= (CORBA::Long) 123456;
828 nvFloat.name =
"float";
829 nvFloat.value <<= (CORBA::Float) 987.654;
833 nvDouble.name =
"double";
834 nvDouble.value <<= (CORBA::Double) 987654.321987;
835 nvlist[3] = nvDouble;
839 CPPUNIT_ASSERT_EQUAL((CORBA::ULong) 0, nvlist.length());
853 CORBA::ORB_ptr m_pORB = CORBA::ORB_init(argc, argv);
854 PortableServer::POA_ptr m_pPOA =
855 PortableServer::POA::_narrow(m_pORB->resolve_initial_references(
"RootPOA"));
856 m_pPOA->the_POAManager()->activate();
861 CPPUNIT_ASSERT_EQUAL(
true, portAdmin.
addPort(*port0));
863 RTC::PortService_var portRef0 = portAdmin.
getPortRef(
"port0");
864 RTC::ConnectorProfile cprof;
865 cprof.connector_id =
"id";
866 cprof.name = CORBA::string_dup(
"Test");
877 cprof.ports.length(1);
878 cprof.ports[0] = portRef0;
881 int len = str.size();
882 int pos = str[0].find(
"IOR", 0);
883 CPPUNIT_ASSERT_EQUAL(1, len);
884 CPPUNIT_ASSERT(pos != string::npos);
899 int main(
int argc,
char* argv[])
912 std::string arg(argv[i]);
913 std::string next_arg;
914 if (i + 1 < argc) next_arg = argv[i + 1];
917 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
930 ofs.open(fname.c_str());
932 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
933 if ( arg ==
"--cerr" ) { target = 1;
break; }
934 if ( arg ==
"--xsl" )
936 if (next_arg ==
"") xsl =
"default.xsl";
939 if ( arg ==
"--namespace" )
943 std::cerr <<
"no namespace specified" << std::endl;
953 CppUnit::TextUi::TestRunner runner;
955 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
957 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
958 CppUnit::Outputter* outputter = 0;
959 std::ostream* stream = target ? &std::cerr : &std::cout;
963 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
966 std::cout <<
"XML_OUT" << std::endl;
967 outputter =
new CppUnit::XmlOutputter(&runner.result(),
969 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
972 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
975 runner.setOutputter(outputter);
981 #endif // CORBA_SeqUtil_cpp functor_find(const string &name)
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
void test_push_back()
push_back()メソッドのテスト
virtual RTC::ReturnCode_t subscribeInterfaces(const RTC::ConnectorProfile &)
int main(int argc, char **argv)
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
void clear(CorbaSequence &seq)
Erase all the elements of the CORBA sequence.
bool operator()(const NameValue &nv)
std::vector< std::pair< std::string, std::string > > NVList
virtual void deactivateInterfaces()
Deactivate all Port interfaces.
void test_for_each()
for_each()メソッドのテスト
void test_erase_if()
erase_if()メソッドのテスト
PortService_ptr getPortRef(const char *port_name) const
Get the reference to Port object.
void test_insert()
insert()メソッドのテスト
CORBA_SeqUtilTests()
Constructor.
void test_push_back_list()
push_back_list()メソッドのテスト
bool operator()(const NameValue &nv)
vector< NameValue > & _receivedNameValues
std::vector< std::string > vstring
void log(const std::string &msg)
virtual RTC::ReturnCode_t publishInterfaces(RTC::ConnectorProfile &)
virtual void setUp()
Test initialization.
void insert(CorbaSequence &seq, SequenceElement &elem, CORBA::ULong index)
Insert the element to the CORBA sequence.
functor_erase_if(const char *name)
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
virtual void tearDown()
Test finalization.
NameValue and NVList utility functions.
void test_clear()
clear()メソッドのテスト
CORBA sequence utility template functions.
void erase_if(CorbaSequence &seq, Functor f)
Remove an element of a sequence according to a predicate.
void test_back()
back()メソッドのテスト
~CORBA_SeqUtilTests()
Destructor.
virtual void activateInterfaces()
Activate all Port interfaces.
CPPUNIT_TEST_SUITE_REGISTRATION(CORBA_SeqUtil::CORBA_SeqUtilTests)
functor_for_each(vector< NameValue > &receivedNameValues)
void test_find()
find()メソッドのテスト
int countLog(const std::string &msg)
std::vector< std::string > m_log
bool addPort(PortBase &port)
Regsiter the Port.
void push_back_list(CorbaSequence &seq1, const CorbaSequence &seq2)
Merge the elements of the CORBA sequence.
void test_refToVstring()
refToVstring()メソッドのテスト
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
test_erase_if()で使用するファンクタ
void test_front()
front()メソッドのテスト
void test_erase()
erase()メソッドのテスト
bool operator()(const NameValue &nv)
test_for_each()で使用するファンクタ
coil::vstring refToVstring(const CorbaRefSequence &objlist)
CORBA IOR helper functions.
virtual void unsubscribeInterfaces(const RTC::ConnectorProfile &)
void setName(const char *name)
Set the name of this Port.
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
RTC's Port administration class.