CbmRoot
Loading...
Searching...
No Matches
_GTestYamlConfig.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023-2025 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4
5#include "CbmYaml.h"
6#include "gtest/gtest.h"
7
8using namespace cbm::util::yaml;
9
10//
11// TODO: These tests are nowhere near exhaustive. Extend after the DC.
12//
13
14TEST(Config, CanDeserializeStdMap)
15{
16 using Map_t = std::map<i32, i32>;
17
18 std::stringstream ss;
19 ss << "1: 2\n";
20 ss << "3: 4\n";
21 ss << "5: 6\n";
22
23 YAML::Node node = YAML::Load(ss.str());
24 auto map = Read<Map_t>(node);
25
26 EXPECT_EQ(map.size(), 3);
27 EXPECT_EQ(map.at(1), 2);
28 EXPECT_EQ(map.at(3), 4);
29 EXPECT_EQ(map.at(5), 6);
30}
31
32TEST(Config, CanSerializeStdMap)
33{
34 using Map_t = std::map<i32, i32>;
35
36 Map_t map;
37 map[1] = 2;
38 map[3] = 4;
39 map[5] = 6;
40
41 YAML::Node node = YAML::Load(Dump{}(map));
42
43 EXPECT_EQ(node.size(), 3);
44 EXPECT_EQ(node[1].as<i32>(), 2);
45 EXPECT_EQ(node[3].as<i32>(), 4);
46 EXPECT_EQ(node[5].as<i32>(), 6);
47}
48
49class Foo {
50 private:
51 i32 fBar = 42;
52 i32 fBaz = 43;
53
54 public:
55 i32 GetBar() const { return fBar; }
56 i32 GetBaz() const { return fBaz; }
57
59};
60
61TEST(Config, CanAccessPrivateMembers)
62{
63 std::stringstream ss;
64 ss << "bar: 1\n";
65 ss << "baz: 2\n";
66
67 YAML::Node node = YAML::Load(ss.str());
68 auto foo = Read<Foo>(node);
69
70 EXPECT_EQ(foo.GetBar(), 1);
71 EXPECT_EQ(foo.GetBaz(), 2);
72}
TEST(Config, CanDeserializeStdMap)
Configuration of the CA tracking (excluding geometry)
Definition CaConfig.h:36
CBM_YAML_PROPERTIES(Property(&Foo::fBar, "bar", ""), Property(&Foo::fBaz, "baz", ""))
i32 GetBar() const
i32 GetBaz() const
T Read(const YAML::Node &node)
Definition CbmYaml.h:74
Property(T Class::*member, std::string_view key, std::string_view description) -> Property< Class, T >
int32_t i32
Definition CbmYaml.h:29