summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-12-19 17:10:51 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-01-04 17:38:33 -0800
commit0c0064c050396eae8dad92e5097692537405704a (patch)
tree5eb3c975fc4295b7fcbc244258f8facbc1f7e30a /test
parent59803d3025683a255737b5ae29bd7fc531a975a3 (diff)
downloadqtlocation-mapboxgl-0c0064c050396eae8dad92e5097692537405704a.tar.gz
[core] Get rid of user-specified refs
Diffstat (limited to 'test')
-rw-r--r--test/style/conversion/stringify.test.cpp98
-rw-r--r--test/style/group_by_layout.test.cpp44
2 files changed, 142 insertions, 0 deletions
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp
new file mode 100644
index 0000000000..be5d65d4ce
--- /dev/null
+++ b/test/style/conversion/stringify.test.cpp
@@ -0,0 +1,98 @@
+#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, Function) {
+ ASSERT_EQ(stringify(Function<float>({{0, 1}}, 2)), "{\"base\":2.0,\"stops\":[[0.0,1.0]]}");
+}
+
+TEST(Stringify, PropertyValue) {
+ ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0");
+ ASSERT_EQ(stringify(PropertyValue<float>(Function<float>({{0, 1}}, 2))), "{\"base\":2.0,\"stops\":[[0.0,1.0]]}");
+}
+
+TEST(Stringify, Layout) {
+ ASSERT_EQ(stringify(SymbolLayoutProperties()), "{}");
+
+ SymbolLayoutProperties layout;
+ layout.unevaluated.get<SymbolAvoidEdges>() = true;
+ layout.unevaluated.get<IconPadding>() = 2.0;
+ ASSERT_EQ(stringify(layout), "{\"symbol-avoid-edges\":true,\"icon-padding\":2.0}");
+}
diff --git a/test/style/group_by_layout.test.cpp b/test/style/group_by_layout.test.cpp
new file mode 100644
index 0000000000..d74916cdc9
--- /dev/null
+++ b/test/style/group_by_layout.test.cpp
@@ -0,0 +1,44 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/group_by_layout.hpp>
+#include <mbgl/style/layers/background_layer.hpp>
+#include <mbgl/style/layers/circle_layer.hpp>
+#include <mbgl/style/layers/line_layer.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+TEST(GroupByLayout, Related) {
+ std::vector<std::unique_ptr<Layer>> layers;
+ layers.push_back(std::make_unique<LineLayer>("a", "source"));
+ layers.push_back(std::make_unique<LineLayer>("b", "source"));
+ auto result = groupByLayout(std::move(layers));
+ ASSERT_EQ(1u, result.size());
+ ASSERT_EQ(2u, result[0].size());
+}
+
+TEST(GroupByLayout, UnrelatedType) {
+ std::vector<std::unique_ptr<Layer>> layers;
+ layers.push_back(std::make_unique<BackgroundLayer>("background"));
+ layers.push_back(std::make_unique<CircleLayer>("circle", "source"));
+ auto result = groupByLayout(std::move(layers));
+ ASSERT_EQ(2u, result.size());
+}
+
+TEST(GroupByLayout, UnrelatedFilter) {
+ std::vector<std::unique_ptr<Layer>> layers;
+ layers.push_back(std::make_unique<LineLayer>("a", "source"));
+ layers.push_back(std::make_unique<LineLayer>("b", "source"));
+ layers[0]->as<LineLayer>()->setFilter(EqualsFilter());
+ auto result = groupByLayout(std::move(layers));
+ ASSERT_EQ(2u, result.size());
+}
+
+TEST(GroupByLayout, UnrelatedLayout) {
+ std::vector<std::unique_ptr<Layer>> layers;
+ layers.push_back(std::make_unique<LineLayer>("a", "source"));
+ layers.push_back(std::make_unique<LineLayer>("b", "source"));
+ layers[0]->as<LineLayer>()->setLineCap(LineCapType::Square);
+ auto result = groupByLayout(std::move(layers));
+ ASSERT_EQ(2u, result.size());
+}