summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheemm@gmail.com>2017-02-21 18:34:45 -0800
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-04 15:42:07 -0800
commit60d10dd27df38ac4e97214d1cd514198c381695c (patch)
treef4ce0ecbf3a7eeb5c19f994d02152fc624b458d9 /test
parentac4e13416a36905b35401fc1a982c680ca37a3d0 (diff)
downloadqtlocation-mapboxgl-60d10dd27df38ac4e97214d1cd514198c381695c.tar.gz
[core] Add support for queryRenderedFeatures filter
Diffstat (limited to 'test')
-rw-r--r--test/api/annotations.test.cpp2
-rw-r--r--test/api/query.test.cpp29
-rw-r--r--test/fixtures/api/query_style.json28
3 files changed, 53 insertions, 6 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 6644e9c92c..30027d8610 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -401,7 +401,7 @@ TEST(Annotations, VisibleFeatures) {
test.map.setBearing(45);
test::render(test.map, test.view);
- auto features = test.map.queryRenderedFeatures(box);
+ auto features = test.map.queryRenderedFeatures(box, {});
auto sortID = [](const Feature& lhs, const Feature& rhs) { return lhs.id < rhs.id; };
auto sameID = [](const Feature& lhs, const Feature& rhs) { return lhs.id == rhs.id; };
std::sort(features.begin(), features.end(), sortID);
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index 4d2bf00f67..b42046fb48 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -10,6 +10,7 @@
#include <mbgl/util/run_loop.hpp>
using namespace mbgl;
+using namespace mbgl::style;
namespace {
@@ -39,7 +40,7 @@ TEST(Query, QueryRenderedFeatures) {
QueryTest test;
auto features1 = test.map.queryRenderedFeatures(test.map.pixelForLatLng({ 0, 0 }));
- EXPECT_EQ(features1.size(), 3u);
+ EXPECT_EQ(features1.size(), 4u);
auto features2 = test.map.queryRenderedFeatures(test.map.pixelForLatLng({ 9, 9 }));
EXPECT_EQ(features2.size(), 0u);
@@ -50,15 +51,33 @@ TEST(Query, QueryRenderedFeaturesFilterLayer) {
auto zz = test.map.pixelForLatLng({ 0, 0 });
- auto features1 = test.map.queryRenderedFeatures(zz, {{ "layer1"}});
+ auto features1 = test.map.queryRenderedFeatures(zz, {{{ "layer1"}}, {}});
EXPECT_EQ(features1.size(), 1u);
- auto features2 = test.map.queryRenderedFeatures(zz, {{ "layer1", "layer2" }});
+ auto features2 = test.map.queryRenderedFeatures(zz, {{{ "layer1", "layer2" }}, {}});
EXPECT_EQ(features2.size(), 2u);
- auto features3 = test.map.queryRenderedFeatures(zz, {{ "foobar" }});
+ auto features3 = test.map.queryRenderedFeatures(zz, {{{ "foobar" }}, {}});
EXPECT_EQ(features3.size(), 0u);
- auto features4 = test.map.queryRenderedFeatures(zz, {{ "foobar", "layer3" }});
+ auto features4 = test.map.queryRenderedFeatures(zz, {{{ "foobar", "layer3" }}, {}});
EXPECT_EQ(features4.size(), 1u);
}
+
+TEST(Query, QueryRenderedFeaturesFilter) {
+ QueryTest test;
+
+ auto zz = test.map.pixelForLatLng({ 0, 0 });
+
+ const EqualsFilter eqFilter = { "key1", std::string("value1") };
+ auto features1 = test.map.queryRenderedFeatures(zz, {{}, { eqFilter }});
+ EXPECT_EQ(features1.size(), 1u);
+
+ const IdentifierNotEqualsFilter idNotEqFilter = { std::string("feature1") };
+ auto features2 = test.map.queryRenderedFeatures(zz, {{{ "layer4" }}, { idNotEqFilter }});
+ EXPECT_EQ(features2.size(), 0u);
+
+ const GreaterThanFilter gtFilter = { "key2", 1.0 };
+ auto features3 = test.map.queryRenderedFeatures(zz, {{ }, { gtFilter }});
+ EXPECT_EQ(features3.size(), 1u);
+}
diff --git a/test/fixtures/api/query_style.json b/test/fixtures/api/query_style.json
index 6978e1ba1b..4e11921775 100644
--- a/test/fixtures/api/query_style.json
+++ b/test/fixtures/api/query_style.json
@@ -30,6 +30,26 @@
0
]
}
+ },
+ "source4": {
+ "type": "geojson",
+ "data": {
+ "type": "Feature",
+ "id": "feature1",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ 0.0,
+ 0.0
+ ]
+ },
+ "properties": {
+ "key1": "value1",
+ "key2": 1.5,
+ "key3": false,
+ "key4": 0.5
+ }
+ }
}
},
"layers": [
@@ -56,6 +76,14 @@
"layout": {
"icon-image": "test-icon"
}
+ },
+ {
+ "id": "layer4",
+ "type": "symbol",
+ "source": "source4",
+ "layout": {
+ "icon-image": "test-icon"
+ }
}
]
}