summaryrefslogtreecommitdiff
path: root/test/style
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-05-17 11:47:31 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-05-17 11:47:31 -0400
commit30376f3ce1d17522d9e64901b1bbc52906ee5267 (patch)
tree1f00d04a223a76a86e16ddebc77f56d2cff88b5b /test/style
parent7d1e52a3255d4eecdcd37e4fb600eb76fa9333f8 (diff)
parent146057adf90e85e3edc80446f02d20e5f6cab378 (diff)
downloadqtlocation-mapboxgl-30376f3ce1d17522d9e64901b1bbc52906ee5267.tar.gz
Merge branch 'release-boba' into masterupstream/fabian-merge-release-4.0.1-master
# Conflicts: # mapbox-gl-js # platform/android/CHANGELOG.md # platform/android/MapboxGLAndroidSDK/gradle.properties # platform/android/gradle/dependencies.gradle # platform/darwin/src/MGLVectorTileSource.mm # platform/darwin/src/MGLVectorTileSource_Private.h # platform/ios/CHANGELOG.md # src/mbgl/style/expression/compound_expression.cpp
Diffstat (limited to 'test/style')
-rw-r--r--test/style/conversion/stringify.test.cpp9
-rw-r--r--test/style/filter.test.cpp65
-rw-r--r--test/style/style_layer.test.cpp2
3 files changed, 71 insertions, 5 deletions
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp
index 136f276aaf..c3faf1f838 100644
--- a/test/style/conversion/stringify.test.cpp
+++ b/test/style/conversion/stringify.test.cpp
@@ -1,5 +1,6 @@
#include <mbgl/test/util.hpp>
+#include <mbgl/style/expression/literal.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
@@ -75,8 +76,12 @@ TEST(Stringify, Value) {
}
TEST(Stringify, Filter) {
- ASSERT_EQ(stringify(NullFilter()), "null");
- ASSERT_EQ(stringify(EqualsFilter { "a", 1.0 }), "[\"==\",\"a\",1.0]");
+ using namespace mbgl::style::expression;
+
+ ASSERT_EQ(stringify(Filter()), "null");
+
+ ParsingContext context;
+ ASSERT_EQ(stringify(Filter(createCompoundExpression("filter-==", createLiteral("a"), createLiteral(1.0), context))), "[\"filter-==\",\"a\",1.0]");
}
TEST(Stringify, CameraFunction) {
diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp
index 49edcaef45..c59a73eab1 100644
--- a/test/style/filter.test.cpp
+++ b/test/style/filter.test.cpp
@@ -4,7 +4,6 @@
#include <mbgl/test/stub_geometry_tile_feature.hpp>
#include <mbgl/style/filter.hpp>
-#include <mbgl/style/filter_evaluator.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/filter.hpp>
@@ -28,6 +27,24 @@ bool filter(const char * json,
return (*filter)(context);
}
+void invalidFilter(const char * json) {
+ conversion::Error error;
+ optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
+ EXPECT_FALSE(bool(filter));
+ EXPECT_NE(error.message, "");
+}
+
+TEST(Filter, EqualsNull) {
+ auto f = R"(["==", "foo", null])";
+ ASSERT_TRUE(filter(f, {{ "foo", mapbox::geometry::null_value }}));
+
+ ASSERT_FALSE(filter(f, {{ "foo", int64_t(0) }}));
+ ASSERT_FALSE(filter(f, {{ "foo", int64_t(1) }}));
+ ASSERT_FALSE(filter(f, {{ "foo", std::string("0") }}));
+ ASSERT_FALSE(filter(f, {{ "foo", true }}));
+ ASSERT_FALSE(filter(f, {{ "foo", false }}));
+ ASSERT_FALSE(filter(f, {{ }}));
+}
TEST(Filter, EqualsString) {
auto f = R"(["==", "foo", "bar"])";
ASSERT_TRUE(filter(f, {{ "foo", std::string("bar") }}));
@@ -53,6 +70,12 @@ TEST(Filter, EqualsType) {
auto f = R"(["==", "$type", "LineString"])";
ASSERT_FALSE(filter(f, {{}}, {}, FeatureType::Point, {}));
ASSERT_TRUE(filter(f, {{}}, {}, FeatureType::LineString, {}));
+ ASSERT_FALSE(filter(f, {{}}, {}, FeatureType::Point, {}));
+
+ invalidFilter("[\"==\", \"$type\"]");
+ invalidFilter("[\"==\", \"$type\", null]");
+ invalidFilter("[\"==\", \"$type\", \"foo\", 1]");
+ invalidFilter("[\"==\", \"$type\", \"foo\", \"Point\"]");
}
TEST(Filter, InType) {
@@ -62,6 +85,14 @@ TEST(Filter, InType) {
ASSERT_TRUE(filter(f, {{}}, {}, FeatureType::Polygon));
}
+TEST(Filter, InID) {
+ auto f = R"(["in", "$id", "123", "1234", 1234])";
+ ASSERT_FALSE(filter(f));
+ ASSERT_TRUE(filter(f, {{}}, { uint64_t(1234) }));
+ ASSERT_TRUE(filter(f, {{}}, { std::string("1234") }));
+ ASSERT_FALSE(filter(f, {{}}, { std::string("4321") }));
+}
+
TEST(Filter, Any) {
ASSERT_FALSE(filter("[\"any\"]"));
ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
@@ -69,6 +100,13 @@ TEST(Filter, Any) {
ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
}
+TEST(Filter, AnyExpression) {
+ ASSERT_FALSE(filter("[\"any\"]"));
+ ASSERT_TRUE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
+ ASSERT_FALSE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 0]]", {{ std::string("foo"), int64_t(1) }}));
+ ASSERT_TRUE(filter("[\"any\", [\"==\", [\"get\", \"foo\"], 0], [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
+}
+
TEST(Filter, All) {
ASSERT_TRUE(filter("[\"all\"]", {{}}));
ASSERT_TRUE(filter("[\"all\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
@@ -76,6 +114,12 @@ TEST(Filter, All) {
ASSERT_FALSE(filter("[\"all\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
}
+TEST(Filter, AllExpression) {
+ ASSERT_TRUE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
+ ASSERT_FALSE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 0]]", {{ std::string("foo"), int64_t(1) }}));
+ ASSERT_FALSE(filter("[\"all\", [\"==\", [\"get\", \"foo\"], 0], [\"==\", [\"get\", \"foo\"], 1]]", {{ std::string("foo"), int64_t(1) }}));
+}
+
TEST(Filter, None) {
ASSERT_TRUE(filter("[\"none\"]"));
ASSERT_FALSE(filter("[\"none\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }}));
@@ -88,6 +132,7 @@ TEST(Filter, Has) {
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{ std::string("foo"), int64_t(0) }}));
ASSERT_TRUE(filter("[\"has\", \"foo\"]", {{ std::string("foo"), false }}));
ASSERT_FALSE(filter("[\"has\", \"foo\"]"));
+ ASSERT_FALSE(filter("[\"has\", \"$id\"]"));
}
TEST(Filter, NotHas) {
@@ -101,7 +146,11 @@ TEST(Filter, ID) {
FeatureIdentifier id1 { uint64_t{ 1234 } };
ASSERT_TRUE(filter("[\"==\", \"$id\", 1234]", {{}}, id1));
ASSERT_FALSE(filter("[\"==\", \"$id\", \"1234\"]", {{}}, id1));
-
+
+ FeatureIdentifier id2 { std::string{ "1" } };
+ ASSERT_FALSE(filter("[\"<\", \"$id\", \"0\"]", {{}}, id2));
+ ASSERT_TRUE(filter("[\"<\", \"$id\", \"1234\"]", {{}}, id2));
+
ASSERT_FALSE(filter("[\"==\", \"$id\", 1234]", {{ "id", uint64_t(1234) }}));
}
@@ -115,6 +164,18 @@ TEST(Filter, PropertyExpression) {
ASSERT_FALSE(filter("[\"==\", [\"get\", \"two\"], 4]", {{"two", int64_t(2)}}));
}
+TEST(Filter, LegacyProperty) {
+ ASSERT_TRUE(filter("[\"<=\", \"two\", 2]", {{"two", int64_t(2)}}));
+ ASSERT_FALSE(filter("[\"==\", \"two\", 4]", {{"two", int64_t(2)}}));
+
+ ASSERT_FALSE(filter("[\"<=\", \"two\", \"2\"]", {{"two", int64_t(2)}}));
+ ASSERT_FALSE(filter("[\"==\", \"bool\", false]", {{"two", true}}));
+
+ ASSERT_TRUE(filter("[\"<=\", \"two\", \"2\"]", {{"two", std::string("2")}}));
+ ASSERT_FALSE(filter("[\"<\", \"two\", \"1\"]", {{"two", std::string("2")}}));
+ ASSERT_FALSE(filter("[\"==\", \"two\", 4]", {{"two", std::string("2")}}));
+}
+
TEST(Filter, ZoomExpressionNested) {
ASSERT_TRUE(filter(R"(["==", ["get", "two"], ["zoom"]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f));
ASSERT_FALSE(filter(R"(["==", ["get", "two"], ["+", ["zoom"], 1]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f));
diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp
index 77acca2868..624ed088c3 100644
--- a/test/style/style_layer.test.cpp
+++ b/test/style/style_layer.test.cpp
@@ -211,7 +211,7 @@ TEST(Layer, Observer) {
EXPECT_EQ(layer.get(), &layer_);
filterChanged = true;
};
- layer->setFilter(NullFilter());
+ layer->setFilter(Filter());
EXPECT_TRUE(filterChanged);
// Notifies observer on visibility change.