Project
Loading...
Searching...
No Matches
test_BoostOptionsRetriever.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include <boost/program_options.hpp>
15#include <boost/program_options/parsers.hpp>
16#include <catch_amalgamated.hpp>
17#include <vector>
18
19using namespace o2::framework;
20
21TEST_CASE("TrivialBoostOptionsRetrieverTest")
22{
23 using namespace o2::framework;
24 namespace bpo = boost::program_options;
25
26 auto specs = std::vector<ConfigParamSpec>{
27 {"someInt", VariantType::Int, 2, {"some int option"}},
28 {"someInt8", VariantType::Int8, static_cast<int8_t>(2), {"some int8 option"}},
29 {"someInt16", VariantType::Int16, static_cast<int16_t>(2), {"some int16 option"}},
30 {"someUInt8", VariantType::UInt8, static_cast<uint8_t>(2u), {"some uint8 option"}},
31 {"someUInt16", VariantType::UInt16, static_cast<uint16_t>(2u), {"some uint16 option"}},
32 {"someUInt32", VariantType::UInt32, 2u, {"some uint32 option"}},
33 {"someUInt64", VariantType::UInt64, static_cast<uint64_t>(2ul), {"some uint64 option"}},
34 {"someInt64", VariantType::Int64, 4ll, {"some int64 option"}},
35 {"someBool", VariantType::Bool, false, {"some bool option"}},
36 {"someFloat", VariantType::Float, 2.0f, {"some float option"}},
37 {"someDouble", VariantType::Double, 2.0, {"some double option"}},
38 {"someString", VariantType::String, strdup("barfoo"), {"some string option"}}};
39 const char* args[] = {
40 "test",
41 "--someBool",
42 "--someInt", "1",
43 "--someInt8", "1",
44 "--someInt16", "1",
45 "--someUInt8", "1",
46 "--someUInt16", "1",
47 "--someUInt32", "1",
48 "--someUInt64", "1",
49 "--someInt64", "50000000000000",
50 "--someFloat", "0.5",
51 "--someDouble", "0.5",
52 "--someString", "foobar"};
53 bpo::variables_map vm;
54 bpo::options_description opts;
55
57
58 bpo::store(parse_command_line(sizeof(args) / sizeof(char*), args, opts), vm);
59 bpo::notify(vm);
60 REQUIRE(vm["someInt"].as<int>() == 1);
61 REQUIRE(vm["someInt8"].as<int8_t>() == '1');
62 REQUIRE(vm["someInt16"].as<int16_t>() == 1);
63 REQUIRE(vm["someUInt8"].as<uint8_t>() == '1');
64 REQUIRE(vm["someUInt16"].as<uint16_t>() == 1);
65 REQUIRE(vm["someUInt32"].as<uint32_t>() == 1);
66 REQUIRE(vm["someUInt64"].as<uint64_t>() == 1);
67 REQUIRE(vm["someInt64"].as<int64_t>() == 50000000000000ll);
68 REQUIRE(vm["someBool"].as<bool>() == true);
69 REQUIRE(vm["someString"].as<std::string>() == "foobar");
70 REQUIRE(vm["someFloat"].as<float>() == 0.5);
71 REQUIRE(vm["someDouble"].as<double>() == 0.5);
72}
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
static void populateBoostProgramOptions(options_description &options, const std::vector< ConfigParamSpec > &specs, options_description vetos=options_description())
TEST_CASE("TrivialBoostOptionsRetrieverTest")