00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef Properties_cpp
00034 #define Properties_cpp
00035
00036 #include <cppunit/ui/text/TestRunner.h>
00037 #include <cppunit/TextOutputter.h>
00038 #include <cppunit/extensions/TestFactoryRegistry.h>
00039 #include <cppunit/extensions/HelperMacros.h>
00040 #include <cppunit/TestAssert.h>
00041 #include <fstream>
00042 #include <coil/Properties.h>
00043 #include <algorithm>
00044
00049 using namespace std;
00050
00051 typedef std::map<std::string, std::string>::iterator Itr;
00052
00053 namespace Properties
00054 {
00055 class PropertiesTests
00056 : public CppUnit::TestFixture
00057 {
00058 CPPUNIT_TEST_SUITE(PropertiesTests);
00059
00060 CPPUNIT_TEST(test_ctor_map);
00061 CPPUNIT_TEST(test_Properties_key_value);
00062 CPPUNIT_TEST(test_Properties_char);
00063 CPPUNIT_TEST(test_Properties_copy);
00064 CPPUNIT_TEST(test_Properties_destructor);
00065 CPPUNIT_TEST(test_substitute);
00066 CPPUNIT_TEST(test_Properties_destructor);
00067
00068 CPPUNIT_TEST(test_getName);
00069 CPPUNIT_TEST(test_getValue);
00070 CPPUNIT_TEST(test_getDefaultValue);
00071 CPPUNIT_TEST(test_getLeaf);
00072 CPPUNIT_TEST(test_getRoot);
00073
00074 CPPUNIT_TEST(test_getProperty);
00075 CPPUNIT_TEST(test_getDefault);
00076 CPPUNIT_TEST(test_setProperty);
00077 CPPUNIT_TEST(test_setDefaults);
00078
00079 CPPUNIT_TEST(test_list);
00080 CPPUNIT_TEST(test_load);
00081 CPPUNIT_TEST(test_store);
00082
00083 CPPUNIT_TEST(test_propertyNames);
00084 CPPUNIT_TEST(test_size);
00085 CPPUNIT_TEST(test_findNode);
00086 CPPUNIT_TEST(test_getNode);
00087 CPPUNIT_TEST(test_createNode);
00088 CPPUNIT_TEST(test_removeNode);
00089 CPPUNIT_TEST(test_hasKey);
00090 CPPUNIT_TEST(test_clear);
00091 CPPUNIT_TEST(test_streamInput);
00092 CPPUNIT_TEST(test_splitKeyValue);
00093
00094
00095
00096 CPPUNIT_TEST_SUITE_END();
00097
00098 private:
00099 string EMPTY_STRING;
00100 map<string, string> DEFAULTS_CONF;
00101
00102
00103 coil::Properties* m_prop;
00104
00105 public:
00109 PropertiesTests()
00110 {
00111 }
00112
00116 ~PropertiesTests()
00117 {
00118 }
00119
00123 virtual void setUp()
00124 {
00125 EMPTY_STRING = "";
00126
00127 DEFAULTS_CONF["rtc.openrtm.version"] = "0.4.0";
00128 DEFAULTS_CONF["rtc.openrtm.release"] = "aist";
00129 DEFAULTS_CONF["rtc.openrtm.vendor"] = "AIST";
00130 DEFAULTS_CONF["rtc.openrtm.author"] = "Noriaki Ando";
00131 DEFAULTS_CONF["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00132 DEFAULTS_CONF["rtc.manager.debug.level"] = "PARANOID";
00133 DEFAULTS_CONF["rtc.manager.orb"] = "omniORB";
00134 DEFAULTS_CONF["rtc.manager.orb.options"] =
00135 "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00136 DEFAULTS_CONF["rtc.manager.arch"] = "i386";
00137 DEFAULTS_CONF["rtc.manager.os"] = "FreeBSD";
00138 DEFAULTS_CONF["rtc.manager.os.release"] = "6.1-RELEASE";
00139 DEFAULTS_CONF["rtc.manager.language"] = "C++";
00140 DEFAULTS_CONF["rtc.manager.subsystems"] =
00141 "Camera, Manipulator, Force Sensor";
00142 DEFAULTS_CONF["rtc.component.conf.path"] =
00143 "C:\\\\Program\\\\ Files\\\\OpenRTM-aist";
00144 DEFAULTS_CONF["rtc.manager.opening_message"] = "\"Hello \" World\"";
00145 }
00146
00150 virtual void tearDown()
00151 {
00152 }
00153
00154
00162 void test_Properties_key_value()
00163 {
00164
00165 string value("test");
00166
00167
00168
00169
00170
00171 string key0("manager");
00172 coil::Properties prop0(key0.c_str(),value.c_str());
00173 string retkey(prop0.getName());
00174 CPPUNIT_ASSERT_EQUAL(key0, retkey);
00175 string retval(prop0.getValue());
00176 CPPUNIT_ASSERT_EQUAL(value, retval);
00177
00178
00179
00180
00181
00182 string key1("manager.test.test");
00183 coil::Properties prop1(key1.c_str(),value.c_str());
00184
00185 retkey = prop1.getName();
00186 CPPUNIT_ASSERT_EQUAL(key1, retkey);
00187 retval = prop1.getValue();
00188 CPPUNIT_ASSERT_EQUAL(value, retval);
00189 }
00190
00199 void test_ctor_map()
00200 {
00201 map<string, string> defaults;
00202 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00203 defaults["rtc.manager.arch"] = "i386";
00204 defaults["rtc.manager.debug.level"] = "PARANOID";
00205 defaults["rtc.manager.language"] = "C++";
00206 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00207 defaults["rtc.manager.opening_message"] = "Hello World";
00208 defaults["rtc.manager.orb.name"] = "omniORB";
00209 defaults["rtc.manager.orb.options"] =
00210 "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00211 defaults["rtc.manager.os.name"] = "FreeBSD";
00212 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00213 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00214 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00215 defaults["rtc.openrtm.release"] = "aist";
00216 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00217 defaults["rtc.openrtm.version"] = "0.4.0";
00218
00219
00220 coil::Properties prop(defaults);
00221
00222
00223
00224 map<string, string>::iterator it;
00225 it = defaults.begin();
00226 for (; it != defaults.end(); ++it) {
00227 string key = it->first;
00228 string value = it->second;
00229 CPPUNIT_ASSERT_EQUAL(value, prop.getDefault(key));
00230 CPPUNIT_ASSERT_EQUAL(value, prop.getProperty(key));
00231 }
00232 }
00233
00234
00235 void test_Properties_char()
00236 {
00237 const char* defaults[] = {
00238 "rtc.component.conf.path", "C:\\Program\\ Files\\OpenRTM-aist",
00239 "rtc.manager.arch", "i386",
00240 "rtc.manager.debug.level", "PARANOID",
00241 "rtc.manager.language", "C++",
00242 "rtc.manager.nameserver", "zonu.a02.aist.go.jp",
00243 "rtc.manager.opening_message", "Hello World",
00244 "rtc.manager.orb.name", "omniORB",
00245 "rtc.manager.orb.options", "IIOPAddrPort, -ORBendPoint, giop:tcp:",
00246 "rtc.manager.os.name", "FreeBSD",
00247 "rtc.manager.os.release", "6.1-RELEASE",
00248 "rtc.manager.subsystems", "Camera, Manipulator, Force Sensor",
00249 "rtc.openrtm.author", "Noriaki Ando",
00250 "rtc.openrtm.release", "aist",
00251 "rtc.openrtm.vendor", "AIST TaskIntelligence",
00252 "rtc.openrtm.version", "0.4.0",
00253 ""
00254 };
00255
00256 coil::Properties prop(defaults);
00257
00258
00259
00260 for (int i = 0; defaults[i] != ""; i += 2) {
00261 string key = defaults[i];
00262 string value = defaults[i + 1];
00263 CPPUNIT_ASSERT_EQUAL(value, prop.getDefault(key));
00264 CPPUNIT_ASSERT_EQUAL(value, prop.getProperty(key));
00265 }
00266 }
00267
00275 void test_Properties_copy()
00276 {
00277 map<string, string> defaults;
00278 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00279 defaults["rtc.manager.arch"] = "i386";
00280 defaults["rtc.manager.debug.level"] = "PARANOID";
00281 defaults["rtc.manager.language"] = "C++";
00282 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00283 defaults["rtc.manager.opening_message"] = "Hello World";
00284 defaults["rtc.manager.orb.name"] = "omniORB";
00285 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00286 defaults["rtc.manager.os.name"] = "FreeBSD";
00287 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00288 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00289 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00290 defaults["rtc.openrtm.release"] = "aist";
00291 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00292 defaults["rtc.openrtm.version"] = "0.4.0";
00293
00294
00295 coil::Properties prop(defaults);
00296 coil::Properties cprop(prop);
00297
00298
00299
00300 for (map<string, string>::iterator it = defaults.begin(); it != defaults.end(); it++) {
00301 string key = it->first;
00302 string value = it->second;
00303 CPPUNIT_ASSERT_EQUAL(value, cprop.getDefault(key));
00304 CPPUNIT_ASSERT_EQUAL(value, cprop.getProperty(key));
00305 }
00306 }
00307
00308
00316 void test_Properties_destructor()
00317 {
00318 map<string, string> defaults;
00319 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00320 defaults["rtc.manager.arch"] = "i386";
00321 defaults["rtc.manager.debug.level"] = "PARANOID";
00322 defaults["rtc.manager.language"] = "C++";
00323 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00324 defaults["rtc.manager.opening_message"] = "Hello World";
00325 defaults["rtc.manager.orb.name"] = "omniORB";
00326 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00327 defaults["rtc.manager.os.name"] = "FreeBSD";
00328 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00329 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00330 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00331 defaults["rtc.openrtm.release"] = "aist";
00332 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00333 defaults["rtc.openrtm.version"] = "0.4.0";
00334
00335
00336 coil::Properties prop(defaults);
00337 std::vector<coil::Properties*> leaf0(prop.getNode("rtc").getLeaf());
00338 CPPUNIT_ASSERT(leaf0.size() == 3);
00339
00340
00341 delete &prop.getNode("rtc.manager");
00342
00343
00344 std::vector<coil::Properties*> leaf1(prop.getNode("rtc").getLeaf());
00345 CPPUNIT_ASSERT(leaf1.size() == 2);
00346 std::string getval(prop.getNode("rtc.manager").getValue());
00347 CPPUNIT_ASSERT("" == getval);
00348 }
00349
00362 void test_substitute()
00363 {
00364
00365 coil::Properties propSrc;
00366
00367
00368 string key1 = "key1";
00369 string key1DefaultValue = "key1-default-value";
00370 string key1Value = "key1-value";
00371 propSrc.setDefault(key1, key1DefaultValue);
00372 propSrc.setProperty(key1, key1Value);
00373
00374
00375 string key2 = "key2";
00376 string key2DefaultValue = "key2-default-value";
00377 propSrc.setDefault(key2, key2DefaultValue);
00378
00379
00380 string key3 = "key3";
00381 string key3Value = "key3-value";
00382 propSrc.setProperty(key3, key3Value);
00383
00384
00385 coil::Properties prop;
00386 prop = propSrc;
00387
00388 CPPUNIT_ASSERT_EQUAL(key1DefaultValue, prop.getDefault(key1));
00389 CPPUNIT_ASSERT_EQUAL(key1Value, prop.getProperty(key1));
00390 CPPUNIT_ASSERT_EQUAL(key2DefaultValue, prop.getDefault(key2));
00391 CPPUNIT_ASSERT_EQUAL(key2DefaultValue, prop.getProperty(key2));
00392 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, prop.getDefault(key3));
00393 CPPUNIT_ASSERT_EQUAL(key3Value, prop.getProperty(key3));
00394 }
00395
00396
00411 void test_getProperty()
00412 {
00413 coil::Properties prop;
00414
00415 prop.setDefault("property_1", "default_1");
00416 prop.setProperty("property_1", "value_1");
00417 prop.setDefault("property_2", "default_2");
00418 prop.setProperty("property_3", "value_3");
00419
00420
00421
00422 string expected_1 = "value_1";
00423 CPPUNIT_ASSERT_EQUAL(expected_1, prop.getProperty("property_1"));
00424
00425
00426
00427 string expected_2 = "default_2";
00428 CPPUNIT_ASSERT_EQUAL(expected_2, prop.getProperty("property_2"));
00429
00430
00431
00432 string expected_3 = "value_3";
00433 CPPUNIT_ASSERT_EQUAL(expected_3, prop.getProperty("property_3"));
00434
00435
00436
00437 string expected_4 = "";
00438 CPPUNIT_ASSERT_EQUAL(expected_4, prop.getProperty("property_4"));
00439 }
00440
00441
00461 void test_getDefault()
00462 {
00463 coil::Properties prop;
00464
00465 string key1 = "key1";
00466 string key1DefaultValue = "key1-default-value";
00467 string key1Value = "key1-value";
00468 prop.setDefault(key1, key1DefaultValue);
00469 prop.setProperty(key1, key1Value);
00470
00471 string key2 = "key2";
00472 string key2DefaultValue = "key2-default-value";
00473 prop.setDefault(key2, key2DefaultValue);
00474
00475 string key3 = "key3";
00476 string key3Value = "key3-value";
00477 prop.setProperty(key3, key3Value);
00478
00479
00480
00481 CPPUNIT_ASSERT_EQUAL(key1DefaultValue, prop.getDefault(key1));
00482
00483
00484
00485 CPPUNIT_ASSERT_EQUAL(key2DefaultValue, prop.getDefault(key2));
00486
00487
00488
00489 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, prop.getDefault(key3));
00490
00491
00492
00493 string keyNonExist = "key-non-exist";
00494 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, prop.getDefault(keyNonExist));
00495 }
00496
00505 void test_setProperty()
00506 {
00507 string key = "key";
00508 string oldValue = "old-value";
00509 string newValue = "new-value";
00510
00511 coil::Properties prop;
00512 prop.setProperty(key, oldValue);
00513
00514
00515 CPPUNIT_ASSERT_EQUAL(oldValue, prop.getProperty(key));
00516
00517
00518 CPPUNIT_ASSERT_EQUAL(oldValue, prop.setProperty(key, newValue));
00519
00520
00521 CPPUNIT_ASSERT_EQUAL(newValue, prop.getProperty(key));
00522 }
00523
00524
00537 void test_list()
00538 {
00539 coil::Properties prop;
00540 prop.setProperty("rtc.component.conf.path",
00541 "C:\\Program\\ Files\\OpenRTM-aist");
00542 prop.setProperty("rtc.manager.arch", "i386");
00543 prop.setProperty("rtc.manager.debug.level", "PARANOID");
00544 prop.setProperty("rtc.manager.language", "C++");
00545 prop.setProperty("rtc.manager.nameserver", "zonu.a02.aist.go.jp");
00546 prop.setProperty("rtc.manager.opening_message", "Hello World");
00547 prop.setProperty("rtc.manager.orb.name", "omniORB");
00548 prop.setProperty("rtc.manager.orb.options",
00549 "IIOPAddrPort, -ORBendPoint, giop:tcp:");
00550 prop.setProperty("rtc.manager.os.name", "FreeBSD");
00551 prop.setProperty("rtc.manager.os.release", "6.1-RELEASE");
00552 prop.setProperty("rtc.manager.subsystems",
00553 "Camera, Manipulator, Force Sensor");
00554 prop.setProperty("rtc.openrtm.author", "Noriaki Ando");
00555 prop.setProperty("rtc.openrtm.release", "aist");
00556 prop.setProperty("rtc.openrtm.vendor", "AIST TaskIntelligence");
00557 prop.setProperty("rtc.openrtm.version", "0.4.0");
00558
00559 std::ofstream outFile("listed.conf");
00560 prop.list(outFile);
00561 outFile.close();
00562
00563 vector<string> expectedLines;
00564 expectedLines.push_back("rtc.component.conf.path: C:\\\\Program\\\\ Files\\\\OpenRTM-aist");
00565 expectedLines.push_back("rtc.manager.arch: i386");
00566 expectedLines.push_back("rtc.manager.debug.level: PARANOID");
00567 expectedLines.push_back("rtc.manager.language: C++");
00568 expectedLines.push_back("rtc.manager.nameserver: zonu.a02.aist.go.jp");
00569 expectedLines.push_back("rtc.manager.opening_message: Hello World");
00570 expectedLines.push_back("rtc.manager.orb.name: omniORB");
00571 expectedLines.push_back("rtc.manager.orb.options: IIOPAddrPort, -ORBendPoint, giop:tcp:");
00572 expectedLines.push_back("rtc.manager.os.name: FreeBSD");
00573 expectedLines.push_back("rtc.manager.os.release: 6.1-RELEASE");
00574 expectedLines.push_back("rtc.manager.subsystems: Camera, Manipulator, Force Sensor");
00575 expectedLines.push_back("rtc.openrtm.author: Noriaki Ando");
00576 expectedLines.push_back("rtc.openrtm.release: aist");
00577 expectedLines.push_back("rtc.openrtm.vendor: AIST TaskIntelligence");
00578 expectedLines.push_back("rtc.openrtm.version: 0.4.0");
00579
00580 vector<string> storedLines;
00581 std::ifstream inFile("listed.conf");
00582 string str;
00583 while (getline(inFile, str))
00584 {
00585 storedLines.push_back(str);
00586 }
00587 inFile.close();
00588
00589
00590 sort(expectedLines.begin(), expectedLines.end());
00591 sort(storedLines.begin(), storedLines.end());
00592 CPPUNIT_ASSERT_EQUAL(expectedLines.size(), storedLines.size());
00593 for (vector<string>::size_type i = 0; i < expectedLines.size(); i++)
00594 {
00595 CPPUNIT_ASSERT_EQUAL(expectedLines[i], storedLines[i]);
00596 }
00597 }
00598
00608 void test_load()
00609 {
00610
00611 coil::Properties prop;
00612 std::ifstream ifl("defaults.conf");
00613 prop.load(ifl);
00614 ifl.close();
00615
00616
00617 map<string, string>::iterator expected;
00618 for (expected = DEFAULTS_CONF.begin();
00619 expected != DEFAULTS_CONF.end(); expected++) {
00620 string key = expected->first;
00621 string value = expected->second;
00622 CPPUNIT_ASSERT_EQUAL(value, prop.getProperty(key));
00623 }
00624 }
00625
00640 void test_store()
00641 {
00642
00643 coil::Properties prop;
00644 prop.setProperty("rtc.component.conf.path",
00645 "C:\\Program\\ Files\\OpenRTM-aist");
00646 prop.setProperty("rtc.manager.arch", "i386");
00647 prop.setProperty("rtc.manager.debug.level", "PARANOID");
00648 prop.setProperty("rtc.manager.language", "C++");
00649 prop.setProperty("rtc.manager.nameserver", "zonu.a02.aist.go.jp");
00650 prop.setProperty("rtc.manager.opening_message", "Hello World");
00651 prop.setProperty("rtc.manager.orb.name", "omniORB");
00652 prop.setProperty("rtc.manager.orb.options",
00653 "IIOPAddrPort, -ORBendPoint, giop:tcp:");
00654 prop.setProperty("rtc.manager.os.name", "FreeBSD");
00655 prop.setProperty("rtc.manager.os.release", "6.1-RELEASE");
00656 prop.setProperty("rtc.manager.subsystems",
00657 "Camera, Manipulator, Force Sensor");
00658 prop.setProperty("rtc.openrtm.author", "Noriaki Ando");
00659 prop.setProperty("rtc.openrtm.release", "aist");
00660 prop.setProperty("rtc.openrtm.vendor", "AIST TaskIntelligence");
00661 prop.setProperty("rtc.openrtm.version", "0.4.0");
00662 prop.setProperty("hello", "\tHello\t");
00663
00664 std::ofstream outFile("stored.conf");
00665 prop.store(outFile, "stored data");
00666 outFile.close();
00667
00668
00669 vector<string> expectedLines;
00670 expectedLines.push_back("# stored data");
00671 expectedLines.push_back("rtc.component.conf.path: C:\\\\Program\\\\ Files\\\\OpenRTM-aist");
00672 expectedLines.push_back("rtc.manager.arch: i386");
00673 expectedLines.push_back("rtc.manager.debug.level: PARANOID");
00674 expectedLines.push_back("rtc.manager.language: C++");
00675 expectedLines.push_back("rtc.manager.nameserver: zonu.a02.aist.go.jp");
00676 expectedLines.push_back("rtc.manager.opening_message: Hello World");
00677 expectedLines.push_back("rtc.manager.orb.name: omniORB");
00678 expectedLines.push_back("rtc.manager.orb.options: IIOPAddrPort, -ORBendPoint, giop:tcp:");
00679 expectedLines.push_back("rtc.manager.os.name: FreeBSD");
00680 expectedLines.push_back("rtc.manager.os.release: 6.1-RELEASE");
00681 expectedLines.push_back("rtc.manager.subsystems: Camera, Manipulator, Force Sensor");
00682 expectedLines.push_back("rtc.openrtm.author: Noriaki Ando");
00683 expectedLines.push_back("rtc.openrtm.release: aist");
00684 expectedLines.push_back("rtc.openrtm.vendor: AIST TaskIntelligence");
00685 expectedLines.push_back("rtc.openrtm.version: 0.4.0");
00686 expectedLines.push_back("hello: \\tHello\\t");
00687
00688
00689 vector<string> storedLines;
00690 std::ifstream inFile("stored.conf");
00691 string str;
00692 while (getline(inFile, str)) {
00693 storedLines.push_back(str);
00694 }
00695 inFile.close();
00696
00697
00698 sort(expectedLines.begin(), expectedLines.end());
00699 sort(storedLines.begin(), storedLines.end());
00700 CPPUNIT_ASSERT_EQUAL(expectedLines.size(), storedLines.size());
00701 for (vector<string>::size_type i = 0; i < expectedLines.size(); i++) {
00702 CPPUNIT_ASSERT_EQUAL(expectedLines[i], storedLines[i]);
00703 }
00704 }
00705
00706
00723 void test_propertyNames()
00724 {
00725 coil::Properties prop;
00726
00727
00728 prop.setProperty("property_01", "value_01");
00729 prop.setDefault("property_01", "default_01");
00730
00731
00732 prop.setProperty("property_02", "value_02");
00733
00734
00735 prop.setDefault("property_03", "default_03");
00736
00737
00738 vector<string> keys = prop.propertyNames();
00739 CPPUNIT_ASSERT_EQUAL(3, (int) keys.size());
00740 CPPUNIT_ASSERT(find(keys.begin(), keys.end(), "property_01")
00741 != keys.end());
00742 CPPUNIT_ASSERT(find(keys.begin(), keys.end(), "property_02")
00743 != keys.end());
00744 CPPUNIT_ASSERT(find(keys.begin(), keys.end(), "property_03")
00745 != keys.end());
00746 }
00747
00748
00756 void test_getName()
00757 {
00758
00759 string value("test");
00760
00761
00762
00763 string key0("manager");
00764 coil::Properties prop0(key0.c_str(),value.c_str());
00765 string retkey(prop0.getName());
00766 CPPUNIT_ASSERT_EQUAL(key0, retkey);
00767
00768
00769
00770 string key1("manager.hoge");
00771 coil::Properties prop1(key1.c_str(),value.c_str());
00772 retkey= prop1.getName();
00773 CPPUNIT_ASSERT_EQUAL(key1, retkey);
00774 }
00775
00783 void test_getValue()
00784 {
00785
00786 string key("manager");
00787 string value("test.test");
00788 coil::Properties prop(key.c_str(),value.c_str());
00789
00790
00791 string retval(prop.getValue());
00792 CPPUNIT_ASSERT_EQUAL(value, retval);
00793 }
00794
00802 void test_getDefaultValue()
00803 {
00804 coil::Properties prop;
00805
00806 string key("property_1");
00807 string value("default_1");
00808
00809 prop.setDefault(key.c_str(), value.c_str());
00810
00811
00812 string retval(prop.getNode(key.c_str()).getDefaultValue());
00813 CPPUNIT_ASSERT_EQUAL(value, retval);
00814 }
00815
00823 void test_getLeaf()
00824 {
00825 map<string, string> defaults;
00826 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00827 defaults["rtc.manager.arch"] = "i386";
00828 defaults["rtc.manager.debug.level"] = "PARANOID";
00829 defaults["rtc.manager.language"] = "C++";
00830 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00831 defaults["rtc.manager.opening_message"] = "Hello World";
00832 defaults["rtc.manager.orb.name"] = "omniORB";
00833 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00834 defaults["rtc.manager.os.name"] = "FreeBSD";
00835 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00836 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00837 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00838 defaults["rtc.openrtm.release"] = "aist";
00839 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00840 defaults["rtc.openrtm.version"] = "0.4.0";
00841
00842
00843 coil::Properties prop(defaults);
00844
00845
00846 std::vector<coil::Properties*> leaf(prop.getNode("rtc").getLeaf());
00847 CPPUNIT_ASSERT(leaf[1]->getProperty("arch") == "i386");
00848 CPPUNIT_ASSERT(leaf[1]->getProperty("debug.level") == "PARANOID");
00849 }
00850
00858 void test_getRoot()
00859 {
00860 map<string, string> defaults;
00861 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00862 defaults["rtc.manager.arch"] = "i386";
00863 defaults["rtc.manager.debug.level"] = "PARANOID";
00864 defaults["rtc.manager.language"] = "C++";
00865 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00866 defaults["rtc.manager.opening_message"] = "Hello World";
00867 defaults["rtc.manager.orb.name"] = "omniORB";
00868 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00869 defaults["rtc.manager.os.name"] = "FreeBSD";
00870 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00871 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00872 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00873 defaults["rtc.openrtm.release"] = "aist";
00874 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00875 defaults["rtc.openrtm.version"] = "0.4.0";
00876
00877
00878 coil::Properties prop(defaults);
00879
00880
00881 const coil::Properties* root(prop.getNode("rtc.manager.os").getRoot());
00882 CPPUNIT_ASSERT(root->getProperty("arch") == "i386");
00883 CPPUNIT_ASSERT(root->getProperty("debug.level") == "PARANOID");
00884 }
00885
00893 void test_operator()
00894 {
00895 map<string, string> defaults;
00896 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00897 defaults["rtc.manager.arch"] = "i386";
00898 defaults["rtc.manager.debug.level"] = "PARANOID";
00899 defaults["rtc.manager.language"] = "C++";
00900 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00901 defaults["rtc.manager.opening_message"] = "Hello World";
00902 defaults["rtc.manager.orb.name"] = "omniORB";
00903 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00904 defaults["rtc.manager.os.name"] = "FreeBSD";
00905 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00906 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00907 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00908 defaults["rtc.openrtm.release"] = "aist";
00909 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00910 defaults["rtc.openrtm.version"] = "0.4.0";
00911
00912
00913
00914
00915 const coil::Properties prop0(defaults);
00916 const string& retval0(prop0["rtc.manager.arch"]);
00917 CPPUNIT_ASSERT(retval0 == "i386");
00918
00919
00920
00921
00922 coil::Properties prop1(defaults);
00923 string retval1(prop1["rtc.manager.arch"]);
00924 CPPUNIT_ASSERT(retval1 == "i386");
00925
00926 }
00927
00935 void test_setDefaults()
00936 {
00937 const char* defaults[] = {
00938 "rtc.component.conf.path", "C:\\Program\\ Files\\OpenRTM-aist",
00939 "rtc.manager.arch", "i386",
00940 "rtc.manager.debug.level", "PARANOID",
00941 "rtc.manager.language", "C++",
00942 "rtc.manager.nameserver", "zonu.a02.aist.go.jp",
00943 "rtc.manager.opening_message", "Hello World",
00944 "rtc.manager.orb.name", "omniORB",
00945 "rtc.manager.orb.options", "IIOPAddrPort, -ORBendPoint, giop:tcp:",
00946 "rtc.manager.os.name", "FreeBSD",
00947 "rtc.manager.os.release", "6.1-RELEASE",
00948 "rtc.manager.subsystems", "Camera, Manipulator, Force Sensor",
00949 "rtc.openrtm.author", "Noriaki Ando",
00950 "rtc.openrtm.release", "aist",
00951 "rtc.openrtm.vendor", "AIST TaskIntelligence",
00952 "rtc.openrtm.version", "0.4.0",
00953 ""
00954 };
00955
00956 coil::Properties prop;
00957 prop.setDefaults(defaults);
00958
00959
00960
00961
00962 for (int i = 0; defaults[i] != ""; i += 2) {
00963 string key = defaults[i];
00964 string value = defaults[i + 1];
00965 CPPUNIT_ASSERT_EQUAL(value, prop.getDefault(key));
00966 }
00967 }
00968
00976 void test_size()
00977 {
00978 map<string, string> defaults;
00979 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
00980 defaults["rtc.manager.arch"] = "i386";
00981 defaults["rtc.manager.debug.level"] = "PARANOID";
00982 defaults["rtc.manager.language"] = "C++";
00983 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
00984 defaults["rtc.manager.opening_message"] = "Hello World";
00985 defaults["rtc.manager.orb.name"] = "omniORB";
00986 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
00987 defaults["rtc.manager.os.name"] = "FreeBSD";
00988 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
00989 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
00990 defaults["rtc.openrtm.author"] = "Noriaki Ando";
00991 defaults["rtc.openrtm.release"] = "aist";
00992 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
00993 defaults["rtc.openrtm.version"] = "0.4.0";
00994
00995 coil::Properties prop(defaults);
00996
00997
00998 CPPUNIT_ASSERT(15 == prop.size());
00999
01000
01001 string key = "key";
01002 string newValue = "new-value";
01003 prop.setProperty(key, newValue);
01004 CPPUNIT_ASSERT(16 == prop.size());
01005 }
01006
01014 void test_findNode()
01015 {
01016 map<string, string> defaults;
01017 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
01018 defaults["rtc.manager.arch"] = "i386";
01019 defaults["rtc.manager.debug.level"] = "PARANOID";
01020 defaults["rtc.manager.language"] = "C++";
01021 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
01022 defaults["rtc.manager.opening_message"] = "Hello World";
01023 defaults["rtc.manager.orb.name"] = "omniORB";
01024 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
01025 defaults["rtc.manager.os.name"] = "FreeBSD";
01026 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
01027 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
01028 defaults["rtc.openrtm.author"] = "Noriaki Ando";
01029 defaults["rtc.openrtm.release"] = "aist";
01030 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
01031 defaults["rtc.openrtm.version"] = "0.4.0";
01032
01033
01034 coil::Properties prop(defaults);
01035
01036
01037 CPPUNIT_ASSERT(prop.findNode("rtc.manager")->getProperty("arch") == "i386");
01038 CPPUNIT_ASSERT(prop.findNode("rtc.manager")->getProperty("debug.level") == "PARANOID");
01039 CPPUNIT_ASSERT(prop.findNode("rtc.manager") != NULL);
01040
01041
01042 CPPUNIT_ASSERT(prop.findNode("manager") == NULL);
01043 CPPUNIT_ASSERT(prop.findNode("rtc.MANAGER") == NULL);
01044 }
01045
01053 void test_getNode()
01054 {
01055 map<string, string> defaults;
01056 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
01057 defaults["rtc.manager.arch"] = "i386";
01058 defaults["rtc.manager.debug.level"] = "PARANOID";
01059 defaults["rtc.manager.language"] = "C++";
01060 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
01061 defaults["rtc.manager.opening_message"] = "Hello World";
01062 defaults["rtc.manager.orb.name"] = "omniORB";
01063 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
01064 defaults["rtc.manager.os.name"] = "FreeBSD";
01065 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
01066 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
01067 defaults["rtc.openrtm.author"] = "Noriaki Ando";
01068 defaults["rtc.openrtm.release"] = "aist";
01069 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
01070 defaults["rtc.openrtm.version"] = "0.4.0";
01071
01072
01073 coil::Properties prop(defaults);
01074
01075
01076 CPPUNIT_ASSERT(prop.getNode("rtc.manager").getProperty("arch") == "i386");
01077 CPPUNIT_ASSERT(prop.getNode("rtc.manager").getProperty("debug.level") == "PARANOID");
01078
01079
01080 std::string getval(prop.getNode("manager").getValue());
01081 CPPUNIT_ASSERT(getval == "");
01082
01083 }
01084
01092 void test_removeNode()
01093 {
01094 map<string, string> defaults;
01095 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
01096 defaults["rtc.manager.arch"] = "i386";
01097 defaults["rtc.manager.debug.level"] = "PARANOID";
01098 defaults["rtc.manager.language"] = "C++";
01099 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
01100 defaults["rtc.manager.opening_message"] = "Hello World";
01101 defaults["rtc.manager.orb.name"] = "omniORB";
01102 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
01103 defaults["rtc.manager.os.name"] = "FreeBSD";
01104 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
01105 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
01106 defaults["rtc.openrtm.author"] = "Noriaki Ando";
01107 defaults["rtc.openrtm.release"] = "aist";
01108 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
01109 defaults["rtc.openrtm.version"] = "0.4.0";
01110
01111
01112 coil::Properties prop(defaults);
01113
01114
01115 CPPUNIT_ASSERT(prop.removeNode("rtc.manager") == NULL);
01116
01117
01118 CPPUNIT_ASSERT(prop.getNode("rtc").removeNode("manager") != NULL);
01119
01120
01121 CPPUNIT_ASSERT(prop.findNode("rtc.manager") == NULL);
01122
01123
01124 std::string getval0(prop.getNode("rtc.manager").getValue());
01125 CPPUNIT_ASSERT(getval0 == "");
01126 }
01127
01135 void test_hasKey()
01136 {
01137 map<string, string> defaults;
01138 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
01139 defaults["rtc.manager.arch"] = "i386";
01140 defaults["rtc.manager.debug.level"] = "PARANOID";
01141 defaults["rtc.manager.language"] = "C++";
01142 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
01143 defaults["rtc.manager.opening_message"] = "Hello World";
01144 defaults["rtc.manager.orb.name"] = "omniORB";
01145 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
01146 defaults["rtc.manager.os.name"] = "FreeBSD";
01147 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
01148 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
01149 defaults["rtc.openrtm.author"] = "Noriaki Ando";
01150 defaults["rtc.openrtm.release"] = "aist";
01151 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
01152 defaults["rtc.openrtm.version"] = "0.4.0";
01153
01154
01155 coil::Properties prop(defaults);
01156
01157
01158 CPPUNIT_ASSERT(prop.hasKey("rtc") != NULL);
01159
01160
01161 CPPUNIT_ASSERT(prop.hasKey("hoge") == NULL);
01162
01163
01164 CPPUNIT_ASSERT(prop.getNode("rtc").hasKey("manager") != NULL);
01165
01166
01167 CPPUNIT_ASSERT(prop.getNode("rtc").hasKey("hoge") == NULL);
01168 }
01169
01177 void test_clear()
01178 {
01179 map<string, string> defaults;
01180 defaults["rtc.component.conf.path"] = "C:\\Program\\ Files\\OpenRTM-aist";
01181 defaults["rtc.manager.arch"] = "i386";
01182 defaults["rtc.manager.debug.level"] = "PARANOID";
01183 defaults["rtc.manager.language"] = "C++";
01184 defaults["rtc.manager.nameserver"] = "zonu.a02.aist.go.jp";
01185 defaults["rtc.manager.opening_message"] = "Hello World";
01186 defaults["rtc.manager.orb.name"] = "omniORB";
01187 defaults["rtc.manager.orb.options"] = "IIOPAddrPort, -ORBendPoint, giop:tcp:";
01188 defaults["rtc.manager.os.name"] = "FreeBSD";
01189 defaults["rtc.manager.os.release"] = "6.1-RELEASE";
01190 defaults["rtc.manager.subsystems"] = "Camera, Manipulator, Force Sensor";
01191 defaults["rtc.openrtm.author"] = "Noriaki Ando";
01192 defaults["rtc.openrtm.release"] = "aist";
01193 defaults["rtc.openrtm.vendor"] = "AIST TaskIntelligence";
01194 defaults["rtc.openrtm.version"] = "0.4.0";
01195
01196
01197 coil::Properties prop(defaults);
01198
01199 prop.getNode("rtc.manager.os").clear();
01200
01201
01202 CPPUNIT_ASSERT(prop.findNode("rtc.manager.os.name") == NULL);
01203 CPPUNIT_ASSERT(prop.findNode("rtc.manager.os.release") == NULL);
01204
01205
01206 CPPUNIT_ASSERT(prop.findNode("rtc.manager.arch") != NULL);
01207 CPPUNIT_ASSERT(prop.findNode("rtc.manager.orb") != NULL);
01208
01209
01210 prop.clear();
01211 CPPUNIT_ASSERT(prop.findNode("rtc.manager.os") == NULL);
01212 CPPUNIT_ASSERT(prop.findNode("rtc.manager") == NULL);
01213 CPPUNIT_ASSERT(prop.findNode("rtc.openrtm") == NULL);
01214 CPPUNIT_ASSERT(prop.findNode("rtc.component") == NULL);
01215 CPPUNIT_ASSERT(prop.findNode("rtc") == NULL);
01216 }
01217
01218
01238 void test_createNode()
01239 {
01240 coil::Properties prop;
01241
01242 string key1 = "key1";
01243 string key1DefaultValue = "key1-default-value";
01244 string key1Value = "key1-value";
01245 prop.setDefault(key1, key1DefaultValue);
01246 prop.setProperty(key1, key1Value);
01247
01248 string key2 = "key2";
01249 string key2DefaultValue = "key2-default-value";
01250 prop.setDefault(key2, key2DefaultValue);
01251
01252 string key3 = "key3";
01253 string key3Value = "key3-value";
01254 prop.setProperty(key3, key3Value);
01255
01256
01257
01258
01259
01260 CPPUNIT_ASSERT(! prop.createNode(key1.c_str()));
01261
01262
01263
01264
01265
01266 CPPUNIT_ASSERT(! prop.createNode(key2.c_str()));
01267
01268
01269
01270
01271
01272 CPPUNIT_ASSERT(! prop.createNode(key3.c_str()));
01273
01274
01275
01276
01277
01278 string keyNonExist = "key-non-exist";
01279 CPPUNIT_ASSERT(prop.createNode(keyNonExist.c_str()));
01280 }
01281
01282
01298 void test_streamInput()
01299 {
01300
01301 coil::Properties propA;
01302
01303 string keyA1 = "keyA1";
01304 string keyA1DefaultValue = "keyA1-default-value";
01305 string keyA1Value = "keyA1-value";
01306 propA.setDefault(keyA1, keyA1DefaultValue);
01307 propA.setProperty(keyA1, keyA1Value);
01308
01309 string keyA2 = "keyA2";
01310 string keyA2DefaultValue = "keyA2-default-value";
01311 propA.setDefault(keyA2, keyA2DefaultValue);
01312
01313 string keyA3 = "keyA3";
01314 string keyA3Value = "keyA3-value";
01315 propA.setProperty(keyA3, keyA3Value);
01316
01317
01318 coil::Properties propB;
01319
01320 string keyB1 = "keyB1";
01321 string keyB1DefaultValue = "keyB1-default-value";
01322 string keyB1Value = "keyB1-value";
01323 propB.setDefault(keyB1, keyB1DefaultValue);
01324 propB.setProperty(keyB1, keyB1Value);
01325
01326 string keyB2 = "keyB2";
01327 string keyB2DefaultValue = "keyB2-default-value";
01328 propB.setDefault(keyB2, keyB2DefaultValue);
01329
01330 string keyB3 = "keyB3";
01331 string keyB3Value = "keyB3-value";
01332 propB.setProperty(keyB3, keyB3Value);
01333
01334
01335
01336
01337 string keyCommon = "keyCommon";
01338 string keyCommonValueA = "keyCommon-value-A";
01339 string keyCommonValueB = "keyCommon-value-B";
01340 propA.setProperty(keyCommon, keyCommonValueA);
01341 propB.setProperty(keyCommon, keyCommonValueB);
01342
01343
01344 propA << propB;
01345
01346
01347
01348
01349 CPPUNIT_ASSERT_EQUAL(keyA1DefaultValue, propA.getDefault(keyA1));
01350 CPPUNIT_ASSERT_EQUAL(keyA1Value, propA.getProperty(keyA1));
01351 CPPUNIT_ASSERT_EQUAL(keyA2DefaultValue, propA.getDefault(keyA2));
01352 CPPUNIT_ASSERT_EQUAL(keyA2DefaultValue, propA.getProperty(keyA2));
01353 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, propA.getDefault(keyA3));
01354 CPPUNIT_ASSERT_EQUAL(keyA3Value, propA.getProperty(keyA3));
01355
01356
01357 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, propA.getDefault(keyB1));
01358 CPPUNIT_ASSERT_EQUAL(keyB1Value, propA.getProperty(keyB1));
01359 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, propA.getDefault(keyB2));
01360 CPPUNIT_ASSERT_EQUAL(keyB2DefaultValue, propA.getProperty(keyB2));
01361 CPPUNIT_ASSERT_EQUAL(EMPTY_STRING, propA.getDefault(keyB3));
01362 CPPUNIT_ASSERT_EQUAL(keyB3Value, propA.getProperty(keyB3));
01363
01364
01365 CPPUNIT_ASSERT_EQUAL(keyCommonValueB, propA.getProperty(keyCommon));
01366 }
01367
01387 void test_splitKeyValue()
01388 {
01389 class P : public coil::Properties
01390 {
01391 public:
01392 void splitKeyValue_protected(const std::string& str,
01393 std::string& key, std::string& value)
01394 {
01395 splitKeyValue(str, key, value);
01396 }
01397 };
01398
01399 string keyAndValue = " property_name : C:\\abc\\pqr.xyz ";
01400
01401 string key, value;
01402 P prop;
01403 prop.splitKeyValue_protected(keyAndValue, key, value);
01404
01405
01406
01407 string expectedKey("property_name");
01408 CPPUNIT_ASSERT_EQUAL(expectedKey, key);
01409
01410 string expectedValue("C:\\abc\\pqr.xyz");
01411 CPPUNIT_ASSERT_EQUAL(expectedValue, value);
01412 }
01413
01414
01415
01416 };
01417 };
01418
01419
01420
01421
01422 CPPUNIT_TEST_SUITE_REGISTRATION(Properties::PropertiesTests);
01423
01424 #ifdef LOCAL_MAIN
01425 int main(int argc, char* argv[])
01426 {
01427
01428 FORMAT format = TEXT_OUT;
01429 int target = 0;
01430 std::string xsl;
01431 std::string ns;
01432 std::string fname;
01433 std::ofstream ofs;
01434
01435 int i(1);
01436 while (i < argc)
01437 {
01438 std::string arg(argv[i]);
01439 std::string next_arg;
01440 if (i + 1 < argc) next_arg = argv[i + 1];
01441 else next_arg = "";
01442
01443 if (arg == "--text") { format = TEXT_OUT; break; }
01444 if (arg == "--xml")
01445 {
01446 if (next_arg == "")
01447 {
01448 fname = argv[0];
01449 fname += ".xml";
01450 }
01451 else
01452 {
01453 fname = next_arg;
01454 }
01455 format = XML_OUT;
01456 ofs.open(fname.c_str());
01457 }
01458 if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
01459 if ( arg == "--cerr" ) { target = 1; break; }
01460 if ( arg == "--xsl" )
01461 {
01462 if (next_arg == "") xsl = "default.xsl";
01463 else xsl = next_arg;
01464 }
01465 if ( arg == "--namespace" )
01466 {
01467 if (next_arg == "")
01468 {
01469 std::cerr << "no namespace specified" << std::endl;
01470 exit(1);
01471 }
01472 else
01473 {
01474 xsl = next_arg;
01475 }
01476 }
01477 ++i;
01478 }
01479 CppUnit::TextUi::TestRunner runner;
01480 if ( ns.empty() )
01481 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
01482 else
01483 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
01484 CppUnit::Outputter* outputter = 0;
01485 std::ostream* stream = target ? &std::cerr : &std::cout;
01486 switch ( format )
01487 {
01488 case TEXT_OUT :
01489 outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
01490 break;
01491 case XML_OUT :
01492 std::cout << "XML_OUT" << std::endl;
01493 outputter = new CppUnit::XmlOutputter(&runner.result(),
01494 ofs, "shift_jis");
01495 static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
01496 break;
01497 case COMPILER_OUT :
01498 outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
01499 break;
01500 }
01501 runner.setOutputter(outputter);
01502 runner.run();
01503 return 0;
01504 }
01505 #endif // MAIN
01506 #endif // Properties_cpp