52 #include <cppunit/ui/text/TestRunner.h> 53 #include <cppunit/TextOutputter.h> 54 #include <cppunit/extensions/TestFactoryRegistry.h> 55 #include <cppunit/extensions/HelperMacros.h> 56 #include <cppunit/TestAssert.h> 73 :
public CppUnit::TestFixture
76 CPPUNIT_TEST(test_newNV_Short);
77 CPPUNIT_TEST(test_newNV_Long);
78 CPPUNIT_TEST(test_newNV_Float);
79 CPPUNIT_TEST(test_newNV_Double);
80 CPPUNIT_TEST(test_newNV_Str);
81 CPPUNIT_TEST(test_newNVChar);
82 CPPUNIT_TEST(test_newNVBool);
83 CPPUNIT_TEST(test_newNVOctet);
84 CPPUNIT_TEST(test_copy);
85 CPPUNIT_TEST(test_toProperties);
86 CPPUNIT_TEST(test_copyToProperties);
87 CPPUNIT_TEST(test_find);
88 CPPUNIT_TEST(test_find_index);
89 CPPUNIT_TEST(test_isString);
90 CPPUNIT_TEST(test_isStringValue);
91 CPPUNIT_TEST(test_toString);
92 CPPUNIT_TEST(test_appendStringValue);
93 CPPUNIT_TEST(test_append);
94 CPPUNIT_TEST(test_dump);
95 CPPUNIT_TEST(test_toStringNV);
96 CPPUNIT_TEST_SUITE_END();
105 for (
int i = 0; i <
g_argc; i++) {
106 argv[i] = (
char *)g_argv[i].c_str();
109 orb = CORBA::ORB_init(g_argc, argv);
132 CORBA::Short value = 1;
133 string name =
"short";
134 SDOPackage::NameValue
nv =
newNV(name.c_str(), value);
136 string nvName(nv.name);
137 CPPUNIT_ASSERT_EQUAL(name, nvName);
139 CORBA::Short nvValue;
140 nv.value >>= nvValue;
141 CPPUNIT_ASSERT_EQUAL(value, nvValue);
152 CORBA::Long value = 999999999;
153 string name =
"long";
154 SDOPackage::NameValue
nv =
newNV(name.c_str(), value);
156 string nvName(nv.name);
157 CPPUNIT_ASSERT_EQUAL(name, nvName);
160 nv.value >>= nvValue;
161 CPPUNIT_ASSERT_EQUAL(value, nvValue);
172 CORBA::Float value = 99999.9;
173 string name =
"float";
174 SDOPackage::NameValue
nv =
newNV(name.c_str(), value);
176 string nvName(nv.name);
177 CPPUNIT_ASSERT_EQUAL(name, nvName);
179 CORBA::Float nvValue;
180 nv.value >>= nvValue;
181 CPPUNIT_ASSERT_EQUAL(value, nvValue);
192 CORBA::Double value = 9999999.999;
193 string name =
"double";
194 SDOPackage::NameValue
nv =
newNV(name.c_str(), value);
196 string nvName(nv.name);
197 CPPUNIT_ASSERT_EQUAL(name, nvName);
199 CORBA::Double nvValue;
200 nv.value >>= nvValue;
201 CPPUNIT_ASSERT_EQUAL(value, nvValue);
212 string name =
"string";
213 CORBA::String_var value = CORBA::string_dup(
"Hello, world!");
214 SDOPackage::NameValue
nv =
newNV(name.c_str(), value);
217 string nvName(nv.name);
218 CPPUNIT_ASSERT_EQUAL(name, nvName);
223 nv.value >>= nvValue;
224 CPPUNIT_ASSERT_EQUAL(
string(
"Hello, world!"),
string(nvValue));
235 string name =
"char";
236 CORBA::Char value =
'A';
237 SDOPackage::NameValue
nv =
newNVChar(name.c_str(), value);
240 string nvName(nv.name);
241 CPPUNIT_ASSERT_EQUAL(name, nvName);
245 nv.value >>= CORBA::Any::to_char(nvValue);
246 CPPUNIT_ASSERT_EQUAL(value, nvValue);
256 string name =
"bool";
257 CORBA::Boolean value =
false;
258 SDOPackage::NameValue
nv =
newNVBool(name.c_str(), value);
260 string nvName(nv.name);
261 CPPUNIT_ASSERT_EQUAL(name, nvName);
263 CORBA::Boolean nvValue;
264 nv.value >>= CORBA::Any::to_boolean(nvValue);
265 CPPUNIT_ASSERT_EQUAL(value, nvValue);
275 string name =
"octet";
276 CORBA::Octet value = 030;
277 SDOPackage::NameValue
nv =
newNVOctet(name.c_str(), value);
279 string nvName(nv.name);
280 CPPUNIT_ASSERT_EQUAL(name, nvName);
282 CORBA::Octet nvValue;
283 nv.value >>= CORBA::Any::to_octet(nvValue);
284 CPPUNIT_ASSERT_EQUAL(value, nvValue);
296 string name =
"port-type";
297 string value =
"port-type-value";
298 map<string, string> mProp;
307 string nvName(nvlist[0].name);
308 CPPUNIT_ASSERT_EQUAL(name, nvName);
311 nvlist[0].value >>= getval;
312 string nvValue(getval);
313 CPPUNIT_ASSERT_EQUAL(value, nvValue);
327 string name1 =
"testname.test1";
328 string value1 =
"testval1";
329 nvlist[0].name = name1.c_str();
330 nvlist[0].value <<= value1.c_str();
332 string name2 =
"testname.test2";
333 string value2 =
"testval2";
334 nvlist[1].name = name2.c_str();
335 nvlist[1].value <<= value2.c_str();
342 CPPUNIT_ASSERT_EQUAL(value1, propValue1);
345 CPPUNIT_ASSERT_EQUAL(value2, propValue2);
359 string name1 =
"testname.test1";
360 string value1 =
"testval1";
361 nvlist[0].name = name1.c_str();
362 nvlist[0].value <<= value1.c_str();
364 string name2 =
"testname.test2";
365 string value2 =
"testval2";
366 nvlist[1].name = name2.c_str();
367 nvlist[1].value <<= value2.c_str();
375 CPPUNIT_ASSERT_EQUAL(value1, propValue1);
377 CPPUNIT_ASSERT_EQUAL(value2, propValue2);
391 string name1 =
"short";
392 CORBA::Short value1 = 1;
393 nvlist[0].name = name1.c_str();
394 nvlist[0].value <<= value1;
397 string name2 =
"long";
398 CORBA::Long value2 = 111;
399 nvlist[1].name = name2.c_str();
400 nvlist[1].value <<= value2;
403 CORBA::Short foundValue1;
404 (
find(nvlist, name1.c_str())) >>= foundValue1;
405 CPPUNIT_ASSERT_EQUAL(value1, foundValue1);
408 CORBA::Long foundValue2;
409 (
find(nvlist, name2.c_str())) >>= foundValue2;
410 CPPUNIT_ASSERT_EQUAL(value2, foundValue2);
424 string name1 =
"short";
425 CORBA::Short value1 = 1;
426 nvlist[0].name = name1.c_str();
427 nvlist[0].value <<= value1;
430 string name2 =
"long";
431 CORBA::Long value2 = 111;
432 nvlist[1].name = name2.c_str();
433 nvlist[1].value <<= value2;
438 CPPUNIT_ASSERT_EQUAL((CORBA::Long)0, ret);
442 CPPUNIT_ASSERT_EQUAL((CORBA::Long)1, ret);
456 string name1 =
"short";
457 CORBA::Short value1 = 1;
458 nvlist[0].name = name1.c_str();
459 nvlist[0].value <<= value1;
462 string name2 =
"string";
463 string value2 =
"test";
464 nvlist[1].name = name2.c_str();
465 nvlist[1].value <<= value2.c_str();
468 CPPUNIT_ASSERT(!
isString(nvlist, name1.c_str()));
469 CPPUNIT_ASSERT(
isString(nvlist, name2.c_str()));
483 string name1 =
"short";
484 CORBA::Short value1 = 1;
485 nvlist[0].name = name1.c_str();
486 nvlist[0].value <<= value1;
489 string name2 =
"string";
490 string value2 =
"test";
491 nvlist[1].name = name2.c_str();
492 nvlist[1].value <<= value2.c_str();
496 CPPUNIT_ASSERT(
isStringValue(nvlist, name2.c_str(),
"test"));
511 string name1 =
"short";
512 CORBA::Short value1 = 1;
513 nvlist[0].name = name1.c_str();
514 nvlist[0].value <<= value1;
517 string name2 =
"string";
518 string value2 =
"test";
519 nvlist[1].name = name2.c_str();
520 nvlist[1].value <<= value2.c_str();
524 CPPUNIT_ASSERT_EQUAL(empty,
toString(nvlist, name1.c_str()));
525 CPPUNIT_ASSERT_EQUAL(value2,
toString(nvlist, name2.c_str()));
540 string name1 =
"language";
541 string value1 =
"japanese";
542 nvlist[0].name = name1.c_str();
543 nvlist[0].value <<= value1.c_str();
545 string name2 =
"fruit";
546 string value2 =
"apple";
547 nvlist[1].name = name2.c_str();
548 nvlist[1].value <<= value2.c_str();
550 string name3 =
"drink";
551 string value3 =
"coffee, coke";
552 nvlist[2].name = name3.c_str();
553 nvlist[2].value <<= value3.c_str();
557 string value4 =
"unix";
559 CPPUNIT_ASSERT_EQUAL(value4,
toString(nvlist, name4.c_str()));
562 string name5 = name1;
563 string value5 =
"english";
565 string expectedValueLanguage =
"japanese,english";
566 CPPUNIT_ASSERT_EQUAL(expectedValueLanguage,
toString(nvlist, name5.c_str()));
569 string name6 = name2;
570 string value6 = value2;
572 CPPUNIT_ASSERT_EQUAL(value2,
toString(nvlist, name6.c_str()));
575 string name7 = name3;
576 string value7 =
"coke, beer";
578 string expectedValueDrink =
"coffee, coke,coke, beer";
579 CPPUNIT_ASSERT_EQUAL(expectedValueDrink,
toString(nvlist, name7.c_str()));
593 string nameA1 =
"nameA1";
594 string valueA1 =
"valueA1";
595 nvlistA[0].name = nameA1.c_str();
596 nvlistA[0].value <<= valueA1.c_str();
598 string nameA2 =
"nameA2";
599 string valueA2 =
"valueA2";
600 nvlistA[1].name = nameA2.c_str();
601 nvlistA[1].value <<= valueA2.c_str();
607 string nameB1 =
"nameB1";
608 string valueB1 =
"valueB1";
609 nvlistB[0].name = nameB1.c_str();
610 nvlistB[0].value <<= valueB1.c_str();
612 string nameB2 =
"nameB2";
613 string valueB2 =
"valueB2";
614 nvlistB[1].name = nameB2.c_str();
615 nvlistB[1].value <<= valueB2.c_str();
621 CPPUNIT_ASSERT_EQUAL(valueA1,
toString(nvlistA, nameA1.c_str()));
622 CPPUNIT_ASSERT_EQUAL(valueA2,
toString(nvlistA, nameA2.c_str()));
623 CPPUNIT_ASSERT_EQUAL(valueB1,
toString(nvlistA, nameB1.c_str()));
624 CPPUNIT_ASSERT_EQUAL(valueB2,
toString(nvlistA, nameB2.c_str()));
631 string nameC1 =
"nameC1";
632 string valueC1 =
"valueC1";
633 nvlistC[0].name = nameC1.c_str();
634 nvlistC[0].value <<= valueC1.c_str();
636 string nameC2 =
"nameC2";
637 string valueC2 =
"valueC2";
638 nvlistC[1].name = nameC2.c_str();
639 nvlistC[1].value <<= valueC2.c_str();
641 string nameC3 =
"name_hoge";
642 string valueC3 =
"value_hoge";
643 nvlistC[2].name = nameC3.c_str();
644 nvlistC[2].value <<= valueC3.c_str();
656 string nameD1 =
"nameD1";
657 string valueD1 =
"valueD1";
658 nvlistD[0].name = nameD1.c_str();
659 nvlistD[0].value <<= valueD1.c_str();
661 string nameD2 =
"nameD2";
662 string valueD2 =
"valueD2";
663 nvlistD[1].name = nameD2.c_str();
664 nvlistD[1].value <<= valueD2.c_str();
666 string strD =
"\n\nnameD1: valueD1\nnameD2: valueD2";
673 string nameE1 =
"short";
674 CORBA::Short valueE1 = 1;
675 nvlistE[0].name = nameE1.c_str();
676 nvlistE[0].value <<= valueE1;
679 string nameE2 =
"string";
680 string valueE2 =
"test";
681 nvlistE[1].name = nameE2.c_str();
682 nvlistE[1].value <<= valueE2.c_str();
686 std::string empty =
"short: not a string value\nstring: test\n";
687 std::string str_nvlistE =
toString(nvlistE);
698 CPPUNIT_ASSERT(
toString(nvlistE) == empty);
711 int main(
int argc,
char* argv[])
724 std::string arg(argv[i]);
725 std::string next_arg;
726 if (i + 1 < argc) next_arg = argv[i + 1];
729 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
742 ofs.open(fname.c_str());
744 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
745 if ( arg ==
"--cerr" ) { target = 1;
break; }
746 if ( arg ==
"--xsl" )
748 if (next_arg ==
"") xsl =
"default.xsl";
751 if ( arg ==
"--namespace" )
755 std::cerr <<
"no namespace specified" << std::endl;
765 CppUnit::TextUi::TestRunner runner;
767 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
769 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
770 CppUnit::Outputter* outputter = 0;
771 std::ostream* stream = target ? &std::cerr : &std::cout;
775 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
778 std::cout <<
"XML_OUT" << std::endl;
779 outputter =
new CppUnit::XmlOutputter(&runner.result(),
781 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
784 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
787 runner.setOutputter(outputter);
SDOPackage::NameValue newNV(const char *name, Value value)
Create NameValue.
int main(int argc, char **argv)
void test_newNV_Float()
newNV(char*,Value)のテスト
void test_copyToProperties()
copyToProperties()のテスト
void test_newNVOctet()
newNVOctet()のテスト
void test_append()
append()のテスト
bool isString(const SDOPackage::NVList &nv, const char *name)
Validate whether value type specified by name is string type.
void test_newNV_Long()
newNV(char*,Value)のテスト
void test_newNVBool()
newNVBool()のテスト
SDOPackage::NameValue newNVOctet(const char *name, const CORBA::Octet value)
Create NameValue typed CORBA::Octet.
bool appendStringValue(SDOPackage::NVList &nv, const char *name, const char *value)
Append the specified string to element of NVList.
std::vector< std::pair< std::string, std::string > > NVList
void test_appendStringValue()
appendStringValue()のテスト
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void test_find()
find()のテスト
SDOPackage::NameValue newNVBool(const char *name, const CORBA::Boolean value)
This operation creates NameValue typed CORBA::Boolean.
void test_find_index()
find_index()のテスト
void test_copy()
copy()のテスト
void test_newNV_Double()
newNV(char*,Value)のテスト
CPPUNIT_TEST_SUITE_REGISTRATION(NVUtil::NVUtilTests)
void test_newNV_Short()
newNV(char*,Value)のテスト
const CORBA::Long find_index(const SDOPackage::NVList &nv, const char *name)
Return the index of element specified by name from NVList.
void test_toProperties()
toProperties()のテスト
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
void test_isString()
isString()のテスト
void copyToProperties(coil::Properties &prop, const SDOPackage::NVList &nv)
Copy NVList to the Proeprties.
std::string toString(const SDOPackage::NVList &nv, const char *name)
Get NVList of specifid name as string.
const CORBA::Any & find(const SDOPackage::NVList &nv, const char *name)
Return the value specified by name from NVList.
void test_newNVChar()
newNVChar()のテスト
NameValue and NVList utility functions.
void test_newNV_Str()
newNV(const char*, const char*)のテスト
void dump(const SDOPackage::NVList &nv)
Print information configured in NVList as a string type to Standard Outport.
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
prop
Organization::get_organization_property ();.
coil::Properties toProperties(const SDOPackage::NVList &nv)
Transform NVList to the properties.
Class represents a set of properties.
SDOPackage::NameValue newNVChar(const char *name, const CORBA::Char value)
Create NameValue typed CORBA::Char.
bool isStringValue(const SDOPackage::NVList &nv, const char *name, const char *value)
Check whether the value of specified name specified matches the specified string. ...
void copyFromProperties(SDOPackage::NVList &nv, const coil::Properties &prop)
Copy the properties to NVList.
void test_toString()
toString()のテスト
void test_isStringValue()
isStringValue()のテスト