27 bpo::options_description testOptions(
"Test options");
28 testOptions.add_options()
29 (
"aFloat", bpo::value<float>()->default_value(10.f))
30 (
"aDouble", bpo::value<double>()->default_value(20.))
31 (
"anInt", bpo::value<int>()->default_value(1))
32 (
"anInt8", bpo::value<int8_t>()->default_value(1))
33 (
"anInt16", bpo::value<int16_t>()->default_value(1))
34 (
"anUInt8", bpo::value<uint8_t>()->default_value(1))
35 (
"anUInt16", bpo::value<uint16_t>()->default_value(1))
36 (
"anUInt32", bpo::value<uint32_t>()->default_value(1))
37 (
"anUInt64", bpo::value<uint64_t>()->default_value(1))
38 (
"anInt64", bpo::value<int64_t>()->default_value(1ll))
39 (
"aBoolean", bpo::value<bool>()->zero_tokens()->default_value(
false))
40 (
"aString,s", bpo::value<std::string>()->default_value(
"something"))
41 (
"aNested.x", bpo::value<int>()->default_value(2))
42 (
"aNested.y", bpo::value<float>()->default_value(3.f));
44 fair::mq::ProgOptions* options =
new fair::mq::ProgOptions();
45 options->AddToCmdLineOptions(testOptions);
46 options->ParseAll({
"cmd",
"--aFloat",
"1.0",
55 "--anInt64",
"50000000000000",
57 "-s",
"somethingelse",
61 std::vector<ConfigParamSpec> specs{
63 ConfigParamSpec{
"anInt8", VariantType::Int8,
static_cast<int8_t
>(1), {
"an int8 option"}},
64 ConfigParamSpec{
"anInt16", VariantType::Int16,
static_cast<int16_t
>(1), {
"an int16 option"}},
65 ConfigParamSpec{
"anUInt8", VariantType::UInt8,
static_cast<uint8_t
>(1u), {
"an int option"}},
66 ConfigParamSpec{
"anUInt16", VariantType::UInt16,
static_cast<uint16_t
>(1u), {
"an int option"}},
67 ConfigParamSpec{
"anUInt32", VariantType::UInt32, 1u, {
"an int option"}},
68 ConfigParamSpec{
"anUInt64", VariantType::UInt64,
static_cast<uint64_t
>(1ul), {
"an int option"}},
69 ConfigParamSpec{
"anInt64", VariantType::Int64, 1ll, {
"an int64_t option"}},
70 ConfigParamSpec{
"aFloat", VariantType::Float, 2.0f, {
"a float option"}},
71 ConfigParamSpec{
"aDouble", VariantType::Double, 3., {
"a double option"}},
72 ConfigParamSpec{
"aString,s", VariantType::String,
"foo", {
"a string option"}},
73 ConfigParamSpec{
"aBoolean", VariantType::Bool,
true, {
"a boolean option"}},
74 ConfigParamSpec{
"aNested.x", VariantType::Int, 2, {
"an int option, nested in an object"}},
75 ConfigParamSpec{
"aNested.y", VariantType::Float, 3.f, {
"a float option, nested in an object"}},
76 ConfigParamSpec{
"aNested.z", VariantType::Float, 4.f, {
"a float option, nested in an object"}},
79 std::vector<std::unique_ptr<ParamRetriever>> retrievers;
81 retrievers.emplace_back(std::move(fairmqRetriver));
88 boost::property_tree::json_parser::write_json(ss, store.store());
90 REQUIRE(store.store().get<
float>(
"aFloat") == 1.0);
91 REQUIRE(store.store().get<
double>(
"aDouble") == 2.0);
92 REQUIRE(store.store().get<
int>(
"anInt") == 10);
93 REQUIRE(store.store().get<int8_t>(
"anInt8") ==
'2');
94 REQUIRE(store.store().get<int16_t>(
"anInt16") == 10);
95 REQUIRE(store.store().get<uint8_t>(
"anUInt8") ==
'2');
96 REQUIRE(store.store().get<uint16_t>(
"anUInt16") == 10);
97 REQUIRE(store.store().get<uint32_t>(
"anUInt32") == 10);
98 REQUIRE(store.store().get<uint64_t>(
"anUInt64") == 10);
99 REQUIRE(store.store().get<int64_t>(
"anInt64") == 50000000000000ll);
100 REQUIRE(store.store().get<
bool>(
"aBoolean") ==
true);
101 REQUIRE(store.store().get<std::string>(
"aString") ==
"somethingelse");
102 REQUIRE(store.store().get<
int>(
"aNested.x") == 1);
103 REQUIRE(store.store().get<
int>(
"aNested.y") == 2.f);
105 auto pt = store.store().get_child(
"aNested");
106 REQUIRE(pt.get<
int>(
"x") == 1);
107 REQUIRE(pt.get<
float>(
"y") == 2.f);
109 std::stringstream ss2;
110 boost::property_tree::json_parser::write_json(ss2, store.provenanceTree());
112 REQUIRE(store.provenance(
"aFloat") ==
"fairmq");
113 REQUIRE(store.provenance(
"aDouble") ==
"fairmq");
114 REQUIRE(store.provenance(
"anInt") ==
"fairmq");
115 REQUIRE(store.provenance(
"anInt8") ==
"fairmq");
116 REQUIRE(store.provenance(
"anInt16") ==
"fairmq");
117 REQUIRE(store.provenance(
"anUInt8") ==
"fairmq");
118 REQUIRE(store.provenance(
"anUInt16") ==
"fairmq");
119 REQUIRE(store.provenance(
"anUInt32") ==
"fairmq");
120 REQUIRE(store.provenance(
"anUInt64") ==
"fairmq");
121 REQUIRE(store.provenance(
"anInt64") ==
"fairmq");
122 REQUIRE(store.provenance(
"aBoolean") ==
"fairmq");
123 REQUIRE(store.provenance(
"aString") ==
"fairmq");
124 REQUIRE(store.provenance(
"aNested.x") ==
"fairmq");
125 REQUIRE(store.provenance(
"aNested.y") ==
"fairmq");
126 REQUIRE(store.provenance(
"aNested.z") ==
"default");