From 1d7a5b0fe0bc3d69cc77cfb654876ad3db2ea33a Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 24 Aug 2016 19:57:16 +0300 Subject: [tests] Add unit test for style loading failures --- include/mbgl/platform/default/headless_view.hpp | 4 ++++ platform/default/headless_view.cpp | 6 +++++ test/map/map.cpp | 32 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index 989c226694..89716643d4 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -43,10 +43,12 @@ public: void invalidate() override; void activate() override; void deactivate() override; + void notifyMapChange(MapChange) override; PremultipliedImage readStillImage() override; void resize(uint16_t width, uint16_t height); + void setMapChangeCallback(std::function&& cb) { mapChangeCallback = std::move(cb); } private: // Implementation specific functions @@ -85,6 +87,8 @@ private: GLXPbuffer glxPbuffer = 0; #endif + std::function mapChangeCallback; + GLuint fbo = 0; GLuint fboDepthStencil = 0; GLuint fboColor = 0; diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 13ea78a709..28c300b41e 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -107,4 +107,10 @@ void HeadlessView::invalidate() { assert(false); } +void HeadlessView::notifyMapChange(MapChange change) { + if (mapChangeCallback) { + mapChangeCallback(change); + } +} + } // namespace mbgl diff --git a/test/map/map.cpp b/test/map/map.cpp index 7e0bbd0234..314fb947f7 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -60,11 +60,20 @@ TEST(Map, SetStyleInvalidJSON) { Log::setObserver(std::make_unique()); + bool fail = false; + test.view.setMapChangeCallback([&](MapChange change) { + if (change == mbgl::MapChangeDidFailLoadingMap) { + fail = true; + } + }); + { Map map(test.view, test.fileSource, MapMode::Still); map.setStyleJSON("invalid"); } + EXPECT_TRUE(fail); + auto observer = Log::removeObserver(); auto flo = dynamic_cast(observer.get()); EXPECT_EQ(1u, flo->count({ EventSeverity::Error, Event::ParseStyle, -1, @@ -73,6 +82,29 @@ TEST(Map, SetStyleInvalidJSON) { EXPECT_TRUE(unchecked.empty()) << unchecked; } +TEST(Map, SetStyleInvalidURL) { + MapTest test; + + test.fileSource.styleResponse = [] (const Resource&) { + Response response; + response.error = std::make_unique( + Response::Error::Reason::Other, + "Failed by the test case"); + return response; + }; + + test.view.setMapChangeCallback([&](MapChange change) { + if (change == mbgl::MapChangeDidFailLoadingMap) { + test.runLoop.stop(); + } + }); + + Map map(test.view, test.fileSource, MapMode::Still); + map.setStyleURL("mapbox://bar"); + + test.runLoop.run(); +} + TEST(Map, DoubleStyleLoad) { MapTest test; -- cgit v1.2.1