diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-12-17 13:10:45 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-12-18 13:48:52 +0200 |
commit | 64a37ceb0547a6ac48196426c513a8fdd6e57f70 (patch) | |
tree | 84b436aed573d8509be1792f4e39c80b68b8834e /render-test | |
parent | 2fd9d4a1feee88741d2a869c1b6333085e7fe58e (diff) | |
download | qtlocation-mapboxgl-64a37ceb0547a6ac48196426c513a8fdd6e57f70.tar.gz |
[test runner] Rendering a single tile in Tile mode
Diffstat (limited to 'render-test')
-rw-r--r-- | render-test/parser.cpp | 5 | ||||
-rw-r--r-- | render-test/runner.cpp | 45 | ||||
-rw-r--r-- | render-test/runner.hpp | 1 |
3 files changed, 40 insertions, 11 deletions
diff --git a/render-test/parser.cpp b/render-test/parser.cpp index 7646b5b455..e58187eb15 100644 --- a/render-test/parser.cpp +++ b/render-test/parser.cpp @@ -497,9 +497,10 @@ TestMetadata parseTestMetadata(const TestPaths& paths, const Manifest& manifest) metadata.outputsImage = true; assert(testValue["mapMode"].IsString()); std::string mapModeStr = testValue["mapMode"].GetString(); - if (mapModeStr == "tile") + if (mapModeStr == "tile") { metadata.mapMode = mbgl::MapMode::Tile; - else if (mapModeStr == "continuous") { + metadata.size = {uint32_t(mbgl::util::tileSize), uint32_t(mbgl::util::tileSize)}; + } else if (mapModeStr == "continuous") { metadata.mapMode = mbgl::MapMode::Continuous; metadata.outputsImage = false; } else if (mapModeStr == "static") diff --git a/render-test/runner.cpp b/render-test/runner.cpp index af3948b123..7b356eb4de 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -10,8 +10,10 @@ #include <mbgl/util/chrono.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> +#include <mbgl/util/projection.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> +#include <mbgl/util/tile_cover.hpp> #include <mapbox/pixelmatch.hpp> @@ -628,7 +630,6 @@ void resetContext(const TestMetadata& metadata, TestContext& ctx) { .withYSkew(metadata.ySkew)); map.setDebug(metadata.debug); map.getStyle().loadJSON(serializeJsonValue(metadata.document)); - map.jumpTo(map.getStyle().getDefaultCamera()); } } // namespace @@ -690,18 +691,30 @@ void TestRunner::run(TestMetadata& metadata) { ctx.runnerImpl = maps[key].get(); auto& frontend = ctx.getFrontend(); + auto& map = ctx.getMap(); resetContext(metadata, ctx); - - for (const auto& operation : parseTestOperations(metadata, manifest)) { - if (!operation(ctx)) return; - } + auto camera = map.getStyle().getDefaultCamera(); HeadlessFrontend::RenderResult result; - try { - if (metadata.outputsImage) result = frontend.render(ctx.getMap()); - } catch (const std::exception&) { - return; + + if (metadata.mapMode == MapMode::Tile) { + assert(camera.zoom); + assert(camera.center); + auto tileIds = util::tileCover(map.latLngBoundsForCamera(camera), *camera.zoom); + for (const auto& tileId : tileIds) { + auto cameraForTile{camera}; + double scale = (1 << tileId.canonical.z) / util::tileSize; + Point<double> tileCenter{tileId.canonical.x + 0.5, tileId.canonical.y + 0.5}; + cameraForTile.withCenter(Projection::unproject(tileCenter, scale)); + + map.jumpTo(cameraForTile); + result = runTest(metadata, ctx); + break; + } + } else { + map.jumpTo(camera); + result = runTest(metadata, ctx); } if (!metadata.ignoredTest) { @@ -727,6 +740,20 @@ void TestRunner::run(TestMetadata& metadata) { } } +mbgl::HeadlessFrontend::RenderResult TestRunner::runTest(TestMetadata& metadata, TestContext& ctx) { + HeadlessFrontend::RenderResult result{}; + for (const auto& operation : parseTestOperations(metadata, manifest)) { + if (!operation(ctx)) return result; + } + + try { + if (metadata.outputsImage) result = ctx.getFrontend().render(ctx.getMap()); + } catch (const std::exception& e) { + ctx.getMetadata().errorMessage = std::string("Renering raised an exception: ") + e.what(); + } + return result; +} + void TestRunner::reset() { maps.clear(); } diff --git a/render-test/runner.hpp b/render-test/runner.hpp index 22bfcc98f1..6ad204428c 100644 --- a/render-test/runner.hpp +++ b/render-test/runner.hpp @@ -46,6 +46,7 @@ public: void doShuffle(uint32_t seed); private: + mbgl::HeadlessFrontend::RenderResult runTest(TestMetadata& metadata, TestContext& ctx); void checkQueryTestResults(mbgl::PremultipliedImage&& actualImage, std::vector<mbgl::Feature>&& features, TestMetadata&); |