Project
Loading...
Searching...
No Matches
test_RootConfigParamHelpers.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
12#include <catch_amalgamated.hpp>
13#include <fairmq/ProgOptions.h>
17#include <boost/program_options.hpp>
18#include "TestClasses.h"
19
20using namespace o2::framework;
21namespace bpo = boost::program_options;
22
23TEST_CASE("TestRootConfigParamRegistry")
24{
25 bpo::options_description testOptions("Test options");
26 testOptions.add_options() //
27 ("foo.x", bpo::value<int>()->default_value(2)) //
28 ("foo.y", bpo::value<float>()->default_value(3.f)); //
29
30 fair::mq::ProgOptions* options = new fair::mq::ProgOptions();
31 options->AddToCmdLineOptions(testOptions);
32 options->ParseAll({"cmd",
33 "--foo.x", "1",
34 "--foo.y", "2"},
35 true);
36
37 std::vector<ConfigParamSpec> specs = RootConfigParamHelpers::asConfigParamSpecs<o2::test::SimplePODClass>("foo");
38
39 std::vector<std::unique_ptr<ParamRetriever>> retrievers;
40 std::unique_ptr<ParamRetriever> fairmqRetriver{new FairOptionsRetriever(options)};
41 retrievers.emplace_back(std::move(fairmqRetriver));
42
43 auto store = std::make_unique<ConfigParamStore>(specs, std::move(retrievers));
44 store->preload();
45 store->activate();
46 ConfigParamRegistry registry(std::move(store));
47
48 REQUIRE(registry.get<int>("foo.x") == 1);
49 REQUIRE(registry.get<float>("foo.y") == 2.f);
50
51 // We can get nested objects also via their top-level ptree.
52 auto pt = registry.get<boost::property_tree::ptree>("foo");
53 REQUIRE(pt.get<int>("x") == 1);
54 REQUIRE(pt.get<float>("y") == 2.f);
55
56 // And we can get it as a generic object as well.
57 auto obj = RootConfigParamHelpers::as<o2::test::SimplePODClass>(pt);
58 REQUIRE(obj.x == 1);
59 REQUIRE(obj.y == 2.f);
60}
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")