ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
testConfigManager.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libdaq_test
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief Test log4cplus helpers
9  */
10 #include <gtest/gtest.h>
11 
12 #include <daq/config/manager.hpp>
13 #include <fmt/ostream.h>
14 
15 struct TestConfig {
16  int value0 = 0; // default
17  std::string value1 = "default"; // default
18 };
19 
20 class TestConfigManager : public ::testing::Test {
21 public:
23  : m_config(), m_config_manager(&m_config, log4cplus::Logger::getInstance("test")) {
24  }
25 
26 protected:
29 };
30 
32  m_config_manager.Register(&TestConfig::value0, {"value0", "description"});
33  m_config_manager.Register(&TestConfig::value1, {"value1", "description"});
34 
35  EXPECT_THROW(m_config_manager.Register(&TestConfig::value0, {}), std::invalid_argument);
36 }
37 
39  m_config_manager.Register(&TestConfig::value0, {"value0", "description value0"});
40 
41  auto val = m_config_manager.Get(&TestConfig::value0);
42  EXPECT_EQ(val.value, m_config.value0);
43  EXPECT_EQ(val.origin.origin, daq::config::Origin::Default);
44  EXPECT_EQ(val.origin.description, "");
45  EXPECT_EQ(val.metadata.canonical_name, "value0");
46  EXPECT_EQ(val.metadata.description, "description value0");
47 
48  EXPECT_THROW(m_config_manager.Get(&TestConfig::value1), std::invalid_argument)
49  << "value1 has not been registered and Get() should throw invalid_argument in that case";
50 }
51 
53  m_config_manager.Register(&TestConfig::value0, {"value0", "description value0"});
54  m_config_manager.Register(&TestConfig::value1, {"value1", "description value1"});
55 
56  {
57  // Pre-test check (covered by testcase "Get")
58  auto val = m_config_manager.Get(&TestConfig::value0);
59  EXPECT_EQ(val.value, m_config.value0);
60  ASSERT_EQ(val.origin.origin, daq::config::Origin::Default);
61  }
62 
63  // Test
64  m_config_manager.Update(&TestConfig::value0, 2, {daq::config::Origin::CommandLine, "args"});
65  auto val = m_config_manager.Get(&TestConfig::value0);
66  EXPECT_EQ(val.value, m_config.value0);
67  EXPECT_EQ(val.origin.origin, daq::config::Origin::CommandLine);
68  EXPECT_EQ(val.origin.description, "args");
69  EXPECT_EQ(val.metadata.canonical_name, "value0");
70  EXPECT_EQ(val.metadata.description, "description value0");
71 }
TestConfig::value1
std::string value1
Definition: testConfigManager.cpp:17
TEST_F
TEST_F(TestConfigManager, Register)
Definition: testConfigManager.cpp:31
manager.hpp
daq::config::Manager and associated types.
TestConfigManager::TestConfigManager
TestConfigManager()
Definition: testConfigManager.cpp:22
TestConfig::value0
int value0
Definition: testConfigManager.cpp:16
daq::config::Origin::Runtime
@ Runtime
Runtime change via e.g.
TestConfigManager
Definition: testConfigManager.cpp:20
TestConfig
Definition: testConfigManager.cpp:15
daq::config::Manager< TestConfig >
TestConfigManager::m_config
TestConfig m_config
Definition: testConfigManager.cpp:27
TestConfigManager::m_config_manager
daq::config::Manager< TestConfig > m_config_manager
Definition: testConfigManager.cpp:28