From ba4a8a97316d65ab595bb7edf759f463bbd10049 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 14:44:46 -0700 Subject: [PATCH] [tests] Add basic tests for Map::{add,remove}Layer --- test/fixtures/map/add_layer/expected.png | Bin 0 -> 1685 bytes test/fixtures/map/remove_layer/expected.png | Bin 0 -> 1238 bytes test/map/map.cpp | 48 ++++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/map/add_layer/expected.png create mode 100644 test/fixtures/map/remove_layer/expected.png diff --git a/test/fixtures/map/add_layer/expected.png b/test/fixtures/map/add_layer/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..8fa3f0f5db7e671b6a9be553b043aa739b6590a0 GIT binary patch literal 1685 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=C}ko-U3d z6^w7MF!C}e@Gu{2tUvG2)MMY&7&m>L@#lT+4Gw_`;?Adi8V-mXFz7WpL>ypfIW0c7 zfw6#@0UJjPE04pDnv0wg z4CW3BItdJio_6~kVA#RPl*q^|pch}l#CCvJfP-72q2T8tVFQM|hEXd<18OuyjpmEd f0%Qo5wBl>OG5_10B6Aj4&oFqp`njxgN@xNAq(%Fv literal 0 HcmV?d00001 diff --git a/test/fixtures/map/remove_layer/expected.png b/test/fixtures/map/remove_layer/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..04f8682f8806e2d9a513e366fb46fb1b2336a583 GIT binary patch literal 1238 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=Aw2JY5_^ zDj45hFa#+)wBW1%+iZ>whr|O7jLd925(WvQjL|?CO$np9fG)Y<12Z$D4FjXpE{9-X PX~f{^>gTe~DWM4f@<$XU literal 0 HcmV?d00001 diff --git a/test/map/map.cpp b/test/map/map.cpp index 4ee44ca61..c6f6843a0 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -8,15 +8,20 @@ #include #include #include +#include using namespace mbgl; using namespace std::literals::string_literals; -TEST(Map, Offline) { +struct MapTest { util::RunLoop runLoop; + std::shared_ptr display { std::make_shared() }; + HeadlessView view { display, 1 }; + StubFileSource fileSource; +}; - auto display = std::make_shared(); - HeadlessView view(display, 1); +TEST(Map, Offline) { + MapTest test; DefaultFileSource fileSource(":memory:", "."); auto expiredItem = [] (const std::string& path) { @@ -35,7 +40,7 @@ TEST(Map, Offline) { fileSource.put(Resource::glyphs(prefix + "{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("glyph.pbf")); NetworkStatus::Set(NetworkStatus::Status::Offline); - Map map(view, fileSource, MapMode::Still); + Map map(test.view, fileSource, MapMode::Still); map.setStyleURL(prefix + "style.json"); test::checkImage("test/fixtures/map/offline", @@ -47,13 +52,36 @@ TEST(Map, Offline) { } TEST(Map, DoubleStyleLoad) { - util::RunLoop runLoop; + MapTest test; - std::shared_ptr display = std::make_shared(); - HeadlessView view(display, 1, 512, 512); - StubFileSource fileSource; - - Map map(view, fileSource); + Map map(test.view, test.fileSource, MapMode::Still); map.setStyleJSON("", ""); map.setStyleJSON("", ""); } + +TEST(Map, AddLayer) { + MapTest test; + + Map map(test.view, test.fileSource, MapMode::Still); + map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + + auto layer = std::make_unique("background"); + layer->setBackgroundColor({{{ 1, 0, 0, 1 }}}); + map.addLayer(std::move(layer)); + + test::checkImage("test/fixtures/map/add_layer", test::render(map)); +} + +TEST(Map, RemoveLayer) { + MapTest test; + + Map map(test.view, test.fileSource, MapMode::Still); + map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + + auto layer = std::make_unique("background"); + layer->setBackgroundColor({{{ 1, 0, 0, 1 }}}); + map.addLayer(std::move(layer)); + map.removeLayer("background"); + + test::checkImage("test/fixtures/map/remove_layer", test::render(map)); +}