Project
Loading...
Searching...
No Matches
test_ConfigurationOptionsRetriever.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 "../src/ConfigurationOptionsRetriever.h"
14#include <catch_amalgamated.hpp>
15#include <Configuration/ConfigurationFactory.h>
16#include <Configuration/ConfigurationInterface.h>
17
18#include <fstream>
19
20using namespace o2::framework;
21using namespace o2::configuration;
22
23TEST_CASE("TestOptionsRetriever")
24{
25 const std::string TEMP_FILE = "/tmp/alice_o2_configuration_test_file.ini";
26 // Put stuff in temp file
27 {
28 std::ofstream stream(TEMP_FILE);
29 stream << "key=value\n"
30 "[section]\n"
31 "key_int=123\n"
32 "key_float=4.56\n"
33 "key_string=hello\n";
34 }
35 // Get file configuration interface from factory
36 auto conf = ConfigurationFactory::getConfiguration("ini:/" + TEMP_FILE);
37
38 std::vector<ConfigParamSpec> specs{
39 ConfigParamSpec{"key", VariantType::String, "someDifferentValue", {"a string option"}},
40 ConfigParamSpec{"section.key_int", VariantType::Int64, 1ll, {"an int64_t option"}},
41 ConfigParamSpec{"section.key_float", VariantType::Float, 2.0f, {"a float option"}},
42 ConfigParamSpec{"section.key_string", VariantType::String, "foo", {"a string option"}},
43 };
44
45 std::vector<std::unique_ptr<ParamRetriever>> retrievers;
46 std::unique_ptr<ParamRetriever> fairmqRetriver{new ConfigurationOptionsRetriever(conf.get(), "")};
47 retrievers.emplace_back(std::move(fairmqRetriver));
48
49 ConfigParamStore store{specs, std::move(retrievers)};
50 store.preload();
51 store.activate();
52
53 REQUIRE(store.store().get<std::string>("key") == "value");
54 REQUIRE(store.store().get<int>("section.key_int") == 123);
55 REQUIRE(store.store().get<float>("section.key_float") == 4.56f);
56 REQUIRE(store.store().get<std::string>("section.key_string") == "hello");
57 // We can get nested objects also via their top-level ptree.
58 auto pt = store.store().get_child("section");
59 REQUIRE(pt.get<int>("key_int") == 123);
60 REQUIRE(pt.get<float>("key_float") == 4.56f);
61}
ParamRetriever which uses AliceO2Group/Configuration to get the options.
GLuint GLuint stream
Definition glcorearb.h:1806
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("TestOptionsRetriever")