From 1520a56813f82bbe875774fdc2b3df26392278d6 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Apr 2017 13:35:34 -0700 Subject: [all] Promote Style to public API --- test/api/custom_layer.test.cpp | 5 ++-- test/api/query.test.cpp | 3 ++- test/map/map.test.cpp | 57 ++++++----------------------------------- test/style/style.test.cpp | 8 +++--- test/style/style_layer.test.cpp | 4 +-- 5 files changed, 19 insertions(+), 58 deletions(-) (limited to 'test') diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index 5a30220cd7..e11ed299a6 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -95,7 +96,7 @@ TEST(CustomLayer, Basic) { Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/water.json")); map.setLatLngZoom({ 37.8, -122.5 }, 10); - map.addLayer(std::make_unique( + map.getStyle().addLayer(std::make_unique( "custom", [] (void* context) { reinterpret_cast(context)->initialize(); @@ -110,7 +111,7 @@ TEST(CustomLayer, Basic) { auto layer = std::make_unique("landcover", "mapbox"); layer->setSourceLayer("landcover"); layer->setFillColor(Color{ 1.0, 1.0, 0.0, 1.0 }); - map.addLayer(std::move(layer)); + map.getStyle().addLayer(std::move(layer)); test::checkImage("test/fixtures/custom_layer/basic", test::render(map, view), 0.0006, 0.1); } diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index 5b7f7c00ff..ad4dc6f4de 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -20,7 +21,7 @@ class QueryTest { public: QueryTest() { map.setStyleJSON(util::read_file("test/fixtures/api/query_style.json")); - map.addImage(std::make_unique("test-icon", + map.getStyle().addImage(std::make_unique("test-icon", decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")), 1.0)); test::render(map, view); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 0ff828ce40..9045f1c8c2 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -247,12 +248,12 @@ TEST(Map, StyleExpired) { fileSource.respond(Resource::Style, response); EXPECT_EQ(1u, fileSource.requests.size()); - map.addLayer(std::make_unique("bg")); + map.getStyle().addLayer(std::make_unique("bg")); EXPECT_EQ(1u, fileSource.requests.size()); fileSource.respond(Resource::Style, response); EXPECT_EQ(0u, fileSource.requests.size()); - EXPECT_NE(nullptr, map.getLayer("bg")); + EXPECT_NE(nullptr, map.getStyle().getLayer("bg")); } TEST(Map, StyleExpiredWithAnnotations) { @@ -289,14 +290,14 @@ TEST(Map, StyleEarlyMutation) { Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL("mapbox://styles/test"); - map.addLayer(std::make_unique("bg")); + map.getStyle().addLayer(std::make_unique("bg")); Response response; response.data = std::make_shared(util::read_file("test/fixtures/api/water.json")); fileSource.respond(Resource::Style, response); EXPECT_EQ(0u, fileSource.requests.size()); - EXPECT_NE(nullptr, map.getLayer("water")); + EXPECT_NE(nullptr, map.getStyle().getLayer("water")); } TEST(Map, MapLoadingSignal) { @@ -396,7 +397,7 @@ TEST(Map, AddLayer) { auto layer = std::make_unique("background"); layer->setBackgroundColor({ { 1, 0, 0, 1 } }); - map.addLayer(std::move(layer)); + map.getStyle().addLayer(std::move(layer)); test::checkImage("test/fixtures/map/add_layer", test::render(map, test.view)); } @@ -422,8 +423,8 @@ TEST(Map, RemoveLayer) { auto layer = std::make_unique("background"); layer->setBackgroundColor({{ 1, 0, 0, 1 }}); - map.addLayer(std::move(layer)); - map.removeLayer("background"); + map.getStyle().addLayer(std::move(layer)); + map.getStyle().removeLayer("background"); test::checkImage("test/fixtures/map/remove_layer", test::render(map, test.view)); } @@ -489,48 +490,6 @@ TEST(Map, DisabledSources) { test::checkImage("test/fixtures/map/disabled_layers/second", test::render(map, test.view)); } -TEST(Map, AddImage) { - MapTest test; - - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); - auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); - auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); - auto image1 = std::make_unique("test-icon", std::move(decoded1), 1.0); - auto image2 = std::make_unique("test-icon", std::move(decoded2), 1.0); - - // No-op. - map.addImage(std::move(image1)); - - map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); - map.addImage(std::move(image2)); - test::checkImage("test/fixtures/map/add_icon", test::render(map, test.view)); -} - -TEST(Map, RemoveImage) { - MapTest test; - - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); - auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); - auto image = std::make_unique("test-icon", std::move(decoded), 1.0); - - map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); - map.addImage(std::move(image)); - map.removeImage("test-icon"); - test::checkImage("test/fixtures/map/remove_icon", test::render(map, test.view)); -} - -TEST(Map, GetImage) { - MapTest test; - - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); - auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); - auto image = std::make_unique("test-icon", std::move(decoded), 1.0); - - map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); - map.addImage(std::move(image)); - test::checkImage("test/fixtures/map/get_icon", map.getImage("test-icon")->getImage()); -} - TEST(Map, DontLoadUnneededTiles) { MapTest test; diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index 841c7b291b..701e4a6434 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -21,7 +21,7 @@ TEST(Style, Properties) { ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; style.setJSON(R"STYLE({"name": "Test"})STYLE"); ASSERT_EQ("Test", style.getName()); @@ -56,7 +56,7 @@ TEST(Style, DuplicateSource) { ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); @@ -78,7 +78,7 @@ TEST(Style, RemoveSourceInUse) { ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index 7d0eb318c0..0e7957c490 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -275,7 +275,7 @@ TEST(Layer, DuplicateLayer) { // Setup style ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); // Add initial layer -- cgit v1.2.1