Scheduler
configurationTest.cpp
Go to the documentation of this file.
1 
10 #include <gtest/gtest.h>
11 #include <utils/configuration.h>
12 #include <iostream>
13 #include <stdexcept>
14 
15 
16 class ConfigurationTest : public ::testing::Test
17 {
18 public:
19  ConfigurationTest() : conf("configurationTest.conf"),
20  wrongFile("blaaa") {};
23 
24 };
25 
26 TEST_F(ConfigurationTest, getStringValueTest)
27 {
28  std::string value = conf.getStringValue("abc", "key1");
29  EXPECT_EQ(std::string("value1"), value);
30 }
31 
32 TEST_F(ConfigurationTest, getStringListTest)
33 {
34  std::vector<std::string> vect = conf.getStringList("def", "key7");
35  EXPECT_EQ(3u, vect.size());
36  EXPECT_EQ(std::string("2"), vect[0]);
37  EXPECT_EQ(std::string("6"), vect[2]);
38 }
39 
40 
41 TEST_F(ConfigurationTest, getDoubleValueTest)
42 {
43  double value = conf.getDoubleValue("def", "key9");
44  EXPECT_DOUBLE_EQ((double) 3.14159, value);
45 }
46 
47 /*FIXME: the behavior works as expected when tested outside of gtest,
48 but for some reason, here stoull throws an invalid_argument exception...
49 might be some compilation settings*/
50 TEST_F(ConfigurationTest, DISABLED_getUnsignedLongLongIntValueTest)
51 {
52  std::cerr << "hi\n";
53  unsigned long long int value = conf.getUnsignedLongLongIntValue("def", "value10");
54  unsigned long long int expected = 18446744073709551615ull;
55  std::cerr << "Hello\n";
56  EXPECT_EQ(expected, value);
57 }
58 
59 TEST_F(ConfigurationTest, getIntValueTest)
60 {
61  int value = conf.getIntValue("def", "key6");
62  EXPECT_EQ((int) -1, value);
63 }
64 
65 TEST_F(ConfigurationTest, getBoolValueTest)
66 {
67  bool value1 = conf.getBoolValue("abc", "key1", true);
68  bool value2 = conf.getBoolValue("abc", "key1", false);
69  bool value3 = conf.getBoolValue("def", "key4", false);
70  bool value4 = conf.getBoolValue("def", "key5", false);
71  bool value5 = conf.getBoolValue("def", "key11", true);
72 
73  EXPECT_TRUE(value1);
74  EXPECT_FALSE(value2);
75  EXPECT_TRUE(value3);
76  EXPECT_TRUE(value4);
77  EXPECT_FALSE(value5);
78 }
79 
80 
81 TEST(ConfigurationNameTest, getFilePrefixTest)
82 {
83  std::string filename = "./configuration.conf";
84  Utils::Configuration conf(filename);
85  std::string actualName = conf.getName();
86  EXPECT_EQ(filename, actualName);
87 
88 
89  std::string expectedPrefix = "configuration.conf";
90  std::string actualPrefix = conf.getFilePrefix();
91  EXPECT_EQ(expectedPrefix, actualPrefix);
92 }
93 
94 
95 TEST_F(ConfigurationTest, wrongFilenameTest)
96 {
97  EXPECT_THROW(wrongFile.getStringValue("abc", "key1"), std::runtime_error);
98 }
99 
100 TEST_F(ConfigurationTest, noSpacesTest)
101 {
102  std::string expected = "value2";
103  std::string actual = conf.getStringValue("abc", "key2");
104  /*Not a bug, a feature! This promotes a clear style*/
105  EXPECT_NE(expected, actual);
106 }
107 
108 
109 
110 
virtual unsigned long long int getUnsignedLongLongIntValue(std::string section, std::string key)
virtual int getIntValue(std::string section, std::string key)
TEST_F(ConfigurationTest, getStringValueTest)
TEST(ConfigurationNameTest, getFilePrefixTest)
std::string getFilePrefix()
returns the name of the configuration file stripped of any directory
Utils::Configuration conf
string filename
Definition: aging.py:5
virtual bool getBoolValue(std::string section, std::string key, bool defaultValue)
virtual double getDoubleValue(std::string section, std::string key)
Utils::Configuration wrongFile
std::string getName()
Definition: configuration.h:36
virtual std::vector< std::string > getStringList(std::string section, std::string key)
virtual std::string getStringValue(std::string section, std::string key)