diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-06-13 10:50:16 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-07-18 10:45:12 +0200 |
commit | 57351c068b133ed140ac7b991181672019fe5c24 (patch) | |
tree | 2a0be8819c2bc57b1cda7d5c6f98e725a030daa2 /test | |
parent | e35cbbae55ab01f33690b1bb2e918c5f8393b854 (diff) | |
download | qtlocation-mapboxgl-57351c068b133ed140ac7b991181672019fe5c24.tar.gz |
[core] split backend from mapobserver
Diffstat (limited to 'test')
-rw-r--r-- | test/api/annotations.test.cpp | 2 | ||||
-rw-r--r-- | test/api/api_misuse.test.cpp | 2 | ||||
-rw-r--r-- | test/api/custom_layer.test.cpp | 2 | ||||
-rw-r--r-- | test/api/query.test.cpp | 2 | ||||
-rw-r--r-- | test/api/render_missing.test.cpp | 2 | ||||
-rw-r--r-- | test/api/repeated_render.test.cpp | 4 | ||||
-rw-r--r-- | test/map/map.test.cpp | 110 | ||||
-rw-r--r-- | test/map/prefetch.test.cpp | 2 | ||||
-rw-r--r-- | test/util/memory.test.cpp | 16 |
9 files changed, 67 insertions, 75 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index 7594d5ed73..42fbcc0a8b 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -33,7 +33,7 @@ public: OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; - Map map { backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still }; + Map map { backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still }; void checkRendering(const char * name) { test::checkImage(std::string("test/fixtures/annotations/") + name, diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp index 54cde8d9b5..e5498576a8 100644 --- a/test/api/api_misuse.test.cpp +++ b/test/api/api_misuse.test.cpp @@ -29,7 +29,7 @@ TEST(API, RenderWithoutCallback) { ThreadPool threadPool(4); std::unique_ptr<Map> map = - std::make_unique<Map>(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + std::make_unique<Map>(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); map->renderStill(view, nullptr); // Force Map thread to join. diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index 2b1138a1d3..b5d94f2786 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -93,7 +93,7 @@ TEST(CustomLayer, Basic) { DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); ThreadPool threadPool(4); - Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); map.setLatLngZoom({ 37.8, -122.5 }, 10); map.getStyle().addLayer(std::make_unique<CustomLayer>( diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index 0b6d75ec4f..0b02e47219 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -33,7 +33,7 @@ public: OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; - Map map { backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still }; + Map map { backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still }; }; } // end namespace diff --git a/test/api/render_missing.test.cpp b/test/api/render_missing.test.cpp index 2e0c4401f4..9cba1dcac7 100644 --- a/test/api/render_missing.test.cpp +++ b/test/api/render_missing.test.cpp @@ -35,7 +35,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { Log::setObserver(std::make_unique<FixtureLogObserver>()); - Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); std::string message; diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp index dd9085efd7..033b741ab6 100644 --- a/test/api/repeated_render.test.cpp +++ b/test/api/repeated_render.test.cpp @@ -33,7 +33,7 @@ TEST(API, RepeatedRender) { Log::setObserver(std::make_unique<FixtureLogObserver>()); - Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); { map.getStyle().loadJSON(style); @@ -86,7 +86,7 @@ TEST(API, ZoomHistory) { Log::setObserver(std::make_unique<FixtureLogObserver>()); - Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); map.getStyle().loadJSON(style); auto geojson = mapbox::geojson::parse(R"t({ "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ -150, -75 ], [ 150, 75 ] ] } } ] })t"); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index a820590fb4..206371613d 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -25,42 +25,46 @@ using namespace mbgl; using namespace mbgl::style; using namespace std::literals::string_literals; -class BackendTest : public HeadlessBackend { +class MockBackend : public HeadlessBackend { public: - BackendTest() : HeadlessBackend(test::sharedDisplay()) {} + MockBackend() + : HeadlessBackend(test::sharedDisplay() ) { + } - void invalidate() { - if (invalidateCallback) { - invalidateCallback(); + std::function<void()> callback; + void invalidate() override { + if (callback) { + callback(); } } +}; - std::function<void()> invalidateCallback; - +class StubMapObserver : public MapObserver { +public: void onWillStartLoadingMap() final { if (onWillStartLoadingMapCallback) { onWillStartLoadingMapCallback(); } } - + void onDidFinishLoadingMap() final { if (onDidFinishLoadingMapCallback) { onDidFinishLoadingMapCallback(); } } - + void onDidFailLoadingMap(std::exception_ptr) final { if (didFailLoadingMapCallback) { didFailLoadingMapCallback(); } } - + void onDidFinishLoadingStyle() final { if (didFinishLoadingStyleCallback) { didFinishLoadingStyleCallback(); } } - + std::function<void()> onWillStartLoadingMapCallback; std::function<void()> onDidFinishLoadingMapCallback; std::function<void()> didFailLoadingMapCallback; @@ -69,7 +73,8 @@ public: struct MapTest { util::RunLoop runLoop; - BackendTest backend; + MockBackend backend; + StubMapObserver observer; BackendScope scope { backend }; OffscreenView view { backend.getContext() }; StubFileSource fileSource; @@ -78,7 +83,7 @@ struct MapTest { TEST(Map, LatLngBehavior) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setLatLngZoom({ 1, 1 }, 0); auto latLng1 = map.getLatLng(); @@ -92,7 +97,7 @@ TEST(Map, LatLngBehavior) { TEST(Map, LatLngBoundsToCamera) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setLatLngZoom({ 40.712730, -74.005953 }, 16.0); @@ -104,7 +109,7 @@ TEST(Map, LatLngBoundsToCamera) { TEST(Map, CameraToLatLngBounds) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setLatLngZoom({ 45, 90 }, 16); @@ -143,7 +148,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(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL(prefix + "style.json"); test::checkImage("test/fixtures/map/offline", @@ -160,12 +165,12 @@ TEST(Map, SetStyleInvalidJSON) { Log::setObserver(std::make_unique<FixtureLogObserver>()); bool fail = false; - test.backend.didFailLoadingMapCallback = [&]() { + test.observer.didFailLoadingMapCallback = [&]() { fail = true; }; { - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadJSON("invalid"); } @@ -191,11 +196,11 @@ TEST(Map, SetStyleInvalidURL) { return response; }; - test.backend.didFailLoadingMapCallback = [&]() { + test.observer.didFailLoadingMapCallback = [&]() { test.runLoop.stop(); }; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://bar"); test.runLoop.run(); @@ -204,7 +209,7 @@ TEST(Map, SetStyleInvalidURL) { TEST(Map, DoubleStyleLoad) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadJSON(""); map.getStyle().loadJSON(""); } @@ -215,7 +220,7 @@ TEST(Map, StyleFresh) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -235,7 +240,7 @@ TEST(Map, StyleExpired) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -262,7 +267,7 @@ TEST(Map, StyleExpiredWithAnnotations) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -288,7 +293,7 @@ TEST(Map, StyleExpiredWithRender) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://styles/test"); EXPECT_EQ(1u, fileSource.requests.size()); @@ -312,7 +317,7 @@ TEST(Map, StyleEarlyMutation) { MapTest test; FakeFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://styles/test"); map.getStyle().addLayer(std::make_unique<style::BackgroundLayer>("bg")); @@ -326,10 +331,10 @@ TEST(Map, StyleEarlyMutation) { TEST(Map, MapLoadingSignal) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); bool emitted = false; - test.backend.onWillStartLoadingMapCallback = [&]() { + test.observer.onWillStartLoadingMapCallback = [&]() { emitted = true; }; map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); @@ -338,13 +343,13 @@ TEST(Map, MapLoadingSignal) { TEST(Map, MapLoadedSignal) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Continuous); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Continuous); - test.backend.onDidFinishLoadingMapCallback = [&]() { + test.observer.onDidFinishLoadingMapCallback = [&]() { test.runLoop.stop(); }; - test.backend.invalidateCallback = [&]() { + test.backend.callback = [&]() { map.render(test.view); }; @@ -354,11 +359,11 @@ TEST(Map, MapLoadedSignal) { TEST(Map, StyleLoadedSignal) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); // The map should emit a signal on style loaded bool emitted = false; - test.backend.didFinishLoadingStyleCallback = [&]() { + test.observer.didFinishLoadingStyleCallback = [&]() { emitted = true; }; map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); @@ -375,10 +380,10 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNetworkErrorRetry)) { MapTest test; OnlineFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-500"); - test.backend.didFinishLoadingStyleCallback = [&]() { + test.observer.didFinishLoadingStyleCallback = [&]() { test.runLoop.stop(); }; @@ -389,18 +394,18 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) { MapTest test; OnlineFileSource fileSource; - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-404"); using namespace std::chrono_literals; util::Timer timer; // Not found errors should not trigger a retry like other errors. - test.backend.didFinishLoadingStyleCallback = [&]() { + test.observer.didFinishLoadingStyleCallback = [&]() { FAIL() << "Should not retry on not found!"; }; - test.backend.didFailLoadingMapCallback = [&]() { + test.observer.didFailLoadingMapCallback = [&]() { timer.start(Milliseconds(1100), 0s, [&] { test.runLoop.stop(); }); @@ -416,7 +421,7 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) { TEST(Map, AddLayer) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); auto layer = std::make_unique<BackgroundLayer>("background"); @@ -433,7 +438,7 @@ TEST(Map, WithoutVAOExtension) { DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); - Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); test::checkImage("test/fixtures/map/no_vao", test::render(map, test.view), 0.002); @@ -442,7 +447,7 @@ TEST(Map, WithoutVAOExtension) { TEST(Map, RemoveLayer) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); auto layer = std::make_unique<BackgroundLayer>("background"); @@ -467,7 +472,7 @@ TEST(Map, DisabledSources) { return {}; }; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.setZoom(1); // This stylesheet has two raster layers, one that starts at zoom 1, the other at zoom 0. @@ -517,7 +522,7 @@ TEST(Map, DisabledSources) { TEST(Map, DontLoadUnneededTiles) { MapTest test; - Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, test.observer, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadJSON(R"STYLE({ "sources": { "a": { "type": "vector", "tiles": [ "a/{z}/{x}/{y}" ] } @@ -562,29 +567,14 @@ TEST(Map, DontLoadUnneededTiles) { } } - -class MockBackend : public HeadlessBackend { -public: - MockBackend(std::shared_ptr<HeadlessDisplay> display_) - : HeadlessBackend(display_) { - } - - std::function<void()> callback; - void invalidate() override { - if (callback) { - callback(); - } - } -}; - TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { util::RunLoop runLoop; - MockBackend backend { test::sharedDisplay() }; + MockBackend backend; BackendScope scope { backend }; OffscreenView view { backend.getContext() }; ThreadPool threadPool { 4 }; DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); - Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Continuous); + Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Continuous); using namespace std::chrono_literals; diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp index af2cd4e92f..47b39f7b88 100644 --- a/test/map/prefetch.test.cpp +++ b/test/map/prefetch.test.cpp @@ -27,7 +27,7 @@ TEST(Map, PrefetchTiles) { OffscreenView view(backend.getContext(), { 512, 512 }); ThreadPool threadPool(4); StubFileSource fileSource; - Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); + Map map(backend, MapObserver::nullObserver(), view.getSize(), 1, fileSource, threadPool, MapMode::Still); std::vector<int> tiles; diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index bca538c6c6..8fd27f2462 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -74,7 +74,7 @@ private: TEST(Memory, Vector) { MemoryTest test; - Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, MapObserver::nullObserver(), { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still); map.setZoom(16); // more map features map.getStyle().loadURL("mapbox://streets"); @@ -84,7 +84,7 @@ TEST(Memory, Vector) { TEST(Memory, Raster) { MemoryTest test; - Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, MapObserver::nullObserver(), { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still); map.getStyle().loadURL("mapbox://satellite"); test::render(map, test.view); @@ -125,7 +125,7 @@ TEST(Memory, Footprint) { // Warm up buffers and cache. for (unsigned i = 0; i < 10; ++i) { - Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still); + Map map(test.backend, MapObserver::nullObserver(), { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still); renderMap(map, "mapbox://streets"); renderMap(map, "mapbox://satellite"); }; @@ -139,8 +139,9 @@ TEST(Memory, Footprint) { long vectorInitialRSS = mbgl::test::getCurrentRSS(); for (unsigned i = 0; i < runs; ++i) { - auto vector = std::make_unique<Map>(test.backend, Size{ 256, 256 }, 2, test.fileSource, - test.threadPool, MapMode::Still); + auto vector = std::make_unique<Map>(test.backend, MapObserver::nullObserver(), + Size{ 256, 256 }, 2, test.fileSource, test.threadPool, + MapMode::Still); renderMap(*vector, "mapbox://streets"); maps.push_back(std::move(vector)); }; @@ -149,8 +150,9 @@ TEST(Memory, Footprint) { long rasterInitialRSS = mbgl::test::getCurrentRSS(); for (unsigned i = 0; i < runs; ++i) { - auto raster = std::make_unique<Map>(test.backend, Size{ 256, 256 }, 2, test.fileSource, - test.threadPool, MapMode::Still); + auto raster = std::make_unique<Map>(test.backend, MapObserver::nullObserver(), + Size{ 256, 256 }, 2, test.fileSource, test.threadPool, + MapMode::Still); renderMap(*raster, "mapbox://satellite"); maps.push_back(std::move(raster)); }; |