forked from vermagav/config-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_test.cc
95 lines (78 loc) · 3.02 KB
/
item_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <stdexcept>
#include "../common/lest.hpp"
#include "item.h"
const lest::test specification[] = {
CASE("A string item is retricted to its type") {
std::string i = "foobar";
config::Item item;
item.SetString(i);
// Able to retrieve correct value of expected type
EXPECT(config::ValueType::STRING == item.GetValueType());
EXPECT(i == item.GetString());
// Throw runtime error when retrieving incompatible types
EXPECT_THROWS_AS(item.GetBoolean(), std::runtime_error);
EXPECT_THROWS_AS(item.GetInteger(), std::runtime_error);
EXPECT_THROWS_AS(item.GetDouble(), std::runtime_error);
EXPECT_THROWS_AS(item.GetList(), std::runtime_error);
},
CASE("A boolean item is retricted to its type") {
bool i = true;
config::Item item;
item.SetBoolean(i);
// Able to retrieve correct value of expected type
EXPECT(config::ValueType::BOOLEAN == item.GetValueType());
EXPECT(i == item.GetBoolean());
// Throw runtime error when retrieving incompatible types
EXPECT_THROWS_AS(item.GetString(), std::runtime_error);
EXPECT_THROWS_AS(item.GetInteger(), std::runtime_error);
EXPECT_THROWS_AS(item.GetDouble(), std::runtime_error);
EXPECT_THROWS_AS(item.GetList(), std::runtime_error);
},
CASE("An integer item is retricted to its type") {
int64_t i = 12345;
config::Item item;
item.SetInteger(i);
// Able to retrieve correct value of expected type
EXPECT(config::ValueType::INTEGER == item.GetValueType());
EXPECT(i == item.GetInteger());
// Throw runtime error when retrieving incompatible types
EXPECT_THROWS_AS(item.GetString(), std::runtime_error);
EXPECT_THROWS_AS(item.GetBoolean(), std::runtime_error);
EXPECT_THROWS_AS(item.GetDouble(), std::runtime_error);
EXPECT_THROWS_AS(item.GetList(), std::runtime_error);
},
CASE("A double item is retricted to its type") {
double i = 3.14;
config::Item item;
item.SetDouble(i);
// Able to retrieve correct value of expected type
EXPECT(config::ValueType::DOUBLE == item.GetValueType());
EXPECT(i == item.GetDouble());
// Throw runtime error when retrieving incompatible types
EXPECT_THROWS_AS(item.GetString(), std::runtime_error);
EXPECT_THROWS_AS(item.GetBoolean(), std::runtime_error);
EXPECT_THROWS_AS(item.GetInteger(), std::runtime_error);
EXPECT_THROWS_AS(item.GetList(), std::runtime_error);
},
CASE("A list item is retricted to its type") {
std::vector<std::string> i = {
std::string("foo"),
std::string("bar"),
std::string("baz")
};
config::Item item;
item.SetList(i);
// Able to retrieve correct value of expected type
EXPECT(config::ValueType::LIST == item.GetValueType());
EXPECT(i == item.GetList());
// Throw runtime error when retrieving incompatible types
EXPECT_THROWS_AS(item.GetString(), std::runtime_error);
EXPECT_THROWS_AS(item.GetBoolean(), std::runtime_error);
EXPECT_THROWS_AS(item.GetInteger(), std::runtime_error);
EXPECT_THROWS_AS(item.GetDouble(), std::runtime_error);
}
};
int main(int argc, char* argv[]) {
return lest::run(specification, argc, argv);
}