9 #include "gtest/gtest.h"
13 TEST(EncodableValueTest, Null) {
18 TEST(EncodableValueTest, Bool) {
21 EXPECT_FALSE(std::get<bool>(value));
23 EXPECT_TRUE(std::get<bool>(value));
26 TEST(EncodableValueTest, Int) {
29 EXPECT_EQ(std::get<int32_t>(value), 42);
30 value = std::numeric_limits<int32_t>::max();
31 EXPECT_EQ(std::get<int32_t>(value), std::numeric_limits<int32_t>::max());
35 TEST(EncodableValueTest, LongValue) {
36 const EncodableValue int_value(std::numeric_limits<int32_t>::max());
37 EXPECT_EQ(int_value.
LongValue(), std::numeric_limits<int32_t>::max());
38 const EncodableValue long_value(std::numeric_limits<int64_t>::max());
39 EXPECT_EQ(long_value.
LongValue(), std::numeric_limits<int64_t>::max());
42 TEST(EncodableValueTest, Long) {
45 EXPECT_EQ(std::get<int64_t>(value), 42);
46 value = std::numeric_limits<int64_t>::max();
47 EXPECT_EQ(std::get<int64_t>(value), std::numeric_limits<int64_t>::max());
50 TEST(EncodableValueTest, Double) {
53 EXPECT_EQ(std::get<double>(value), 3.14);
54 value = std::numeric_limits<double>::max();
55 EXPECT_EQ(std::get<double>(value), std::numeric_limits<double>::max());
58 TEST(EncodableValueTest, String) {
59 std::string hello(
"Hello, world!");
62 EXPECT_EQ(std::get<std::string>(value), hello);
63 value = std::string(
"Goodbye");
64 EXPECT_EQ(std::get<std::string>(value),
"Goodbye");
68 TEST(EncodableValueTest, CString) {
69 const char* hello =
"Hello, world!";
72 EXPECT_EQ(std::get<std::string>(value), hello);
74 EXPECT_EQ(std::get<std::string>(value),
"Goodbye");
77 TEST(EncodableValueTest, UInt8List) {
78 std::vector<uint8_t> data = {0, 2};
81 auto& list_value = std::get<std::vector<uint8_t>>(value);
82 list_value.push_back(std::numeric_limits<uint8_t>::max());
83 EXPECT_EQ(list_value[0], 0);
84 EXPECT_EQ(list_value[1], 2);
86 ASSERT_EQ(list_value.size(), 3u);
87 EXPECT_EQ(data.size(), 2u);
88 EXPECT_EQ(list_value[2], std::numeric_limits<uint8_t>::max());
91 TEST(EncodableValueTest, Int32List) {
92 std::vector<int32_t> data = {-10, 2};
95 auto& list_value = std::get<std::vector<int32_t>>(value);
96 list_value.push_back(std::numeric_limits<int32_t>::max());
97 EXPECT_EQ(list_value[0], -10);
98 EXPECT_EQ(list_value[1], 2);
100 ASSERT_EQ(list_value.size(), 3u);
101 EXPECT_EQ(data.size(), 2u);
102 EXPECT_EQ(list_value[2], std::numeric_limits<int32_t>::max());
105 TEST(EncodableValueTest, Int64List) {
106 std::vector<int64_t> data = {-10, 2};
109 auto& list_value = std::get<std::vector<int64_t>>(value);
110 list_value.push_back(std::numeric_limits<int64_t>::max());
111 EXPECT_EQ(list_value[0], -10);
112 EXPECT_EQ(list_value[1], 2);
114 ASSERT_EQ(list_value.size(), 3u);
115 EXPECT_EQ(data.size(), 2u);
116 EXPECT_EQ(list_value[2], std::numeric_limits<int64_t>::max());
119 TEST(EncodableValueTest, DoubleList) {
120 std::vector<double> data = {-10.0, 2.0};
123 auto& list_value = std::get<std::vector<double>>(value);
124 list_value.push_back(std::numeric_limits<double>::max());
125 EXPECT_EQ(list_value[0], -10.0);
126 EXPECT_EQ(list_value[1], 2.0);
128 ASSERT_EQ(list_value.size(), 3u);
129 EXPECT_EQ(data.size(), 2u);
130 EXPECT_EQ(list_value[2], std::numeric_limits<double>::max());
133 TEST(EncodableValueTest, List) {
141 auto& list_value = std::get<EncodableList>(value);
142 EXPECT_EQ(std::get<int32_t>(list_value[0]), 1);
143 EXPECT_EQ(std::get<double>(list_value[1]), 2.0);
144 EXPECT_EQ(std::get<std::string>(list_value[2]),
"Three");
148 ASSERT_EQ(list_value.size(), 4u);
149 EXPECT_EQ(encodables.size(), 3u);
150 EXPECT_EQ(std::get<bool>(std::get<EncodableList>(value)[3]),
true);
153 TEST(EncodableValueTest, Map) {
161 auto& map_value = std::get<EncodableMap>(value);
163 std::holds_alternative<std::vector<int32_t>>(map_value[
EncodableValue()]),
165 EXPECT_EQ(std::get<int64_t>(map_value[
EncodableValue(1)]), INT64_C(10000));
166 EXPECT_EQ(std::get<int32_t>(map_value[
EncodableValue(
"two")]), 7);
170 ASSERT_EQ(map_value.size(), 4u);
171 EXPECT_EQ(encodables.size(), 3u);
172 EXPECT_EQ(std::get<bool>(map_value[
EncodableValue(
true)]),
false);
177 TEST(EncodableValueTest, Comparison) {
225 for (
size_t i = 0; i < values.size(); ++i) {
226 const auto& a = values[i];
227 for (
size_t j = 0; j < values.size(); ++j) {
228 const auto& b = values[j];
236 EXPECT_NE(a < b, b < a) <<
"Indexes: " << i <<
", " << j;
242 EXPECT_FALSE(a < copy || copy < a);
247 TEST(EncodableValueTest, DeepCopy) {
263 ASSERT_TRUE(std::holds_alternative<EncodableList>(copy));
266 auto& root_list = std::get<EncodableList>(copy);
267 auto& first_child = std::get<EncodableMap>(root_list[0]);
268 EXPECT_EQ(std::get<int32_t>(first_child[
EncodableValue(
"two")]), 7);
269 auto& second_child = std::get<EncodableList>(root_list[1]);
270 auto& innermost_map = std::get<EncodableMap>(second_child[2]);
271 EXPECT_EQ(std::get<std::string>(innermost_map[
EncodableValue(
"a")]),
"b");
279 first_child = std::get<EncodableMap>(original[0]);
280 EXPECT_EQ(std::get<int32_t>(first_child[
EncodableValue(
"two")]), 7);
281 second_child = std::get<EncodableList>(original[1]);
282 innermost_map = std::get<EncodableMap>(second_child[2]);
283 EXPECT_EQ(std::get<std::string>(innermost_map[
EncodableValue(
"a")]),
"b");
293 int x()
const {
return x_; }
294 int y()
const {
return y_; }
301 TEST(EncodableValueTest, TypeIndexesCorrect) {