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