summaryrefslogtreecommitdiff
path: root/test/api/query.test.cpp
blob: d989d222c51a83650896e290eda170c0bda0282c (plain)
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
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/util.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>

using namespace mbgl;

namespace {

class QueryTest {
public:
    QueryTest() {
        auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
        auto image = std::make_unique<SpriteImage>(std::move(decoded), 1.0);

        map.setStyleJSON(util::read_file("test/fixtures/api/query_style.json"));
        map.addImage("test-icon", std::move(image));

        test::render(map);
    }

    util::RunLoop loop;
    HeadlessBackend backend;
    HeadlessView view;
    StubFileSource fileSource;
    ThreadPool threadPool { 4 };
    Map map { backend, view, view.getPixelRatio(), fileSource, threadPool, MapMode::Still };
};

} // end namespace

TEST(Query, QueryRenderedFeatures) {
    QueryTest test;

    auto features1 = test.map.queryRenderedFeatures(test.map.pixelForLatLng({ 0, 0 }));
    EXPECT_EQ(features1.size(), 3u);

    auto features2 = test.map.queryRenderedFeatures(test.map.pixelForLatLng({ 9, 9 }));
    EXPECT_EQ(features2.size(), 0u);
}

TEST(Query, QueryRenderedFeaturesFilterLayer) {
    QueryTest test;

    auto zz = test.map.pixelForLatLng({ 0, 0 });

    auto features1 = test.map.queryRenderedFeatures(zz, {{ "layer1"}});
    EXPECT_EQ(features1.size(), 1u);

    auto features2 = test.map.queryRenderedFeatures(zz, {{ "layer1", "layer2" }});
    EXPECT_EQ(features2.size(), 2u);

    auto features3 = test.map.queryRenderedFeatures(zz, {{ "foobar" }});
    EXPECT_EQ(features3.size(), 0u);

    auto features4 = test.map.queryRenderedFeatures(zz, {{ "foobar", "layer3" }});
    EXPECT_EQ(features4.size(), 1u);
}