36 bpo::options_description testOptions(
"Test options");
37 testOptions.add_options()
38 (
"aFloat", bpo::value<float>()->default_value(10.f))
39 (
"aDouble", bpo::value<double>()->default_value(20.))
40 (
"anInt", bpo::value<int>()->default_value(1))
41 (
"anInt8", bpo::value<int8_t>()->default_value(1))
42 (
"anInt16", bpo::value<int16_t>()->default_value(1))
43 (
"anUInt8", bpo::value<uint8_t>()->default_value(1))
44 (
"anUInt16", bpo::value<uint16_t>()->default_value(1))
45 (
"anUInt32", bpo::value<uint32_t>()->default_value(1))
46 (
"anUInt64", bpo::value<uint64_t>()->default_value(1))
47 (
"anInt64", bpo::value<int64_t>()->default_value(1ll))
48 (
"aBoolean", bpo::value<bool>()->zero_tokens()->default_value(
false))
49 (
"aString,s", bpo::value<std::string>()->default_value(
"something"))
50 (
"aNested.x", bpo::value<int>()->default_value(2))
51 (
"aNested.y", bpo::value<float>()->default_value(3.f));
53 fair::mq::ProgOptions* options =
new fair::mq::ProgOptions();
54 options->AddToCmdLineOptions(testOptions);
55 options->ParseAll({
"cmd",
"--aFloat",
"1.0",
64 "--anInt64",
"50000000000000",
66 "-s",
"somethingelse",
70 std::vector<ConfigParamSpec> specs{
72 ConfigParamSpec{
"anInt8", VariantType::Int8,
static_cast<int8_t
>(1), {
"an int8 option"}},
73 ConfigParamSpec{
"anInt16", VariantType::Int16,
static_cast<int16_t
>(1), {
"an int16 option"}},
74 ConfigParamSpec{
"anUInt8", VariantType::UInt8,
static_cast<uint8_t
>(1u), {
"an uint8 option"}},
75 ConfigParamSpec{
"anUInt16", VariantType::UInt16,
static_cast<uint16_t
>(1u), {
"an uint16 option"}},
76 ConfigParamSpec{
"anUInt32", VariantType::UInt32, 1u, {
"an uint32 option"}},
77 ConfigParamSpec{
"anUInt64", VariantType::UInt64,
static_cast<uint64_t
>(1ul), {
"an uint64 option"}},
78 ConfigParamSpec{
"anInt64", VariantType::Int64, 1ll, {
"an int64_t option"}},
79 ConfigParamSpec{
"aFloat", VariantType::Float, 2.0f, {
"a float option"}},
80 ConfigParamSpec{
"aDouble", VariantType::Double, 3., {
"a double option"}},
81 ConfigParamSpec{
"aString,s", VariantType::String,
"foo", {
"a string option"}},
82 ConfigParamSpec{
"aBoolean", VariantType::Bool,
true, {
"a boolean option"}},
83 ConfigParamSpec{
"aNested.x", VariantType::Int, 2, {
"an int option, nested in an object"}},
84 ConfigParamSpec{
"aNested.y", VariantType::Float, 3.f, {
"a float option, nested in an object"}},
85 ConfigParamSpec{
"aNested.z", VariantType::Float, 4.f, {
"a float option, nested in an object"}},
88 std::vector<std::unique_ptr<ParamRetriever>> retrievers;
90 retrievers.emplace_back(std::move(fairmqRetriver));
92 auto store = std::make_unique<ConfigParamStore>(specs, std::move(retrievers));
97 REQUIRE(registry.
get<
float>(
"aFloat") == 1.0);
98 REQUIRE(registry.
get<
double>(
"aDouble") == 2.0);
99 REQUIRE(registry.
get<
int>(
"anInt") == 10);
100 REQUIRE(registry.
get<int8_t>(
"anInt8") ==
'2');
101 REQUIRE(registry.
get<int16_t>(
"anInt16") == 10);
102 REQUIRE(registry.
get<uint8_t>(
"anUInt8") ==
'2');
103 REQUIRE(registry.
get<uint16_t>(
"anUInt16") == 10);
104 REQUIRE(registry.
get<uint32_t>(
"anUInt32") == 10);
105 REQUIRE(registry.
get<uint64_t>(
"anUInt64") == 10);
106 REQUIRE(registry.
get<int64_t>(
"anInt64") == 50000000000000ll);
107 REQUIRE(registry.
get<
bool>(
"aBoolean") ==
true);
108 REQUIRE(registry.
get<std::string>(
"aString") ==
"somethingelse");
109 REQUIRE(registry.
get<
int>(
"aNested.x") == 1);
110 REQUIRE(registry.
get<
float>(
"aNested.y") == 2.f);
111 REQUIRE(registry.
get<
float>(
"aNested.z") == 4.f);
113 auto pt = registry.
get<boost::property_tree::ptree>(
"aNested");
114 auto pt2 = registry.
get<boost::property_tree::ptree>(
"aDict");
115 REQUIRE(pt.get<
int>(
"x") == 1);
116 REQUIRE(pt.get<
float>(
"y") == 2.f);
120 REQUIRE(obj.
y == 2.f);