00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #include <icl_core_config/Config.h>
00024
00025 #include <iterator>
00026 #include <vector>
00027 #include <boost/assign/list_of.hpp>
00028 #include <boost/test/unit_test.hpp>
00029
00030 namespace icc = icl_core::config;
00031 namespace icl = icl_core::logging;
00032
00033 enum EnumValue
00034 {
00035 ONE,
00036 TWO,
00037 THREE
00038 };
00039
00040 std::vector<std::string> enum_value_description =
00041 boost::assign::list_of<std::string>("ONE")("TWO")("THREE");
00042
00043 char const * enum_value_char_description[] = {"ONE", "TWO", "THREE", NULL};
00044
00045 struct ConfigListEntry
00046 {
00047 std::string string_value;
00048 EnumValue enum_value;
00049 struct Foo
00050 {
00051 uint32_t uint32_value;
00052 EnumValue enum_value;
00053 struct Bar {
00054 double double_value;
00055 EnumValue enum_value;
00056 } bar;
00057 } foo;
00058 };
00059
00060 BOOST_AUTO_TEST_SUITE(ts_BatchGet)
00061
00062 #ifdef ICL_CORE_CONFIG_HAS_ENHANCED_CONFIG_MACROS
00063
00064 BOOST_AUTO_TEST_CASE(ConfigValue)
00065 {
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 icc::setValue("/ConfigValue/StringEntry", "string-value");
00076 icc::setValue("/ConfigValue/UInt32Entry", "12345");
00077 icc::setValue("/ConfigValue/DoubleEntry", "1.2345");
00078
00079 std::string string_value = "";
00080 uint32_t uint32_value = 0;
00081 double double_value = 0.;
00082 bool read_success =
00083 icc::get(CONFIG_VALUES(CONFIG_VALUE("/ConfigValue/StringEntry", string_value)
00084 CONFIG_VALUE("/ConfigValue/UInt32Entry", uint32_value)
00085 CONFIG_VALUE("/ConfigValue/DoubleEntry", double_value)),
00086 icl::Nirwana::instance());
00087 BOOST_CHECK(read_success);
00088
00089 BOOST_CHECK_EQUAL(string_value, "string-value");
00090 BOOST_CHECK_EQUAL(uint32_value, uint32_t(12345));
00091 BOOST_CHECK_EQUAL(double_value, double(1.2345));
00092 }
00093
00094 BOOST_AUTO_TEST_CASE(ConfigValueDefault)
00095 {
00096
00097
00098
00099
00100
00101
00102
00103 icc::setValue("/ConfigValueDefault/StringEntry", "string-value");
00104
00105 std::string string_value = "";
00106 uint32_t uint32_value = 0;
00107 bool read_success =
00108 icc::get(CONFIG_VALUES(
00109 CONFIG_VALUE_DEFAULT("/ConfigValueDefault/StringEntry", string_value, "other-string-value")
00110 CONFIG_VALUE_DEFAULT("/ConfigValue/UInt32Entry", uint32_value, 12345)),
00111 icl::Nirwana::instance());
00112 BOOST_CHECK(read_success);
00113
00114 BOOST_CHECK_EQUAL(string_value, "string-value");
00115 BOOST_CHECK_EQUAL(uint32_value, uint32_t(12345));
00116 }
00117
00118 BOOST_AUTO_TEST_CASE(ConfigEnum)
00119 {
00120
00121
00122
00123
00124
00125
00126
00127
00128 icc::setValue("/ConfigEnum/Entry1", "ONE");
00129 icc::setValue("/ConfigEnum/Entry2", "TWO");
00130
00131 EnumValue value1 = THREE;
00132 EnumValue value2 = THREE;
00133 bool read_success =
00134 icc::get(CONFIG_VALUES(CONFIG_ENUM("/ConfigEnum/Entry1", value1, enum_value_char_description)
00135 CONFIG_ENUM("/ConfigEnum/Entry2", value2, enum_value_char_description)),
00136 icl::Nirwana::instance());
00137 BOOST_CHECK(read_success);
00138
00139 BOOST_CHECK_EQUAL(value1, ONE);
00140 BOOST_CHECK_EQUAL(value2, TWO);
00141 }
00142
00143 BOOST_AUTO_TEST_CASE(ConfigEnumDefault)
00144 {
00145
00146
00147
00148
00149
00150
00151
00152 icc::setValue("/ConfigEnumDefault/Entry1", "ONE");
00153
00154 EnumValue value1 = THREE;
00155 EnumValue value2 = THREE;
00156 bool read_success =
00157 icc::get(CONFIG_VALUES(
00158 CONFIG_ENUM_DEFAULT("/ConfigEnumDefault/Entry1", value1, TWO, enum_value_char_description)
00159 CONFIG_ENUM_DEFAULT("/ConfigEnumDefault/Entry2", value2, TWO, enum_value_char_description)),
00160 icl::Nirwana::instance());
00161 BOOST_CHECK(read_success);
00162
00163 BOOST_CHECK_EQUAL(value1, ONE);
00164 BOOST_CHECK_EQUAL(value2, TWO);
00165 }
00166
00167 BOOST_AUTO_TEST_CASE(ConfigPrefix)
00168 {
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 icc::setValue("/ConfigPrefix/StringEntry", "string-value");
00180 icc::setValue("/ConfigPrefix/UInt32Entry", "12345");
00181 icc::setValue("/ConfigPrefix/DoubleEntry", "1.2345");
00182 icc::setValue("/ConfigPrefix/EnumEntry", "TWO");
00183
00184 std::string string_value = "";
00185 uint32_t uint32_value = 0;
00186 double double_value = 0.;
00187 EnumValue enum_value = ONE;
00188 bool read_success =
00189 icc::get("/ConfigPrefix",
00190 CONFIG_VALUES(CONFIG_VALUE("StringEntry", string_value)
00191 CONFIG_VALUE("UInt32Entry", uint32_value)
00192 CONFIG_VALUE("DoubleEntry", double_value)
00193 CONFIG_ENUM ("EnumEntry", enum_value, enum_value_char_description)),
00194 icl::Nirwana::instance());
00195 BOOST_CHECK(read_success);
00196
00197 BOOST_CHECK_EQUAL(string_value, "string-value");
00198 BOOST_CHECK_EQUAL(uint32_value, uint32_t(12345));
00199 BOOST_CHECK_EQUAL(double_value, double(1.2345));
00200 BOOST_CHECK_EQUAL(enum_value, TWO);
00201 }
00202
00203 BOOST_AUTO_TEST_CASE(ConfigList)
00204 {
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 icc::setValue("/ConfigList/List/Entry1/StringEntry", "string-value-1");
00250 icc::setValue("/ConfigList/List/Entry1/EnumEntry", "ONE");
00251 icc::setValue("/ConfigList/List/Entry1/Foo/UInt32Entry", "1");
00252 icc::setValue("/ConfigList/List/Entry1/Foo/EnumEntry", "ONE");
00253 icc::setValue("/ConfigList/List/Entry1/Foo/Bar/DoubleEntry", "0.1");
00254 icc::setValue("/ConfigList/List/Entry1/Foo/Bar/EnumEntry", "ONE");
00255 icc::setValue("/ConfigList/List/Entry2/StringEntry", "string-value-2");
00256 icc::setValue("/ConfigList/List/Entry2/EnumEntry", "TWO");
00257 icc::setValue("/ConfigList/List/Entry2/Foo/UInt32Entry", "2");
00258 icc::setValue("/ConfigList/List/Entry2/Foo/EnumEntry", "TWO");
00259 icc::setValue("/ConfigList/List/Entry2/Foo/Bar/DoubleEntry", "0.2");
00260 icc::setValue("/ConfigList/List/Entry2/Foo/Bar/EnumEntry", "TWO");
00261 icc::setValue("/ConfigList/List/Entry3/StringEntry", "string-value-3");
00262 icc::setValue("/ConfigList/List/Entry3/EnumEntry", "THREE");
00263 icc::setValue("/ConfigList/List/Entry3/Foo/UInt32Entry", "3");
00264 icc::setValue("/ConfigList/List/Entry3/Foo/EnumEntry", "THREE");
00265 icc::setValue("/ConfigList/List/Entry3/Foo/Bar/DoubleEntry", "0.3");
00266 icc::setValue("/ConfigList/List/Entry3/Foo/Bar/EnumEntry", "THREE");
00267
00268
00269
00270 std::vector<ConfigListEntry> config_list;
00271 bool read_successful =
00272 icc::get(CONFIG_VALUES(
00273 CONFIG_LIST(
00274 ConfigListEntry, "/ConfigList/List",
00275 MEMBER_MAPPING(
00276 ConfigListEntry,
00277 MEMBER_VALUE_1("StringEntry", ConfigListEntry, string_value)
00278 MEMBER_VALUE_2("Foo/UInt32Entry", ConfigListEntry, foo, uint32_value)
00279 MEMBER_VALUE_3("Foo/Bar/DoubleEntry", ConfigListEntry, foo, bar, double_value)
00280 MEMBER_ENUM_1 ("EnumEntry", ConfigListEntry, enum_value, enum_value_description)
00281 MEMBER_ENUM_2 ("Foo/EnumEntry", ConfigListEntry, foo, enum_value, enum_value_description)
00282 MEMBER_ENUM_3 ("Foo/Bar/EnumEntry", ConfigListEntry, foo, bar, enum_value,
00283
00284 enum_value_char_description)),
00285 std::back_inserter(config_list))),
00286 icl::Nirwana::instance());
00287 BOOST_CHECK(read_successful);
00288
00289 BOOST_CHECK_EQUAL(config_list.size(), 3u);
00290
00291 BOOST_CHECK_EQUAL(config_list[0].string_value, "string-value-1");
00292 BOOST_CHECK_EQUAL(config_list[0].foo.uint32_value, 1u);
00293 BOOST_CHECK_EQUAL(config_list[0].foo.bar.double_value, 0.1);
00294 BOOST_CHECK_EQUAL(config_list[0].enum_value, ONE);
00295 BOOST_CHECK_EQUAL(config_list[0].foo.enum_value, ONE);
00296 BOOST_CHECK_EQUAL(config_list[0].foo.bar.enum_value, ONE);
00297
00298 BOOST_CHECK_EQUAL(config_list[1].string_value, "string-value-2");
00299 BOOST_CHECK_EQUAL(config_list[1].foo.uint32_value, 2u);
00300 BOOST_CHECK_EQUAL(config_list[1].foo.bar.double_value, 0.2);
00301 BOOST_CHECK_EQUAL(config_list[1].enum_value, TWO);
00302 BOOST_CHECK_EQUAL(config_list[1].foo.enum_value, TWO);
00303 BOOST_CHECK_EQUAL(config_list[1].foo.bar.enum_value, TWO);
00304
00305 BOOST_CHECK_EQUAL(config_list[2].string_value, "string-value-3");
00306 BOOST_CHECK_EQUAL(config_list[2].foo.uint32_value, 3u);
00307 BOOST_CHECK_EQUAL(config_list[2].foo.bar.double_value, 0.3);
00308 BOOST_CHECK_EQUAL(config_list[2].enum_value, THREE);
00309 BOOST_CHECK_EQUAL(config_list[2].foo.enum_value, THREE);
00310 BOOST_CHECK_EQUAL(config_list[2].foo.bar.enum_value, THREE);
00311 }
00312
00313 #else
00314 # if defined(_MSC_VER)
00315 # pragma message("The icl_core_config batch convenience macros are only available in Visual Studio 2010 and newer.")
00316 # endif
00317 #endif
00318
00319 BOOST_AUTO_TEST_SUITE_END()