summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2020-01-03 14:31:49 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2020-01-08 13:07:12 +0200
commitaf8092a86fc5465de3fe0bb2c9e1c24f3fec5965 (patch)
tree2925a8bf49759626ba1bf914b1562174a17c8d83
parentf0d2a2f636bf45889cf8082ba42e0d22875c1e3a (diff)
downloadqtlocation-mapboxgl-af8092a86fc5465de3fe0bb2c9e1c24f3fec5965.tar.gz
[render-test] Use image from the cache for addImage operation
Instead of trying to read it from the filesystem.
-rw-r--r--render-test/metadata.hpp7
-rw-r--r--render-test/parser.cpp22
-rw-r--r--render-test/runner.cpp15
-rw-r--r--render-test/runner.hpp4
4 files changed, 37 insertions, 11 deletions
diff --git a/render-test/metadata.hpp b/render-test/metadata.hpp
index 6b8e080471..e64e07ffc3 100644
--- a/render-test/metadata.hpp
+++ b/render-test/metadata.hpp
@@ -1,12 +1,12 @@
#pragma once
+#include <mbgl/map/mode.hpp>
+#include <mbgl/renderer/query.hpp>
+#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/size.hpp>
-#include <mbgl/map/mode.hpp>
-#include <mbgl/renderer/query.hpp>
-
#include "filesystem.hpp"
#include <list>
@@ -185,6 +185,7 @@ class TestContext {
public:
virtual mbgl::HeadlessFrontend& getFrontend() = 0;
virtual mbgl::Map& getMap() = 0;
+ virtual mbgl::FileSource& getFileSource() = 0;
virtual TestRunnerMapObserver& getObserver() = 0;
virtual TestMetadata& getMetadata() = 0;
diff --git a/render-test/parser.cpp b/render-test/parser.cpp
index c5fca18d64..484428976e 100644
--- a/render-test/parser.cpp
+++ b/render-test/parser.cpp
@@ -688,12 +688,26 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
imageName.erase(std::remove(imageName.begin(), imageName.end(), '"'), imageName.end());
std::string imagePath = operationArray[2].GetString();
- imagePath.erase(std::remove(imagePath.begin(), imagePath.end(), '"'), imagePath.end());
- result.emplace_back([imagePath, imageName, sdf, pixelRatio](TestContext& ctx) {
- mbgl::optional<std::string> maybeImage = mbgl::util::readFile(imagePath);
+ result.emplace_back([imageName, imagePath, sdf, pixelRatio](TestContext& ctx) {
+ mbgl::optional<std::string> maybeImage;
+ bool requestCompleted = false;
+
+ auto req = ctx.getFileSource().request(mbgl::Resource::image("mapbox://render-tests/" + imagePath),
+ [&](mbgl::Response response) {
+ if (response.data) {
+ maybeImage = *response.data;
+ }
+
+ requestCompleted = true;
+ });
+
+ while (!requestCompleted) {
+ mbgl::util::RunLoop::Get()->runOnce();
+ }
+
if (!maybeImage) {
- ctx.getMetadata().errorMessage = std::string("Failed to load expected image ") + imagePath;
+ ctx.getMetadata().errorMessage += std::string("Failed to load expected image ") + imagePath;
return false;
}
diff --git a/render-test/runner.cpp b/render-test/runner.cpp
index eaf1934125..0492868051 100644
--- a/render-test/runner.cpp
+++ b/render-test/runner.cpp
@@ -651,9 +651,10 @@ uint32_t getImageTileOffset(const std::set<uint32_t>& dims, uint32_t dim) {
} // namespace
-TestRunner::Impl::Impl(const TestMetadata& metadata, const Manifest& manifest)
+TestRunner::Impl::Impl(const TestMetadata& metadata, const mbgl::ResourceOptions& resourceOptions)
: observer(std::make_unique<TestRunnerMapObserver>()),
frontend(metadata.size, metadata.pixelRatio, swapBehavior(metadata.mapMode)),
+ fileSource(mbgl::FileSource::getSharedFileSource(resourceOptions)),
map(frontend,
*observer.get(),
mbgl::MapOptions()
@@ -661,7 +662,7 @@ TestRunner::Impl::Impl(const TestMetadata& metadata, const Manifest& manifest)
.withSize(metadata.size)
.withPixelRatio(metadata.pixelRatio)
.withCrossSourceCollisions(metadata.crossSourceCollisions),
- mbgl::ResourceOptions().withCachePath(manifest.getCachePath()).withAccessToken(manifest.getAccessToken())) {}
+ resourceOptions) {}
TestRunner::Impl::~Impl() {}
@@ -680,6 +681,12 @@ void TestRunner::run(TestMetadata& metadata) {
assert(runnerImpl);
return runnerImpl->map;
}
+
+ FileSource& getFileSource() override {
+ assert(runnerImpl);
+ return *runnerImpl->fileSource;
+ }
+
TestRunnerMapObserver& getObserver() override {
assert(runnerImpl);
return *runnerImpl->observer;
@@ -703,7 +710,9 @@ void TestRunner::run(TestMetadata& metadata) {
mbgl::util::toString(uint32_t(metadata.crossSourceCollisions));
if (maps.find(key) == maps.end()) {
- maps[key] = std::make_unique<TestRunner::Impl>(metadata, manifest);
+ maps[key] = std::make_unique<TestRunner::Impl>(
+ metadata,
+ mbgl::ResourceOptions().withCachePath(manifest.getCachePath()).withAccessToken(manifest.getAccessToken()));
}
ctx.runnerImpl = maps[key].get();
diff --git a/render-test/runner.hpp b/render-test/runner.hpp
index 75e552ead7..e6027e335c 100644
--- a/render-test/runner.hpp
+++ b/render-test/runner.hpp
@@ -2,6 +2,7 @@
#include <mbgl/gfx/headless_frontend.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/storage/file_source.hpp>
#include "manifest_parser.hpp"
@@ -54,11 +55,12 @@ private:
void checkProbingResults(TestMetadata&);
struct Impl {
- Impl(const TestMetadata&, const Manifest&);
+ Impl(const TestMetadata&, const mbgl::ResourceOptions&);
~Impl();
std::unique_ptr<TestRunnerMapObserver> observer;
mbgl::HeadlessFrontend frontend;
+ std::shared_ptr<mbgl::FileSource> fileSource;
mbgl::Map map;
};
std::unordered_map<std::string, std::unique_ptr<Impl>> maps;