VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
ConfigurationFileTest.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#include <gmock/gmock.h>
35
37
38using namespace vf::basics;
39
41{
42 ConfigurationFile config;
43 config.data["key1"] = "value1";
44 config.data["key2"] = "value2";
45
46 EXPECT_TRUE(config.contains("key1"));
47 EXPECT_TRUE(config.contains("key2"));
48}
49
51{
52 ConfigurationFile config;
53 config.data["key1"] = "value1";
54
55 EXPECT_FALSE(config.contains("key2"));
56}
57
59{
60 ConfigurationFile config;
61 config.data["key1"] = "value1";
62 config.data["key2"] = "1234";
63
64 EXPECT_EQ(config.getValue<std::string>("key1"), "value1");
65 EXPECT_EQ(config.getValue<int>("key2"), 1234);
66}
67
69{
70 ConfigurationFile config;
71 config.data["key1"] = "value1";
72
73 EXPECT_THROW(config.getValue<std::string>("key2"), UbException);
74}
75
77{
78 ConfigurationFile config;
79 config.data["key1"] = "1, 2, 3";
80 config.data["key2"] = "4; 5; 6";
81
82 std::vector<int> v1 = config.getVector<int>("key1");
83 std::vector<int> v2 = config.getVector<int>("key2");
84
85 EXPECT_EQ(v1.size(), 3);
86 EXPECT_EQ(v1[0], 1);
87 EXPECT_EQ(v1[1], 2);
88 EXPECT_EQ(v1[2], 3);
89
90 EXPECT_EQ(v2.size(), 3);
91 EXPECT_EQ(v2[0], 4);
92 EXPECT_EQ(v2[1], 5);
93 EXPECT_EQ(v2[2], 6);
94}
95
97{
98 ConfigurationFile config;
99 config.data["key1"] = "1, 2, 3";
100
101 EXPECT_THROW(config.getVector<int>("key2"), UbException);
102}
103
105{
106 ConfigurationFile config;
107 config.data["key1"] = "value1";
108
109 int defaultValue = 42;
110 int value = config.getValue<int>("key2", defaultValue);
111
112 EXPECT_EQ(value, defaultValue);
113}
114
116{
117 ConfigurationFile config;
118 config.data["key1"] = "42";
119
120 int defaultValue = 0;
121 int value = config.getValue<int>("key1", defaultValue);
122
123 EXPECT_EQ(value, 42);
124}
125
127{
128 ConfigurationFile config;
129 config.data["key1"] = "true";
130 config.data["key2"] = "false";
131
132 bool valueTrue = config.getValue<bool>("key1");
133 bool valueFalse = config.getValue<bool>("key2");
134
137}
138
140{
141 ConfigurationFile config;
142 config.data["key1"] = "text";
143
144 EXPECT_THROW(config.getVector<int>("key1"), UbException);
145}
146
148{
149 ConfigurationFile config;
150 config.data["key1"] = "value1";
151 config.data["key2"] = "value2";
152
153 config.clear();
154
155 EXPECT_TRUE(config.data.empty());
156}
157
std::vector< T > getVector(const std::string &key) const
get vector with key
std::map< std::string, std::string > data
the container is public to test this class
bool contains(const std::string &key) const
check if value associated with given key exists
T getValue(const std::string &key) const
get value with key
std::shared_ptr< T > SPtr
TEST(ConfigurationFileTest, ContainsReturnsTrueForExistingKey)
Simple configuration file.