| 196 | } |
| 197 | |
| 198 | void test_priority() |
| 199 | { |
| 200 | options_description desc; |
| 201 | desc.add_options() |
| 202 | // Value of this option will be specified in two sources, |
| 203 | // and only first one should be used. |
| 204 | ("first", value<vector<int>>()) |
| 205 | // Value of this option will have default value in the first source, |
| 206 | // and explicit assignment in the second, so the second should be used. |
| 207 | ("second", value<vector<int>>()->default_value(vector<int>(1, 1), ""))( |
| 208 | "aux", value<vector<int>>()) |
| 209 | // This will have values in both sources, and values should be combined |
| 210 | ("include", value<vector<int>>()->composing()); |
| 211 | |
| 212 | const char* cmdline1_[] = { |
| 213 | "--first=1", "--aux=10", "--first=3", "--include=1"}; |
| 214 | vector<string> cmdline1 = |
| 215 | sv(cmdline1_, sizeof(cmdline1_) / sizeof(const char*)); |
| 216 | |
| 217 | parsed_options p1 = command_line_parser(cmdline1).options(desc).run(); |
| 218 | |
| 219 | const char* cmdline2_[] = {"--first=12", "--second=7", "--include=7"}; |
| 220 | vector<string> cmdline2 = |
| 221 | sv(cmdline2_, sizeof(cmdline2_) / sizeof(const char*)); |
| 222 | |
| 223 | parsed_options p2 = command_line_parser(cmdline2).options(desc).run(); |
| 224 | |
| 225 | variables_map vm; |
| 226 | store(p1, vm); |
| 227 | |
| 228 | HPX_TEST_EQ(vm.count("first"), std::size_t(1)); |
| 229 | HPX_TEST_EQ(vm["first"].as<vector<int>>().size(), std::size_t(2)); |
| 230 | HPX_TEST_EQ(vm["first"].as<vector<int>>()[0], 1); |
| 231 | HPX_TEST_EQ(vm["first"].as<vector<int>>()[1], 3); |
| 232 | |
| 233 | HPX_TEST_EQ(vm.count("second"), std::size_t(1)); |
| 234 | HPX_TEST_EQ(vm["second"].as<vector<int>>().size(), std::size_t(1)); |
| 235 | HPX_TEST_EQ(vm["second"].as<vector<int>>()[0], 1); |
| 236 | |
| 237 | store(p2, vm); |
| 238 | |
| 239 | // Value should not change. |
| 240 | HPX_TEST_EQ(vm.count("first"), std::size_t(1)); |
| 241 | HPX_TEST_EQ(vm["first"].as<vector<int>>().size(), std::size_t(2)); |
| 242 | HPX_TEST_EQ(vm["first"].as<vector<int>>()[0], 1); |
| 243 | HPX_TEST_EQ(vm["first"].as<vector<int>>()[1], 3); |
| 244 | |
| 245 | // Value should change to 7 |
| 246 | HPX_TEST_EQ(vm.count("second"), std::size_t(1)); |
| 247 | HPX_TEST_EQ(vm["second"].as<vector<int>>().size(), std::size_t(1)); |
| 248 | HPX_TEST_EQ(vm["second"].as<vector<int>>()[0], 7); |
| 249 | |
| 250 | HPX_TEST_EQ(vm.count("include"), std::size_t(1)); |
| 251 | HPX_TEST_EQ(vm["include"].as<vector<int>>().size(), std::size_t(2)); |
| 252 | HPX_TEST_EQ(vm["include"].as<vector<int>>()[0], 1); |
| 253 | HPX_TEST_EQ(vm["include"].as<vector<int>>()[1], 7); |
| 254 | } |
| 255 |
no test coverage detected