summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/api/query.test.cpp15
-rw-r--r--test/renderer/group_by_layout.test.cpp5
-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
5 files changed, 84 insertions, 12 deletions
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index c67ff9064c..ffab52692b 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -13,6 +13,7 @@
using namespace mbgl;
using namespace mbgl::style;
+using namespace mbgl::style::expression;
namespace {
@@ -67,18 +68,19 @@ TEST(Query, QueryRenderedFeaturesFilterLayer) {
TEST(Query, QueryRenderedFeaturesFilter) {
QueryTest test;
+ ParsingContext context;
auto zz = test.map.pixelForLatLng({ 0, 0 });
- const EqualsFilter eqFilter = { "key1", std::string("value1") };
+ const Filter eqFilter(createCompoundExpression("filter-==", createLiteral("key1"), createLiteral("value1"), context));
auto features1 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{}, { eqFilter }});
EXPECT_EQ(features1.size(), 1u);
- const IdentifierNotEqualsFilter idNotEqFilter = { std::string("feature1") };
+ const Filter idNotEqFilter(createCompoundExpression("!", std::move(*createCompoundExpression("filter-id-==", createLiteral("feature1"), context)), context));
auto features2 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{{ "layer4" }}, { idNotEqFilter }});
EXPECT_EQ(features2.size(), 0u);
- const GreaterThanFilter gtFilter = { "key2", 1.0 };
+ const Filter gtFilter(createCompoundExpression("filter->", createLiteral("key2"), createLiteral(1.0), context));
auto features3 = test.frontend.getRenderer()->queryRenderedFeatures(zz, {{ }, { gtFilter }});
EXPECT_EQ(features3.size(), 1u);
}
@@ -108,16 +110,17 @@ TEST(Query, QuerySourceFeaturesOptionValidation) {
TEST(Query, QuerySourceFeaturesFilter) {
QueryTest test;
+ ParsingContext context;
- const EqualsFilter eqFilter = { "key1", std::string("value1") };
+ const Filter eqFilter(createCompoundExpression("filter-==", createLiteral("key1"), createLiteral("value1"), context));
auto features1 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { eqFilter }});
EXPECT_EQ(features1.size(), 1u);
- const IdentifierNotEqualsFilter idNotEqFilter = { std::string("feature1") };
+ const Filter idNotEqFilter(createCompoundExpression("!", std::move(*createCompoundExpression("filter-id-==", createLiteral("feature1"), context)), context));
auto features2 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { idNotEqFilter }});
EXPECT_EQ(features2.size(), 0u);
- const GreaterThanFilter gtFilter = { "key2", 1.0 };
+ const Filter gtFilter(createCompoundExpression("filter->", createLiteral("key2"), createLiteral(1.0), context));
auto features3 = test.frontend.getRenderer()->querySourceFeatures("source4", {{}, { gtFilter }});
EXPECT_EQ(features3.size(), 1u);
}
diff --git a/test/renderer/group_by_layout.test.cpp b/test/renderer/group_by_layout.test.cpp
index 958f1bdf24..6cf17e2279 100644
--- a/test/renderer/group_by_layout.test.cpp
+++ b/test/renderer/group_by_layout.test.cpp
@@ -5,9 +5,11 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
+#include <mbgl/style/expression/compound_expression.hpp>
using namespace mbgl;
using namespace mbgl::style;
+using namespace mbgl::style::expression;
static std::vector<std::unique_ptr<RenderLayer>> toRenderLayers(const std::vector<std::unique_ptr<Layer>>& layers) {
std::vector<std::unique_ptr<RenderLayer>> result;
@@ -39,7 +41,8 @@ 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());
+ ParsingContext context;
+ layers[0]->as<LineLayer>()->setFilter(Filter(createCompoundExpression("filter-has-id", context)));
auto result = groupByLayout(toRenderLayers(layers));
ASSERT_EQ(2u, result.size());
}
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.