[render-test] Use image from the cache for addImage operation

Instead of trying to read it from the filesystem.
This commit is contained in:
Thiago Marcos P. Santos
2020-01-03 14:31:49 +02:00
parent f0d2a2f636
commit af8092a86f
4 changed files with 38 additions and 12 deletions

View File

@@ -1,11 +1,11 @@
#pragma once
#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 <mbgl/storage/file_source.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/size.hpp>
#include "filesystem.hpp"
@@ -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;

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;