From fc70cbf1e12e27737c7a256682524cd617d18f71 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 13 Mar 2017 16:16:38 +0200 Subject: [core] Replace MapChange enum with MapObserver --- test/map/map.test.cpp | 70 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'test/map/map.test.cpp') diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 618c2e6a74..c5d579be3a 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -24,9 +24,37 @@ using namespace mbgl; using namespace mbgl::style; using namespace std::literals::string_literals; +class BackendTest : public HeadlessBackend { +public: + BackendTest() : HeadlessBackend(test::sharedDisplay()) {} + + void setDidFailLoadingMapCallback(std::function&& callback) { + didFailLoadingMapCallback = std::move(callback); + } + + void setDidFinishLoadingStyleCallback(std::function&& callback) { + didFinishLoadingStyleCallback = std::move(callback); + } + + void onDidFailLoadingMap() final { + if (didFailLoadingMapCallback) { + didFailLoadingMapCallback(); + } + } + + void onDidFinishLoadingStyle() final { + if (didFinishLoadingStyleCallback) { + didFinishLoadingStyleCallback(); + } + } + + std::function didFailLoadingMapCallback; + std::function didFinishLoadingStyleCallback; +}; + struct MapTest { util::RunLoop runLoop; - HeadlessBackend backend { test::sharedDisplay() }; + BackendTest backend; OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; @@ -85,10 +113,8 @@ TEST(Map, SetStyleInvalidJSON) { Log::setObserver(std::make_unique()); bool fail = false; - test.backend.setMapChangeCallback([&](MapChange change) { - if (change == mbgl::MapChangeDidFailLoadingMap) { - fail = true; - } + test.backend.setDidFailLoadingMapCallback([&]() { + fail = true; }); { @@ -118,10 +144,8 @@ TEST(Map, SetStyleInvalidURL) { return response; }; - test.backend.setMapChangeCallback([&](MapChange change) { - if (change == mbgl::MapChangeDidFailLoadingMap) { - test.runLoop.stop(); - } + test.backend.setDidFailLoadingMapCallback([&]() { + test.runLoop.stop(); }); Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); @@ -233,10 +257,8 @@ TEST(Map, StyleLoadedSignal) { // The map should emit a signal on style loaded bool emitted = false; - test.backend.setMapChangeCallback([&](MapChange change) { - if (change == mbgl::MapChangeDidFinishLoadingStyle) { - emitted = true; - } + test.backend.setDidFinishLoadingStyleCallback([&]() { + emitted = true; }); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); EXPECT_TRUE(emitted); @@ -255,10 +277,8 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNetworkErrorRetry)) { Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.setStyleURL("http://127.0.0.1:3000/style-fail-once-500"); - test.backend.setMapChangeCallback([&](MapChange change) { - if (change == mbgl::MapChangeDidFinishLoadingStyle) { - test.runLoop.stop(); - } + test.backend.setDidFinishLoadingStyleCallback([&]() { + test.runLoop.stop(); }); test.runLoop.run(); @@ -275,16 +295,14 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) { util::Timer timer; // Not found errors should not trigger a retry like other errors. - test.backend.setMapChangeCallback([&](MapChange change) { - if (change == mbgl::MapChangeDidFinishLoadingStyle) { - FAIL() << "Should not retry on not found!"; - } + test.backend.setDidFinishLoadingStyleCallback([&]() { + FAIL() << "Should not retry on not found!"; + }); - if (change == mbgl::MapChangeDidFailLoadingMap) { - timer.start(Milliseconds(1100), 0s, [&] { - test.runLoop.stop(); - }); - } + test.backend.setDidFailLoadingMapCallback([&]() { + timer.start(Milliseconds(1100), 0s, [&] { + test.runLoop.stop(); + }); }); test.runLoop.run(); -- cgit v1.2.1