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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#include <mbgl/test/util.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
using namespace mbgl;
using namespace mbgl::style;
using namespace mbgl::style::conversion;
template <class T>
std::string stringify(const T& t) {
rapidjson::StringBuffer s;
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
stringify(writer, t);
return s.GetString();
}
TEST(Stringify, NullValue) {
ASSERT_EQ(stringify(NullValue()), "null");
}
TEST(Stringify, Boolean) {
ASSERT_EQ(stringify(true), "true");
ASSERT_EQ(stringify(false), "false");
}
TEST(Stringify, Uint64) {
ASSERT_EQ(stringify(uint64_t(0)), "0");
ASSERT_EQ(stringify(uint64_t(1)), "1");
}
TEST(Stringify, Int64) {
ASSERT_EQ(stringify(int64_t(0)), "0");
ASSERT_EQ(stringify(int64_t(-1)), "-1");
}
TEST(Stringify, Double) {
ASSERT_EQ(stringify(0.0), "0.0");
ASSERT_EQ(stringify(10.1234), "10.1234");
}
TEST(Stringify, String) {
ASSERT_EQ(stringify(std::string("test")), "\"test\"");
}
TEST(Stringify, Enum) {
ASSERT_EQ(stringify(VisibilityType::Visible), "\"visible\"");
}
TEST(Stringify, Color) {
ASSERT_EQ(stringify(Color::blue()), "\"rgba(0,0,255,1)\"");
}
TEST(Stringify, Array) {
ASSERT_EQ(stringify(std::array<float, 2> {{ 1, 2 }}), "[1.0,2.0]");
}
TEST(Stringify, Vector) {
ASSERT_EQ(stringify(std::vector<float> {{ 1, 2 }}), "[1.0,2.0]");
}
TEST(Stringify, Map) {
ASSERT_EQ(stringify(std::unordered_map<std::string, float> {{ "a", 1 }}), "{\"a\":1.0}");
}
TEST(Stringify, Value) {
ASSERT_EQ(stringify(Value(true)), "true");
ASSERT_EQ(stringify(Value(uint64_t(0))), "0");
ASSERT_EQ(stringify(Value(1.2)), "1.2");
}
TEST(Stringify, Filter) {
ASSERT_EQ(stringify(NullFilter()), "null");
ASSERT_EQ(stringify(EqualsFilter { "a", 1.0 }), "[\"==\",\"a\",1.0]");
}
TEST(Stringify, CameraFunction) {
ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 })),
"{\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}");
ASSERT_EQ(stringify(CameraFunction<float>(IntervalStops<float> { {{0, 1}} })),
"{\"type\":\"interval\",\"stops\":[[0.0,1.0]]}");
}
TEST(Stringify, SourceFunction) {
ASSERT_EQ(stringify(SourceFunction<float>("property", ExponentialStops<float> { {{0, 1}}, 2 })),
"{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}");
ASSERT_EQ(stringify(SourceFunction<float>("property", IntervalStops<float> { {{0, 1}} })),
"{\"property\":\"property\",\"type\":\"interval\",\"stops\":[[0.0,1.0]]}");
ASSERT_EQ(stringify(SourceFunction<float>("property", CategoricalStops<float> { {{CategoricalValue(true), 1}} })),
"{\"property\":\"property\",\"type\":\"categorical\",\"stops\":[[true,1.0]]}");
ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {})),
"{\"property\":\"property\",\"type\":\"identity\"}");
ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {}, 0.0f)),
"{\"property\":\"property\",\"type\":\"identity\",\"default\":0.0}");
}
TEST(Stringify, CompositeFunction) {
ASSERT_EQ(stringify(CompositeFunction<float>("property",
CompositeExponentialStops<float> {
{
{ 0, {{0, 1}} },
{ 1, {{0, 1}} }
},
2
}, 0.0f)),
"{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0,"
"\"stops\":["
"[{\"zoom\":0.0,\"value\":0.0},1.0],"
"[{\"zoom\":1.0,\"value\":0.0},1.0]],\"default\":0.0}");
}
TEST(Stringify, PropertyValue) {
ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0");
ASSERT_EQ(stringify(PropertyValue<float>(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 }))),
"{\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}");
}
TEST(Stringify, Layout) {
auto stringify = [] (const SymbolLayoutProperties::Unevaluated& layout) {
rapidjson::StringBuffer s;
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
layout.stringify(writer);
return std::string(s.GetString());
};
ASSERT_EQ(stringify(SymbolLayoutProperties::Unevaluated()), "{}");
SymbolLayoutProperties::Unevaluated layout;
layout.get<SymbolAvoidEdges>() = true;
layout.get<IconPadding>() = 2.0;
ASSERT_EQ(stringify(layout), "{\"symbol-avoid-edges\":true,\"icon-padding\":2.0}");
}
|