core: rename mbgl namespace to mln (#4487)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Bart Louwers
2026-08-14 23:25:20 +02:00
committed by GitHub
parent 836b862984
commit 550f64be22
1970 changed files with 8931 additions and 8967 deletions

View File

@@ -9,7 +9,7 @@
#include "file_source.hpp"
namespace mbgl {
namespace mln {
std::atomic_size_t requestCount{0};
std::atomic_size_t transferredSize{0};
@@ -63,11 +63,11 @@ std::unique_ptr<AsyncRequest> ProxyFileSource::request(const Resource& resource,
return defaultResourceLoader->request(transformed, [=](Response response) {
if (transformed.loadingMethod == Resource::LoadingMethod::CacheOnly && response.noContent) {
if (transformed.kind == Resource::Kind::Tile && transformed.tileData) {
mbgl::Log::Info(
mbgl::Event::Database,
mln::Log::Info(
mln::Event::Database,
"Resource not found in cache: " + transformed.url + "(" + transformed.tileData->urlTemplate + ")");
} else {
mbgl::Log::Info(mbgl::Event::Database, "Resource not found in cache: " + transformed.url);
mln::Log::Info(mln::Event::Database, "Resource not found in cache: " + transformed.url);
}
}
@@ -123,4 +123,4 @@ size_t ProxyFileSource::getTransferredSize() {
return transferredSize;
}
} // namespace mbgl
} // namespace mln

View File

@@ -2,7 +2,7 @@
#include <mbgl/storage/file_source.hpp>
namespace mbgl {
namespace mln {
class ClientOptions;
class ResourceOptions;
@@ -56,4 +56,4 @@ private:
ClientOptions clientOptions;
};
} // namespace mbgl
} // namespace mln

View File

@@ -2,8 +2,8 @@
#include <filesystem>
namespace mbgl {
namespace mln {
namespace filesystem = std::filesystem;
} // namespace mbgl
} // namespace mln

View File

@@ -2,7 +2,7 @@
#include <functional>
namespace mbgl {
namespace mln {
struct TestStatus {
size_t completed;
@@ -11,4 +11,4 @@ struct TestStatus {
int runRenderTests(int argc, char* argv[], std::function<void(TestStatus)>);
} // namespace mbgl
} // namespace mln

View File

@@ -18,18 +18,18 @@ bool TestRunner::startTest(const std::string& manifestBasePath) {
}
argv.push_back(nullptr);
std::function<void(mbgl::TestStatus)> testStatus = [&](mbgl::TestStatus status) {
mbgl::Log::Info(mbgl::Event::General,
"Current finished tests number is '" + std::to_string(status.completed) + "/" +
std::to_string(status.total) + "' ");
std::function<void(mln::TestStatus)> testStatus = [&](mln::TestStatus status) {
mln::Log::Info(mln::Event::General,
"Current finished tests number is '" + std::to_string(status.completed) + "/" +
std::to_string(status.total) + "' ");
};
mbgl::Log::Info(mbgl::Event::General, "Start running RenderTestRunner with manifest: '" + manifest + "' ");
mln::Log::Info(mln::Event::General, "Start running RenderTestRunner with manifest: '" + manifest + "' ");
auto result = mbgl::runRenderTests(static_cast<int>(argv.size() - 1), argv.data(), testStatus);
auto result = mln::runRenderTests(static_cast<int>(argv.size() - 1), argv.data(), testStatus);
mbgl::Log::Info(mbgl::Event::General,
"End running RenderTestRunner with manifest: '" + manifest + "' with result value " +
std::to_string(result));
mln::Log::Info(mln::Event::General,
"End running RenderTestRunner with manifest: '" + manifest + "' with result value " +
std::to_string(result));
return result == 0;
};
@@ -43,12 +43,12 @@ bool TestRunner::startTest(const std::string& manifestBasePath) {
status = runTestWithManifest(manifestBasePath + "/ios-render-test-runner-metrics.json") && status;
#endif
} catch (...) {
mbgl::Log::Info(mbgl::Event::General, "Failed with exception");
mln::Log::Info(mln::Event::General, "Failed with exception");
}
mbgl::Log::Info(mbgl::Event::General, "All tests are finished!");
mln::Log::Info(mln::Event::General, "All tests are finished!");
if (!status) {
mbgl::Log::Info(mbgl::Event::General, "There are failing test cases");
mln::Log::Info(mln::Event::General, "There are failing test cases");
}
return status;
}

View File

@@ -55,14 +55,14 @@ void Manifest::doShuffle(uint32_t seed) {
}
namespace {
std::vector<std::pair<std::string, std::string>> parseIgnores(const std::vector<mbgl::filesystem::path>& ignoresPaths) {
std::vector<std::pair<std::string, std::string>> parseIgnores(const std::vector<mln::filesystem::path>& ignoresPaths) {
std::vector<std::pair<std::string, std::string>> ignores;
for (const auto& path : ignoresPaths) {
auto maybeIgnores = readJson(path);
if (!maybeIgnores.is<mbgl::JSDocument>()) {
if (!maybeIgnores.is<mln::JSDocument>()) {
continue;
}
for (const auto& property : maybeIgnores.get<mbgl::JSDocument>().GetObject()) {
for (const auto& property : maybeIgnores.get<mln::JSDocument>().GetObject()) {
const std::string ignore = {property.name.GetString(), property.name.GetStringLength()};
const std::string reason = {property.value.GetString(), property.value.GetStringLength()};
ignores.emplace_back(std::make_pair(ignore, reason));
@@ -75,50 +75,49 @@ std::vector<std::pair<std::string, std::string>> parseIgnores(const std::vector<
// defaultExpectationPath: absolute path that contains the style.json file for testing
// testId: Test case id that used for composing expectation path
// expectatedPaths: absolute paths that contain possible expected.png/metrics.json files for result checking
std::vector<mbgl::filesystem::path> getTestExpectations(const mbgl::filesystem::path& defaultExpectationPath,
const std::string& testId,
std::vector<mbgl::filesystem::path> expectatedPaths) {
std::vector<mbgl::filesystem::path> expectations{defaultExpectationPath};
std::vector<mln::filesystem::path> getTestExpectations(const mln::filesystem::path& defaultExpectationPath,
const std::string& testId,
std::vector<mln::filesystem::path> expectatedPaths) {
std::vector<mln::filesystem::path> expectations{defaultExpectationPath};
for (const auto& expectedPath : expectatedPaths) {
expectations.emplace_back(expectedPath / testId);
}
return expectations;
}
mbgl::filesystem::path getValidPath(const std::string& manifestPath, const std::string& path) {
const static mbgl::filesystem::path BasePath{manifestPath};
mbgl::filesystem::path result{path};
mln::filesystem::path getValidPath(const std::string& manifestPath, const std::string& path) {
const static mln::filesystem::path BasePath{manifestPath};
mln::filesystem::path result{path};
if (result.is_relative()) {
result = BasePath / result;
}
if (mbgl::filesystem::exists(result)) {
if (mln::filesystem::exists(result)) {
return result.lexically_normal();
}
mbgl::Log::Warning(mbgl::Event::General, "Invalid path is provided inside the manifest file: " + path);
return mbgl::filesystem::path{};
mln::Log::Warning(mln::Event::General, "Invalid path is provided inside the manifest file: " + path);
return mln::filesystem::path{};
}
} // namespace
std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifestPath, std::string testFilter) {
Manifest manifest;
const auto filePath = mbgl::filesystem::path(manifestPath);
const auto filePath = mln::filesystem::path(manifestPath);
manifest.manifestPath = manifestPath.substr(0, manifestPath.find(filePath.filename().generic_string()));
auto contents = readJson(filePath);
if (!contents.is<mbgl::JSDocument>()) {
mbgl::Log::Error(mbgl::Event::General,
"Provided manifest file: " + filePath.generic_string() + " is not a valid json");
if (!contents.is<mln::JSDocument>()) {
mln::Log::Error(mln::Event::General,
"Provided manifest file: " + filePath.generic_string() + " is not a valid json");
return std::nullopt;
}
auto document = std::move(contents.get<mbgl::JSDocument>());
auto document = std::move(contents.get<mln::JSDocument>());
if (document.HasMember("result_path")) {
const auto& resultPathValue = document["result_path"];
if (!resultPathValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General,
"Invalid result_path is provided inside the manifest file: " + filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid result_path is provided inside the manifest file: " + filePath.generic_string());
return std::nullopt;
}
manifest.resultPath = (getValidPath(manifest.manifestPath, resultPathValue.GetString()) / "").generic_string();
@@ -129,8 +128,8 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
if (document.HasMember("cache_path")) {
const auto& cachePathValue = document["cache_path"];
if (!cachePathValue.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid cache_path is provided inside the manifest file: " + filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid cache_path is provided inside the manifest file: " + filePath.generic_string());
return std::nullopt;
}
manifest.cachePath = (getValidPath(manifest.manifestPath, ".") / cachePathValue.GetString()).generic_string();
@@ -142,8 +141,8 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
if (document.HasMember("access_token")) {
const auto& apiKeyValue = document["access_token"];
if (!apiKeyValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General,
mln::Log::Warning(
mln::Event::General,
"Invalid access_token is provided inside the manifest file: " + filePath.generic_string());
return std::nullopt;
}
@@ -152,14 +151,14 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
return std::nullopt;
}
}
mbgl::filesystem::path baseTestPath;
mln::filesystem::path baseTestPath;
if (document.HasMember("base_test_path")) {
const auto& testPathValue = document["base_test_path"];
if (!testPathValue.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid base_test_path is provided inside the manifest "
"file: " +
filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid base_test_path is provided inside the manifest "
"file: " +
filePath.generic_string());
return std::nullopt;
}
baseTestPath = getValidPath(manifest.manifestPath, testPathValue.GetString());
@@ -167,13 +166,12 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
return std::nullopt;
}
}
mbgl::filesystem::path expectedMetricPath;
mln::filesystem::path expectedMetricPath;
if (document.HasMember("metric_path")) {
const auto& metricPathValue = document["metric_path"];
if (!metricPathValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General,
"Invalid metric_path is provided inside the manifest file: " + filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid metric_path is provided inside the manifest file: " + filePath.generic_string());
return std::nullopt;
}
expectedMetricPath = getValidPath(manifest.manifestPath, metricPathValue.GetString());
@@ -181,22 +179,22 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
return std::nullopt;
}
}
std::vector<mbgl::filesystem::path> expectationPaths{};
std::vector<mln::filesystem::path> expectationPaths{};
if (document.HasMember("expectation_paths")) {
const auto& expectationPathValue = document["expectation_paths"];
if (!expectationPathValue.IsArray()) {
mbgl::Log::Warning(mbgl::Event::General,
"Provided expectation_paths inside the manifest file: %s is "
"not a valid array" +
filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Provided expectation_paths inside the manifest file: %s is "
"not a valid array" +
filePath.generic_string());
return std::nullopt;
}
for (const auto& value : expectationPathValue.GetArray()) {
if (!value.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid expectation path item is provided inside the "
"manifest file: " +
filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid expectation path item is provided inside the "
"manifest file: " +
filePath.generic_string());
return std::nullopt;
}
expectationPaths.emplace_back(getValidPath(manifest.manifestPath, value.GetString()));
@@ -205,21 +203,21 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
}
}
}
std::vector<mbgl::filesystem::path> ignorePaths{};
std::vector<mln::filesystem::path> ignorePaths{};
if (document.HasMember("ignore_paths")) {
const auto& ignorePathValue = document["ignore_paths"];
if (!ignorePathValue.IsArray()) {
mbgl::Log::Warning(mbgl::Event::General,
"Provided ignore_paths inside the manifest file: " + filePath.generic_string() +
" is not a valid array");
mln::Log::Warning(mln::Event::General,
"Provided ignore_paths inside the manifest file: " + filePath.generic_string() +
" is not a valid array");
return std::nullopt;
}
for (const auto& value : ignorePathValue.GetArray()) {
if (!value.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid ignore path item is provided inside the manifest "
"file: " +
filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid ignore path item is provided inside the manifest "
"file: " +
filePath.generic_string());
return std::nullopt;
}
ignorePaths.emplace_back(getValidPath(manifest.manifestPath, value.GetString()));
@@ -233,17 +231,17 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
if (document.HasMember("probes")) {
const auto& probesValue = document["probes"];
if (!probesValue.IsArray()) {
mbgl::Log::Warning(
mbgl::Event::General,
mln::Log::Warning(
mln::Event::General,
"Provided probes inside the manifest file: " + filePath.generic_string() + "is not a valid array");
return std::nullopt;
}
for (const auto& value : probesValue.GetArray()) {
if (!value.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid probe type is provided inside the manifest "
"file: " +
filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid probe type is provided inside the manifest "
"file: " +
filePath.generic_string());
return std::nullopt;
}
manifest.probes.emplace(value.GetString());
@@ -253,8 +251,8 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
if (testFilter.empty() && document.HasMember("filter")) {
const auto& filterValue = document["filter"];
if (!filterValue.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid filter is provided inside the manifest file: " + filePath.generic_string());
mln::Log::Warning(mln::Event::General,
"Invalid filter is provided inside the manifest file: " + filePath.generic_string());
return std::nullopt;
}
@@ -277,19 +275,19 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
auto& path = manifest.testRootPath;
auto& testPaths = manifest.testPaths;
for (auto& testPath : mbgl::filesystem::recursive_directory_iterator(path)) {
for (auto& testPath : mln::filesystem::recursive_directory_iterator(path)) {
// Skip paths that fail regexp search.
if (!testFilter.empty() && !std::regex_search(testPath.path().generic_string(), std::regex(testFilter))) {
continue;
}
if (testPath.path().filename() == "style.json") {
const auto defaultExpectationPath{std::move(mbgl::filesystem::path(testPath).remove_filename())};
const auto defaultExpectationPath{std::move(mln::filesystem::path(testPath).remove_filename())};
const auto rootLength = manifest.testRootPath.length();
auto testId = defaultExpectationPath.generic_string();
testId = testId.substr(rootLength + 1, testId.length() - rootLength - 1);
std::vector<mbgl::filesystem::path> expectedMetricPaths{expectedMetricPath};
std::vector<mln::filesystem::path> expectedMetricPaths{expectedMetricPath};
#if defined(__ANDROID__)
// todo: use `Context.getExternalFilesDir()` or similar via JNI to select an appropriate destination
const auto locations = std::vector<std::string>{
@@ -299,16 +297,16 @@ std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifes
};
static bool reportedOnce = false;
for (const auto& location : locations) {
// Checking `mbgl::filesystem::status` doesn't accurately reflect whether we can create subdirectories,
// Checking `mln::filesystem::status` doesn't accurately reflect whether we can create subdirectories,
// so just try it. (See `TestRunner::checkProbingResults`)
try {
const auto baselinesPath = location + "/baselines";
mbgl::filesystem::create_directories(baselinesPath);
mln::filesystem::create_directories(baselinesPath);
expectedMetricPaths.emplace_back(baselinesPath);
break;
} catch (mbgl::filesystem::filesystem_error& ex) {
} catch (mln::filesystem::filesystem_error& ex) {
if (!reportedOnce) {
mbgl::Log::Warning(mbgl::Event::Android, "Not a writable directory: " + std::string(ex.what()));
mln::Log::Warning(mln::Event::Android, "Not a writable directory: " + std::string(ex.what()));
}
}
}

View File

@@ -12,14 +12,14 @@
#include <list>
#include <map>
namespace mbgl {
namespace mln {
class Map;
class HeadlessFrontend;
namespace gfx {
struct RenderingStats;
}
} // namespace mbgl
} // namespace mln
class TestRunnerMapObserver;
struct TestStatistics {
@@ -34,16 +34,16 @@ struct TestStatistics {
struct TestPaths {
TestPaths() = default;
TestPaths(mbgl::filesystem::path stylePath_,
std::vector<mbgl::filesystem::path> expectations_,
std::vector<mbgl::filesystem::path> expectedMetrics_)
TestPaths(mln::filesystem::path stylePath_,
std::vector<mln::filesystem::path> expectations_,
std::vector<mln::filesystem::path> expectedMetrics_)
: stylePath(std::move(stylePath_)),
expectations(std::move(expectations_)),
expectedMetrics(std::move(expectedMetrics_)) {}
mbgl::filesystem::path stylePath;
std::vector<mbgl::filesystem::path> expectations;
std::vector<mbgl::filesystem::path> expectedMetrics;
mln::filesystem::path stylePath;
std::vector<mln::filesystem::path> expectations;
std::vector<mln::filesystem::path> expectedMetrics;
std::string defaultExpectations() const {
assert(!expectations.empty());
@@ -118,7 +118,7 @@ struct GfxProbe {
};
GfxProbe() = default;
GfxProbe(const mbgl::gfx::RenderingStats&, const GfxProbe&);
GfxProbe(const mln::gfx::RenderingStats&, const GfxProbe&);
int numBuffers;
int numDrawCalls;
@@ -144,7 +144,7 @@ struct TestMetadata {
TestMetadata() = default;
TestPaths paths;
mbgl::JSDocument document;
mln::JSDocument document;
bool renderTest = true;
bool outputsImage = true;
bool ignoredTest = false;
@@ -154,20 +154,20 @@ struct TestMetadata {
// to prevent the unit test fail, and just verify the render result.
bool ignoreProbing = true;
mbgl::Size size{512u, 512u};
mln::Size size{512u, 512u};
std::optional<float> maxPitch;
float pixelRatio = 1.0f;
double allowed = 0.00015; // diff
std::string description;
mbgl::MapMode mapMode = mbgl::MapMode::Static;
mbgl::MapDebugOptions debug = mbgl::MapDebugOptions::NoDebug;
mln::MapMode mapMode = mln::MapMode::Static;
mln::MapDebugOptions debug = mln::MapDebugOptions::NoDebug;
bool crossSourceCollisions = true;
bool axonometric = false;
double xSkew = 0.0;
double ySkew = 1.0;
mbgl::ScreenCoordinate queryGeometry{0u, 0u};
mbgl::ScreenBox queryGeometryBox{{0u, 0u}, {0u, 0u}};
mbgl::RenderedQueryOptions queryOptions;
mln::ScreenCoordinate queryGeometry{0u, 0u};
mln::ScreenBox queryGeometryBox{{0u, 0u}, {0u, 0u}};
mln::RenderedQueryOptions queryOptions;
// TODO
uint32_t fadeDuration = 0;
@@ -200,9 +200,9 @@ struct TestMetadata {
class TestContext {
public:
virtual mbgl::HeadlessFrontend& getFrontend() = 0;
virtual mbgl::Map& getMap() = 0;
virtual mbgl::FileSource& getFileSource() = 0;
virtual mln::HeadlessFrontend& getFrontend() = 0;
virtual mln::Map& getMap() = 0;
virtual mln::FileSource& getFileSource() = 0;
virtual TestRunnerMapObserver& getObserver() = 0;
virtual TestMetadata& getMetadata() = 0;

View File

@@ -104,23 +104,23 @@ const char* resultsHeaderButtons = R"HTML(
</h1>
)HTML";
void writeJSON(rapidjson::PrettyWriter<rapidjson::StringBuffer>& writer, const mbgl::Value& value) {
value.match([&writer](const mbgl::NullValue&) { writer.Null(); },
void writeJSON(rapidjson::PrettyWriter<rapidjson::StringBuffer>& writer, const mln::Value& value) {
value.match([&writer](const mln::NullValue&) { writer.Null(); },
[&writer](bool b) { writer.Bool(b); },
[&writer](uint64_t u) { writer.Uint64(u); },
[&writer](int64_t i) { writer.Int64(i); },
[&writer](double d) { d == std::floor(d) ? writer.Int64(static_cast<int64_t>(d)) : writer.Double(d); },
[&writer](const std::string& s) { writer.String(s); },
[&writer](const std::vector<mbgl::Value>& arr) {
[&writer](const std::vector<mln::Value>& arr) {
writer.StartArray();
for (const auto& item : arr) {
writeJSON(writer, item);
}
writer.EndArray();
},
[&writer](const std::unordered_map<std::string, mbgl::Value>& obj) {
[&writer](const std::unordered_map<std::string, mln::Value>& obj) {
writer.StartObject();
std::map<std::string, mbgl::Value> sorted(obj.begin(), obj.end());
std::map<std::string, mln::Value> sorted(obj.begin(), obj.end());
for (const auto& entry : sorted) {
writer.Key(entry.first.c_str());
writeJSON(writer, entry.second);
@@ -131,7 +131,7 @@ void writeJSON(rapidjson::PrettyWriter<rapidjson::StringBuffer>& writer, const m
} // namespace
std::string toJSON(const mbgl::Value& value, unsigned indent, bool singleLine) {
std::string toJSON(const mln::Value& value, unsigned indent, bool singleLine) {
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
if (singleLine) {
@@ -142,7 +142,7 @@ std::string toJSON(const mbgl::Value& value, unsigned indent, bool singleLine) {
return buffer.GetString();
}
std::string toJSON(const std::vector<mbgl::Feature>& features, unsigned indent, bool singleLine) {
std::string toJSON(const std::vector<mln::Feature>& features, unsigned indent, bool singleLine) {
rapidjson::CrtAllocator allocator;
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
@@ -152,9 +152,9 @@ std::string toJSON(const std::vector<mbgl::Feature>& features, unsigned indent,
writer.SetIndent(' ', indent);
writer.StartArray();
for (const auto& feature : features) {
mbgl::JSValue result(rapidjson::kObjectType);
mln::JSValue result(rapidjson::kObjectType);
result.AddMember("type", "Feature", allocator);
if (!feature.id.is<mbgl::NullValue>()) {
if (!feature.id.is<mln::NullValue>()) {
result.AddMember(
"id", mapbox::geojson::identifier::visit(feature.id, mapbox::geojson::to_value{allocator}), allocator);
}
@@ -171,22 +171,22 @@ std::string toJSON(const std::vector<mbgl::Feature>& features, unsigned indent,
return buffer.GetString();
}
JSONReply readJson(const mbgl::filesystem::path& jsonPath) {
auto maybeJSON = mbgl::util::readFile(jsonPath.generic_string());
JSONReply readJson(const mln::filesystem::path& jsonPath) {
auto maybeJSON = mln::util::readFile(jsonPath.generic_string());
if (!maybeJSON) {
return {std::string("Unable to open file ") + jsonPath.string()};
}
mbgl::JSDocument document;
mln::JSDocument document;
document.Parse<0>(*maybeJSON);
if (document.HasParseError()) {
return {mbgl::formatJSONParseError(document)};
return {mln::formatJSONParseError(document)};
}
return {std::move(document)};
}
std::string serializeJsonValue(const mbgl::JSValue& value) {
std::string serializeJsonValue(const mln::JSValue& value) {
rapidjson::StringBuffer buffer;
buffer.Clear();
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@@ -297,9 +297,9 @@ std::string serializeMetrics(const TestMetrics& metrics) {
}
namespace {
std::vector<std::string> readExpectedEntries(const std::regex& regex, const mbgl::filesystem::path& base) {
std::vector<std::string> readExpectedEntries(const std::regex& regex, const mln::filesystem::path& base) {
std::vector<std::string> expectedEntries;
for (const auto& entry : mbgl::filesystem::directory_iterator(base)) {
for (const auto& entry : mln::filesystem::directory_iterator(base)) {
if (entry.is_regular_file()) {
const std::string path = entry.path().string();
if (std::regex_match(path, regex)) {
@@ -311,33 +311,33 @@ std::vector<std::string> readExpectedEntries(const std::regex& regex, const mbgl
}
} // namespace
std::vector<std::string> readExpectedImageEntries(const mbgl::filesystem::path& base) {
std::vector<std::string> readExpectedImageEntries(const mln::filesystem::path& base) {
static const std::regex regex(".*[/\\\\]expected.*.png");
return readExpectedEntries(regex, base);
}
std::vector<std::string> readExpectedMetricEntries(const mbgl::filesystem::path& base) {
std::vector<std::string> readExpectedMetricEntries(const mln::filesystem::path& base) {
static const std::regex regex(".*[/\\\\]metrics.json");
return readExpectedEntries(regex, base);
}
std::vector<std::string> readExpectedJSONEntries(const mbgl::filesystem::path& base) {
std::vector<std::string> readExpectedJSONEntries(const mln::filesystem::path& base) {
static const std::regex regex(".*[/\\\\]expected.*.json");
return readExpectedEntries(regex, base);
}
TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
TestMetrics readExpectedMetrics(const mln::filesystem::path& path) {
TestMetrics result;
auto maybeJson = readJson(path.string());
if (!maybeJson.is<mbgl::JSDocument>()) { // NOLINT
if (!maybeJson.is<mln::JSDocument>()) { // NOLINT
return result;
}
const auto& document = maybeJson.get<mbgl::JSDocument>();
const auto& document = maybeJson.get<mln::JSDocument>();
if (document.HasMember("file-size")) {
const mbgl::JSValue& fileSizeValue = document["file-size"];
const mln::JSValue& fileSizeValue = document["file-size"];
assert(fileSizeValue.IsArray());
for (auto& probeValue : fileSizeValue.GetArray()) {
assert(probeValue.IsArray());
@@ -359,7 +359,7 @@ TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
}
if (document.HasMember("memory")) {
const mbgl::JSValue& memoryValue = document["memory"];
const mln::JSValue& memoryValue = document["memory"];
assert(memoryValue.IsArray());
for (auto& probeValue : memoryValue.GetArray()) {
assert(probeValue.IsArray());
@@ -377,7 +377,7 @@ TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
}
if (document.HasMember("network")) {
const mbgl::JSValue& networkValue = document["network"];
const mln::JSValue& networkValue = document["network"];
assert(networkValue.IsArray());
for (auto& probeValue : networkValue.GetArray()) {
assert(probeValue.IsArray());
@@ -396,7 +396,7 @@ TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
}
if (document.HasMember("fps")) {
const mbgl::JSValue& fpsValue = document["fps"];
const mln::JSValue& fpsValue = document["fps"];
assert(fpsValue.IsArray());
for (auto& probeValue : fpsValue.GetArray()) {
assert(probeValue.IsArray());
@@ -413,7 +413,7 @@ TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
}
if (document.HasMember("gfx")) {
const mbgl::JSValue& gfxValue = document["gfx"];
const mln::JSValue& gfxValue = document["gfx"];
assert(gfxValue.IsArray());
for (auto& probeValue : gfxValue.GetArray()) {
assert(probeValue.IsArray());
@@ -454,49 +454,49 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
metadata.paths = paths;
auto maybeJson = readJson(paths.stylePath.string());
if (!maybeJson.is<mbgl::JSDocument>()) { // NOLINT
if (!maybeJson.is<mln::JSDocument>()) { // NOLINT
metadata.errorMessage = std::string("Unable to parse: ") + metadata.paths.stylePath.string();
return metadata;
}
metadata.document = std::move(maybeJson.get<mbgl::JSDocument>());
metadata.document = std::move(maybeJson.get<mln::JSDocument>());
if (!metadata.document.HasMember("metadata")) {
mbgl::Log::Warning(mbgl::Event::ParseStyle, "Style has no 'metadata': " + paths.stylePath.string());
mln::Log::Warning(mln::Event::ParseStyle, "Style has no 'metadata': " + paths.stylePath.string());
return metadata;
}
const mbgl::JSValue& metadataValue = metadata.document["metadata"];
const mln::JSValue& metadataValue = metadata.document["metadata"];
if (!metadataValue.HasMember("test")) {
mbgl::Log::Warning(mbgl::Event::ParseStyle, "Style has no 'metadata.test': " + paths.stylePath.string());
mln::Log::Warning(mln::Event::ParseStyle, "Style has no 'metadata.test': " + paths.stylePath.string());
return metadata;
}
const mbgl::JSValue& testValue = metadataValue["test"];
const mln::JSValue& testValue = metadataValue["test"];
if (testValue.HasMember("mapMode")) {
metadata.outputsImage = true;
assert(testValue["mapMode"].IsString());
std::string mapModeStr = testValue["mapMode"].GetString();
if (mapModeStr == "tile") {
metadata.mapMode = mbgl::MapMode::Tile;
metadata.mapMode = mln::MapMode::Tile;
// In the tile mode, map is showing exactly one tile.
metadata.size = {mbgl::util::tileSize_I, mbgl::util::tileSize_I};
metadata.size = {mln::util::tileSize_I, mln::util::tileSize_I};
} else if (mapModeStr == "continuous") {
metadata.mapMode = mbgl::MapMode::Continuous;
metadata.mapMode = mln::MapMode::Continuous;
metadata.outputsImage = false;
} else if (mapModeStr == "static")
metadata.mapMode = mbgl::MapMode::Static;
metadata.mapMode = mln::MapMode::Static;
else {
mbgl::Log::Warning(mbgl::Event::ParseStyle,
"Unknown map mode: " + mapModeStr + ". Falling back to static mode");
metadata.mapMode = mbgl::MapMode::Static;
mln::Log::Warning(mln::Event::ParseStyle,
"Unknown map mode: " + mapModeStr + ". Falling back to static mode");
metadata.mapMode = mln::MapMode::Static;
}
}
if (testValue.HasMember("width")) {
assert(testValue["width"].IsNumber());
if (metadata.mapMode == mbgl::MapMode::Tile) {
mbgl::Log::Warning(mbgl::Event::ParseStyle, "The 'width' metadata field is ignored in tile map mode");
if (metadata.mapMode == mln::MapMode::Tile) {
mln::Log::Warning(mln::Event::ParseStyle, "The 'width' metadata field is ignored in tile map mode");
} else {
metadata.size.width = testValue["width"].GetInt();
}
@@ -504,8 +504,8 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
if (testValue.HasMember("height")) {
assert(testValue["height"].IsNumber());
if (metadata.mapMode == mbgl::MapMode::Tile) {
mbgl::Log::Warning(mbgl::Event::ParseStyle, "The 'height' metadata field is ignored in tile map mode");
if (metadata.mapMode == mln::MapMode::Tile) {
mln::Log::Warning(mln::Event::ParseStyle, "The 'height' metadata field is ignored in tile map mode");
} else {
metadata.size.height = testValue["height"].GetInt();
}
@@ -535,15 +535,15 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
// Test operations handled in runner.cpp.
if (testValue.HasMember("debug")) {
metadata.debug |= mbgl::MapDebugOptions::TileBorders;
metadata.debug |= mln::MapDebugOptions::TileBorders;
}
if (testValue.HasMember("collisionDebug")) {
metadata.debug |= mbgl::MapDebugOptions::Collision;
metadata.debug |= mln::MapDebugOptions::Collision;
}
if (testValue.HasMember("showOverdrawInspector")) {
metadata.debug |= mbgl::MapDebugOptions::Overdraw;
metadata.debug |= mln::MapDebugOptions::Overdraw;
}
if (testValue.HasMember("crossSourceCollisions")) {
@@ -595,8 +595,8 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
metadata.queryOptions.layerIDs = layersVec;
}
using namespace mbgl::style;
using namespace mbgl::style::conversion;
using namespace mln::style;
using namespace mln::style::conversion;
if (testValue["queryOptions"].HasMember("filter")) {
assert(testValue["queryOptions"]["filter"].IsArray());
auto& filterVal = testValue["queryOptions"]["filter"];
@@ -613,7 +613,7 @@ TestMetadata parseTestMetadata(const TestPaths& paths) {
return metadata;
}
namespace mbgl {
namespace mln {
MBGL_DEFINE_ENUM(TileLodMode, {{TileLodMode::Default, "default"}, {TileLodMode::Distance, "distance"}});
}
@@ -689,18 +689,18 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
});
} else if (operationArray[0].GetString() == sleepOp) {
// sleep
mbgl::Duration duration = mbgl::Seconds(3);
mln::Duration duration = mln::Seconds(3);
if (operationArray.Size() >= 2u) {
duration = mbgl::Milliseconds(operationArray[1].GetUint());
duration = mln::Milliseconds(operationArray[1].GetUint());
}
result.emplace_back([duration](TestContext&) {
mbgl::util::Timer sleepTimer;
mln::util::Timer sleepTimer;
bool sleeping = true;
sleepTimer.start(duration, mbgl::Duration::zero(), [&]() { sleeping = false; });
sleepTimer.start(duration, mln::Duration::zero(), [&]() { sleeping = false; });
while (sleeping) {
mbgl::util::RunLoop::Get()->runOnce();
mln::util::RunLoop::Get()->runOnce();
}
return true;
});
@@ -732,8 +732,8 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
std::optional<std::string> maybeImage;
bool requestCompleted = false;
auto req = ctx.getFileSource().request(mbgl::Resource::image("mapbox://render-tests/" + imagePath),
[&](mbgl::Response response) {
auto req = ctx.getFileSource().request(mln::Resource::image("mapbox://render-tests/" + imagePath),
[&](mln::Response response) {
if (response.data) {
maybeImage = *response.data;
}
@@ -742,7 +742,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
});
while (!requestCompleted) {
mbgl::util::RunLoop::Get()->runOnce();
mln::util::RunLoop::Get()->runOnce();
}
if (!maybeImage) {
@@ -751,7 +751,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
}
ctx.getMap().getStyle().addImage(
std::make_unique<mbgl::style::Image>(imageName, mbgl::decodeImage(*maybeImage), pixelRatio, sdf));
std::make_unique<mln::style::Image>(imageName, mln::decodeImage(*maybeImage), pixelRatio, sdf));
return true;
});
@@ -790,9 +790,9 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
const auto& centerArray = operationArray[1].GetArray();
assert(centerArray.Size() == 2u);
mbgl::LatLng center{centerArray[1].GetDouble(), centerArray[0].GetDouble()};
mln::LatLng center{centerArray[1].GetDouble(), centerArray[0].GetDouble()};
result.emplace_back([center](TestContext& ctx) {
ctx.getMap().jumpTo(mbgl::CameraOptions().withCenter(center));
ctx.getMap().jumpTo(mln::CameraOptions().withCenter(center));
return true;
});
} else if (operationArray[0].GetString() == setZoomOp) {
@@ -801,7 +801,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsNumber());
double zoom = operationArray[1].GetDouble();
result.emplace_back([zoom](TestContext& ctx) {
ctx.getMap().jumpTo(mbgl::CameraOptions().withZoom(zoom));
ctx.getMap().jumpTo(mln::CameraOptions().withZoom(zoom));
return true;
});
} else if (operationArray[0].GetString() == setBearingOp) {
@@ -810,7 +810,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsNumber());
double bearing = operationArray[1].GetDouble();
result.emplace_back([bearing](TestContext& ctx) {
ctx.getMap().jumpTo(mbgl::CameraOptions().withBearing(bearing));
ctx.getMap().jumpTo(mln::CameraOptions().withBearing(bearing));
return true;
});
} else if (operationArray[0].GetString() == setPitchOp) {
@@ -819,7 +819,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsNumber());
double pitch = operationArray[1].GetDouble();
result.emplace_back([pitch](TestContext& ctx) {
ctx.getMap().jumpTo(mbgl::CameraOptions().withPitch(pitch));
ctx.getMap().jumpTo(mln::CameraOptions().withPitch(pitch));
return true;
});
} else if (operationArray[0].GetString() == setRollOp) {
@@ -828,7 +828,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsNumber());
double roll = operationArray[1].GetDouble();
result.emplace_back([roll](TestContext& ctx) {
ctx.getMap().jumpTo(mbgl::CameraOptions().withRoll(roll));
ctx.getMap().jumpTo(mln::CameraOptions().withRoll(roll));
return true;
});
} else if (operationArray[0].GetString() == setCenterAltitudeOp) {
@@ -837,7 +837,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsNumber());
double centerAltitude = operationArray[1].GetDouble();
result.emplace_back([centerAltitude](TestContext& ctx) {
ctx.getMap().jumpTo(mbgl::CameraOptions().withCenterAltitude(centerAltitude));
ctx.getMap().jumpTo(mln::CameraOptions().withCenterAltitude(centerAltitude));
return true;
});
} else if (operationArray[0].GetString() == setFilterOp) {
@@ -846,8 +846,8 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsString());
std::string layerName{operationArray[1].GetString(), operationArray[1].GetStringLength()};
mbgl::style::conversion::Error error;
auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(operationArray[2], error);
mln::style::conversion::Error error;
auto converted = mln::style::conversion::convert<mln::style::Filter>(operationArray[2], error);
result.emplace_back([converted, layerName, error](TestContext& ctx) {
if (!converted) {
ctx.getMetadata().errorMessage = std::string("Unable to convert filter: ") + error.message;
@@ -886,14 +886,14 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
// setLight
assert(operationArray.Size() >= 2u);
assert(operationArray[1].IsObject());
mbgl::style::conversion::Error error;
auto converted = mbgl::style::conversion::convert<mbgl::style::Light>(operationArray[1], error);
mln::style::conversion::Error error;
auto converted = mln::style::conversion::convert<mln::style::Light>(operationArray[1], error);
if (!converted) {
metadata.errorMessage = std::string("Unable to convert light: ") + error.message;
return {};
}
result.emplace_back([impl = converted->impl](TestContext& ctx) {
ctx.getMap().getStyle().setLight(std::make_unique<mbgl::style::Light>(impl));
ctx.getMap().getStyle().setLight(std::make_unique<mln::style::Light>(impl));
return true;
});
} else if (operationArray[0].GetString() == addLayerOp) {
@@ -901,8 +901,8 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray.Size() >= 2u);
assert(operationArray[1].IsObject());
result.emplace_back([json = serializeJsonValue(operationArray[1])](TestContext& ctx) {
mbgl::style::conversion::Error error;
auto converted = mbgl::style::conversion::convertJSON<std::unique_ptr<mbgl::style::Layer>>(json, error);
mln::style::conversion::Error error;
auto converted = mln::style::conversion::convertJSON<std::unique_ptr<mln::style::Layer>>(json, error);
if (!converted) {
ctx.getMetadata().errorMessage = std::string("Unable to convert layer: ") + error.message;
return false;
@@ -925,8 +925,8 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
std::string sourceName = operationArray[1].GetString();
result.emplace_back([sourceName, json = serializeJsonValue(operationArray[2])](TestContext& ctx) {
mbgl::style::conversion::Error error;
auto converted = mbgl::style::conversion::convertJSON<std::unique_ptr<mbgl::style::Source>>(
mln::style::conversion::Error error;
auto converted = mln::style::conversion::convertJSON<std::unique_ptr<mln::style::Source>>(
json, error, sourceName);
if (!converted) {
ctx.getMetadata().errorMessage = std::string("Unable to convert source: ") + error.message;
@@ -958,9 +958,9 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
ctx.getMetadata().errorMessage = std::string("Layer not found: ") + layerName;
return false;
}
mbgl::JSDocument d;
mln::JSDocument d;
d.Parse(json.c_str(), json.length());
const mbgl::JSValue* propertyValue = &d;
const mln::JSValue* propertyValue = &d;
layer->setProperty(propertyName, propertyValue);
return true;
});
@@ -976,7 +976,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(!path.empty());
float tolerance = static_cast<float>(operationArray[3].GetDouble());
mbgl::filesystem::path filePath(path);
mln::filesystem::path filePath(path);
bool compressed = false;
if (operationArray.Size() == 5) {
@@ -989,15 +989,15 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
filePath = metadata.paths.defaultExpectations() / filePath;
}
result.emplace_back([filePath, path, mark, tolerance, compressed](TestContext& ctx) {
if (!mbgl::filesystem::exists(filePath)) {
if (!mln::filesystem::exists(filePath)) {
ctx.getMetadata().errorMessage = std::string("File not found: ") + path;
return false;
}
size_t size = 0;
if (compressed) {
size = mbgl::util::compress(*mbgl::util::readFile(filePath.generic_string())).size();
size = mln::util::compress(*mln::util::readFile(filePath.generic_string())).size();
} else {
size = mbgl::filesystem::file_size(filePath);
size = mln::filesystem::file_size(filePath);
}
ctx.getMetadata().metrics.fileSize.emplace(std::piecewise_construct,
@@ -1043,7 +1043,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
} else if (operationArray[0].GetString() == networkProbeStartOp) {
// probeNetworkStart
result.emplace_back([](TestContext&) {
mbgl::ProxyFileSource::setTrackingActive(true);
mln::ProxyFileSource::setTrackingActive(true);
return true;
});
} else if (operationArray[0].GetString() == networkProbeOp) {
@@ -1055,14 +1055,14 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
ctx.getMetadata().metrics.network.emplace(
std::piecewise_construct,
std::forward_as_tuple(std::move(mark)),
std::forward_as_tuple(mbgl::ProxyFileSource::getRequestCount(),
mbgl::ProxyFileSource::getTransferredSize()));
std::forward_as_tuple(mln::ProxyFileSource::getRequestCount(),
mln::ProxyFileSource::getTransferredSize()));
return true;
});
} else if (operationArray[0].GetString() == networkProbeEndOp) {
// probeNetworkEnd
result.emplace_back([](TestContext&) {
mbgl::ProxyFileSource::setTrackingActive(false);
mln::ProxyFileSource::setTrackingActive(false);
return true;
});
} else if (operationArray[0].GetString() == setFeatureStateOp) {
@@ -1071,8 +1071,8 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[1].IsObject());
assert(operationArray[2].IsObject());
using namespace mbgl;
using namespace mbgl::style::conversion;
using namespace mln;
using namespace mln::style::conversion;
std::string sourceID;
std::optional<std::string> sourceLayer;
@@ -1093,7 +1093,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
if (featureOptions["id"].IsString()) {
featureID = featureOptions["id"].GetString();
} else if (featureOptions["id"].IsNumber()) {
featureID = mbgl::util::toString(featureOptions["id"].GetUint64());
featureID = mln::util::toString(featureOptions["id"].GetUint64());
}
}
const JSValue* state = &operationArray[2];
@@ -1164,7 +1164,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
if (featureOptions["id"].IsString()) {
featureID = featureOptions["id"].GetString();
} else if (featureOptions["id"].IsNumber()) {
featureID = mbgl::util::toString(featureOptions["id"].GetUint64());
featureID = mln::util::toString(featureOptions["id"].GetUint64());
}
}
result.emplace_back([sourceID, sourceLayer, featureID](TestContext& ctx) {
@@ -1174,7 +1174,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
} catch (const std::exception&) {
return false;
}
mbgl::FeatureState state;
mln::FeatureState state;
frontend.getRenderer()->getFeatureState(state, sourceID, sourceLayer, featureID);
return true;
});
@@ -1199,7 +1199,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
if (featureOptions["id"].IsString()) {
featureID = featureOptions["id"].GetString();
} else if (featureOptions["id"].IsNumber()) {
featureID = mbgl::util::toString(featureOptions["id"].GetUint64());
featureID = mln::util::toString(featureOptions["id"].GetUint64());
}
}
@@ -1226,17 +1226,17 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
assert(operationArray[3].IsArray()); // start [lat, lng, zoom]
assert(operationArray[4].IsArray()); // end [lat, lng, zoom]
if (metadata.mapMode != mbgl::MapMode::Continuous) {
if (metadata.mapMode != mln::MapMode::Continuous) {
metadata.errorMessage = "Map mode must be Continuous for " + panGestureOp + " operation";
return {};
}
std::string mark = operationArray[1].GetString();
int duration = static_cast<int>(operationArray[2].GetFloat());
mbgl::LatLng startPos, endPos;
mln::LatLng startPos, endPos;
double startZoom, endZoom;
auto parsePosition = [](auto arr) -> std::tuple<mbgl::LatLng, double> {
auto parsePosition = [](auto arr) -> std::tuple<mln::LatLng, double> {
assert(arr.Size() >= 3);
return {{arr[1].GetDouble(), arr[0].GetDouble()}, arr[2].GetDouble()};
};
@@ -1250,7 +1250,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
auto& frontend = ctx.getFrontend();
std::vector<float> samples;
// Jump to the starting point of the segment and make sure there's something to render
map.jumpTo(mbgl::CameraOptions().withCenter(startPos).withZoom(startZoom));
map.jumpTo(mln::CameraOptions().withCenter(startPos).withZoom(startZoom));
observer.reset();
while (!observer.finishRenderingMap) {
@@ -1263,13 +1263,13 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
float totalTime = 0.0;
bool transitionFinished = false;
mbgl::AnimationOptions animationOptions(mbgl::Milliseconds(duration * 1000));
animationOptions.minZoom = mbgl::util::min(startZoom, endZoom);
mln::AnimationOptions animationOptions(mln::Milliseconds(duration * 1000));
animationOptions.minZoom = mln::util::min(startZoom, endZoom);
animationOptions.transitionFinishFn = [&]() {
transitionFinished = true;
};
map.flyTo(mbgl::CameraOptions().withCenter(endPos).withZoom(endZoom), animationOptions);
map.flyTo(mln::CameraOptions().withCenter(endPos).withZoom(endZoom), animationOptions);
while (!transitionFinished) {
frames++;
@@ -1286,7 +1286,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
// Use 1% of the longest frames to compute the minimum fps
std::sort(samples.begin(), samples.end());
int sampleCount = mbgl::util::max(1, (int)samples.size() / 100);
int sampleCount = mln::util::max(1, (int)samples.size() / 100);
for (auto it = samples.rbegin(); it != samples.rbegin() + sampleCount; it++) minFrameTime += *it;
float minOnePcFps = sampleCount / minFrameTime;
@@ -1318,7 +1318,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
auto& frontend = ctx.getFrontend();
// Render the map and fetch rendering stats
try {
mbgl::gfx::RenderingStats stats = frontend.render(ctx.getMap()).stats;
mln::gfx::RenderingStats stats = frontend.render(ctx.getMap()).stats;
ctx.activeGfxProbe = GfxProbe(stats, ctx.activeGfxProbe);
} catch (const std::exception&) {
return false;
@@ -1373,7 +1373,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
// setTileLodMode
assert(operationArray.Size() == 2u);
assert(operationArray[1].IsString());
mbgl::TileLodMode mode = mbgl::Enum<mbgl::TileLodMode>::toEnum(operationArray[1].GetString()).value();
mln::TileLodMode mode = mln::Enum<mln::TileLodMode>::toEnum(operationArray[1].GetString()).value();
result.emplace_back([mode](TestContext& ctx) {
ctx.getMap().setTileLodMode(mode);
return true;
@@ -1409,17 +1409,17 @@ std::string createResultItem(const TestMetadata& metadata, bool hasFailedTests)
if (!metadata.renderErrored) {
if (metadata.outputsImage) {
if (metadata.renderTest) {
html.append("<img width=" + mbgl::util::toString(metadata.size.width));
html.append(" height=" + mbgl::util::toString(metadata.size.height));
html.append("<img width=" + mln::util::toString(metadata.size.width));
html.append(" height=" + mln::util::toString(metadata.size.height));
html.append(" src=\"data:image/png;base64," + encodeBase64(metadata.actual) + "\"");
html.append(" data-alt-src=\"data:image/png;base64," + encodeBase64(metadata.expected) + "\">\n");
html.append("<img width=" + mbgl::util::toString(metadata.size.width));
html.append(" height=" + mbgl::util::toString(metadata.size.height));
html.append("<img width=" + mln::util::toString(metadata.size.width));
html.append(" height=" + mln::util::toString(metadata.size.height));
html.append(" src=\"data:image/png;base64," + encodeBase64(metadata.diff) + "\">\n");
} else {
html.append("<img width=" + mbgl::util::toString(metadata.size.width));
html.append(" height=" + mbgl::util::toString(metadata.size.height));
html.append("<img width=" + mln::util::toString(metadata.size.width));
html.append(" height=" + mln::util::toString(metadata.size.height));
html.append(" src=\"data:image/png;base64," + encodeBase64(metadata.actual) + "\">\n");
}
}
@@ -1436,7 +1436,7 @@ std::string createResultItem(const TestMetadata& metadata, bool hasFailedTests)
if (metadata.difference != 0.0) {
if (metadata.renderTest) {
html.append("<p class=\"diff\"><strong>Diff:</strong> " + mbgl::util::toString(metadata.difference) +
html.append("<p class=\"diff\"><strong>Diff:</strong> " + mln::util::toString(metadata.difference) +
"</p>\n");
} else {
html.append("<p class=\"diff\"><strong>Diff:</strong> " + metadata.diff + "</p>\n");
@@ -1460,7 +1460,7 @@ std::string createResultPage(const TestStatistics& stats,
// Header
if (unsuccessful) {
resultsPage.append(R"HTML(<h1 style="color: red;">)HTML");
resultsPage.append(mbgl::util::toString(unsuccessful) + " tests failed.");
resultsPage.append(mln::util::toString(unsuccessful) + " tests failed.");
} else {
resultsPage.append(R"HTML(<h1 style="color: green;">)HTML");
resultsPage.append("All tests passed!");
@@ -1470,18 +1470,18 @@ std::string createResultPage(const TestStatistics& stats,
// stats
resultsPage.append(R"HTML(<p class="stats">)HTML");
if (stats.ignoreFailedTests) {
resultsPage.append(mbgl::util::toString(stats.ignoreFailedTests) + " ignored failed, ");
resultsPage.append(mln::util::toString(stats.ignoreFailedTests) + " ignored failed, ");
}
if (stats.ignorePassedTests) {
resultsPage.append(mbgl::util::toString(stats.ignorePassedTests) + " ignored passed, ");
resultsPage.append(mln::util::toString(stats.ignorePassedTests) + " ignored passed, ");
}
if (stats.erroredTests) {
resultsPage.append(mbgl::util::toString(stats.erroredTests) + " errored, ");
resultsPage.append(mln::util::toString(stats.erroredTests) + " errored, ");
}
if (stats.failedTests) {
resultsPage.append(mbgl::util::toString(stats.failedTests) + " failed, ");
resultsPage.append(mln::util::toString(stats.failedTests) + " failed, ");
}
resultsPage.append(mbgl::util::toString(stats.passedTests) + " passed.\n");
resultsPage.append(mln::util::toString(stats.passedTests) + " passed.\n");
resultsPage.append("</p>\n");
// Test sequence
@@ -1508,7 +1508,7 @@ std::string createResultPage(const TestStatistics& stats,
// Shuffle
if (shuffle) {
resultsPage.append("<p><strong>Shuffle seed</strong>: " + mbgl::util::toString(seed) + "</p>\n");
resultsPage.append("<p><strong>Shuffle seed</strong>: " + mln::util::toString(seed) + "</p>\n");
}
resultsPage.append("</div>\n");

View File

@@ -12,25 +12,25 @@
class Manifest;
using ErrorMessage = std::string;
using JSONReply = mbgl::variant<mbgl::JSDocument, ErrorMessage>;
using JSONReply = mln::variant<mln::JSDocument, ErrorMessage>;
JSONReply readJson(const mbgl::filesystem::path&);
std::string serializeJsonValue(const mbgl::JSValue&);
JSONReply readJson(const mln::filesystem::path&);
std::string serializeJsonValue(const mln::JSValue&);
std::string serializeMetrics(const TestMetrics&);
std::vector<std::string> readExpectedImageEntries(const mbgl::filesystem::path& base);
std::vector<std::string> readExpectedMetricEntries(const mbgl::filesystem::path& base);
std::vector<std::string> readExpectedJSONEntries(const mbgl::filesystem::path& base);
std::vector<std::string> readExpectedImageEntries(const mln::filesystem::path& base);
std::vector<std::string> readExpectedMetricEntries(const mln::filesystem::path& base);
std::vector<std::string> readExpectedJSONEntries(const mln::filesystem::path& base);
TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path);
TestMetrics readExpectedMetrics(const mln::filesystem::path& path);
TestMetadata parseTestMetadata(const TestPaths& paths);
TestOperations parseTestOperations(TestMetadata& metadata);
std::string createResultPage(const TestStatistics&, const std::vector<TestMetadata>&, bool shuffle, uint32_t seed);
std::string toJSON(const mbgl::Value& value, unsigned indent, bool singleLine);
std::string toJSON(const std::vector<mbgl::Feature>& features, unsigned indent, bool singleLine);
std::string toJSON(const mln::Value& value, unsigned indent, bool singleLine);
std::string toJSON(const std::vector<mln::Feature>& features, unsigned indent, bool singleLine);
namespace TestOperationNames {
extern const std::string waitOp;

View File

@@ -94,26 +94,26 @@ ArgumentsTuple parseArguments(int argc, char** argv) {
} catch (const args::Help&) {
std::ostringstream stream;
stream << argumentParser;
mbgl::Log::Info(mbgl::Event::General, stream.str());
mln::Log::Info(mln::Event::General, stream.str());
exit(0);
} catch (const args::ParseError& e) {
std::ostringstream stream;
stream << argumentParser;
mbgl::Log::Info(mbgl::Event::General, stream.str());
mbgl::Log::Error(mbgl::Event::General, e.what());
mln::Log::Info(mln::Event::General, stream.str());
mln::Log::Error(mln::Event::General, e.what());
exit(1);
} catch (const args::ValidationError& e) {
std::ostringstream stream;
stream << argumentParser;
mbgl::Log::Info(mbgl::Event::General, stream.str());
mbgl::Log::Error(mbgl::Event::General, e.what());
mln::Log::Info(mln::Event::General, stream.str());
mln::Log::Error(mln::Event::General, e.what());
exit(2);
}
mbgl::filesystem::path manifestPath = args::get(testPathValue);
if (!mbgl::filesystem::exists(manifestPath) || !manifestPath.has_filename()) {
mbgl::Log::Error(mbgl::Event::General,
"Provided test manifest file path '" + manifestPath.string() + "' does not exist");
mln::filesystem::path manifestPath = args::get(testPathValue);
if (!mln::filesystem::exists(manifestPath) || !manifestPath.has_filename()) {
mln::Log::Error(mln::Event::General,
"Provided test manifest file path '" + manifestPath.string() + "' does not exist");
exit(3);
}
@@ -183,7 +183,7 @@ void runWithAlternateSources(TestRunner& runner, TestMetadata& metadata, bool& e
}
}
} // namespace
namespace mbgl {
namespace mln {
int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testStatus) {
int returnCode = 0;
@@ -205,7 +205,7 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
if (!manifestData) {
exit(5);
}
mbgl::util::RunLoop runLoop;
mln::util::RunLoop runLoop;
TestRunner runner(std::move(*manifestData), updateResults);
if (shuffle) {
printf(ANSI_COLOR_YELLOW "Shuffle seed: %d" ANSI_COLOR_RESET "\n", seed);
@@ -216,7 +216,7 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
#if MLN_RENDER_BACKEND_METAL
printf(ANSI_COLOR_YELLOW "Using GPU Expression Evaluation" ANSI_COLOR_RESET "\n");
mbgl::gfx::Backend::setEnableGPUExpressionEval(true);
mln::gfx::Backend::setEnableGPUExpressionEval(true);
#endif // MLN_RENDER_BACKEND_METAL
const auto& manifest = runner.getManifest();
@@ -247,7 +247,7 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
bool shouldIgnore = false;
std::string ignoreReason;
const mbgl::filesystem::path ignoreName(id);
const mln::filesystem::path ignoreName(id);
const auto it = std::find_if(
ignores.cbegin(), ignores.cend(), [&ignoreName](auto pair) { return pair.first == ignoreName; });
if (it != ignores.end()) {
@@ -255,7 +255,7 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
ignoreReason = it->second;
if (ignoreReason.starts_with("skip")) {
printf(ANSI_COLOR_GRAY "* skipped %s (%s)" ANSI_COLOR_RESET "\n", id.c_str(), ignoreReason.c_str());
mbgl::Log::Info(mbgl::Event::General, "* skipped " + id + "(" + ignoreReason + ")");
mln::Log::Info(mln::Event::General, "* skipped " + id + "(" + ignoreReason + ")");
continue;
}
}
@@ -280,14 +280,14 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
color = "#E8A408";
stats.ignorePassedTests++;
printf(ANSI_COLOR_YELLOW "* ignore %s (%s)" ANSI_COLOR_RESET "\n", id.c_str(), ignoreReason.c_str());
mbgl::Log::Info(mbgl::Event::General, "* ignore " + id + " (" + ignoreReason + ")");
mln::Log::Info(mln::Event::General, "* ignore " + id + " (" + ignoreReason + ")");
} else {
status = "ignored failed";
color = "#9E9E9E";
stats.ignoreFailedTests++;
printf(
ANSI_COLOR_LIGHT_GRAY "* ignore %s (%s)" ANSI_COLOR_RESET "\n", id.c_str(), ignoreReason.c_str());
mbgl::Log::Info(mbgl::Event::General, "* ignore " + id + " (" + ignoreReason + ")");
mln::Log::Info(mln::Event::General, "* ignore " + id + " (" + ignoreReason + ")");
}
} else {
// Only fail the bots on render errors, this is a CI limitation that
@@ -304,7 +304,7 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
color = "green";
stats.passedTests++;
printf(ANSI_COLOR_GREEN "* passed %s" ANSI_COLOR_RESET "\n", id.c_str());
mbgl::Log::Info(mbgl::Event::General, "* passed " + id);
mln::Log::Info(mln::Event::General, "* passed " + id);
} else if (errored) {
status = "errored";
color = "red";
@@ -312,15 +312,15 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
returnCode = 2;
printf(ANSI_COLOR_RED "* errored %s" ANSI_COLOR_RESET "\n", id.c_str());
printf(ANSI_COLOR_RED "* error: %s" ANSI_COLOR_RESET "\n", metadata.errorMessage.c_str());
mbgl::Log::Info(mbgl::Event::General, "* errored " + id);
mbgl::Log::Info(mbgl::Event::General, "* error " + metadata.errorMessage);
mln::Log::Info(mln::Event::General, "* errored " + id);
mln::Log::Info(mln::Event::General, "* error " + metadata.errorMessage);
} else {
status = "failed";
color = "red";
stats.failedTests++;
returnCode = 3;
printf(ANSI_COLOR_RED "* failed %s" ANSI_COLOR_RESET "\n", id.c_str());
mbgl::Log::Info(mbgl::Event::General, "* failed " + id);
mln::Log::Info(mln::Event::General, "* failed " + id);
}
}
@@ -330,10 +330,10 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
}
}
const std::string manifestName = mbgl::filesystem::path(manifestPath).stem().generic_string();
const std::string manifestName = mln::filesystem::path(manifestPath).stem().generic_string();
const std::string resultPath = manifest.getResultPath() + "/" + manifestName + ".html";
std::string resultsHTML = createResultPage(stats, metadatas, shuffle, seed);
mbgl::util::write_file(resultPath, resultsHTML);
mln::util::write_file(resultPath, resultsHTML);
const uint32_t count = stats.erroredTests + stats.failedTests + stats.ignoreFailedTests + stats.ignorePassedTests +
stats.passedTests;
@@ -342,37 +342,36 @@ int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testSt
printf(ANSI_COLOR_GREEN "%u passed (%.1lf%%)" ANSI_COLOR_RESET "\n",
stats.passedTests,
100.0 * stats.passedTests / count);
mbgl::Log::Info(mbgl::Event::General, std::to_string(stats.passedTests) + " passed tests");
mln::Log::Info(mln::Event::General, std::to_string(stats.passedTests) + " passed tests");
}
if (stats.ignorePassedTests) {
printf(ANSI_COLOR_YELLOW "%u passed but were ignored (%.1lf%%)" ANSI_COLOR_RESET "\n",
stats.ignorePassedTests,
100.0 * stats.ignorePassedTests / count);
mbgl::Log::Info(mbgl::Event::General,
std::to_string(stats.ignorePassedTests) + " passed tests but were ignored");
mln::Log::Info(mln::Event::General, std::to_string(stats.ignorePassedTests) + " passed tests but were ignored");
}
if (stats.ignoreFailedTests) {
printf(ANSI_COLOR_LIGHT_GRAY "%u ignored (%.1lf%%)" ANSI_COLOR_RESET "\n",
stats.ignoreFailedTests,
100.0 * stats.ignoreFailedTests / count);
mbgl::Log::Info(mbgl::Event::General, std::to_string(stats.ignoreFailedTests) + " ignored tests");
mln::Log::Info(mln::Event::General, std::to_string(stats.ignoreFailedTests) + " ignored tests");
}
if (stats.failedTests) {
printf(ANSI_COLOR_RED "%u failed (%.1lf%%)" ANSI_COLOR_RESET "\n",
stats.failedTests,
100.0 * stats.failedTests / count);
mbgl::Log::Info(mbgl::Event::General, std::to_string(stats.failedTests) + " failed tests");
mln::Log::Info(mln::Event::General, std::to_string(stats.failedTests) + " failed tests");
}
if (stats.erroredTests) {
printf(ANSI_COLOR_RED "%u errored (%.1lf%%)" ANSI_COLOR_RESET "\n",
stats.erroredTests,
100.0 * stats.erroredTests / count);
mbgl::Log::Info(mbgl::Event::General, std::to_string(stats.erroredTests) + " errored tests");
mln::Log::Info(mln::Event::General, std::to_string(stats.erroredTests) + " errored tests");
}
printf("Results at: %s\n", mbgl::filesystem::canonical(resultPath).generic_string().c_str());
printf("Results at: %s\n", mln::filesystem::canonical(resultPath).generic_string().c_str());
return returnCode;
}
} // namespace mbgl
} // namespace mln

View File

@@ -34,10 +34,10 @@
#include <codecvt>
#include <locale>
using namespace mbgl;
using namespace mln;
using namespace TestOperationNames;
GfxProbe::GfxProbe(const mbgl::gfx::RenderingStats& stats, const GfxProbe& prev)
GfxProbe::GfxProbe(const mln::gfx::RenderingStats& stats, const GfxProbe& prev)
: numBuffers(stats.numBuffers),
numDrawCalls(stats.numDrawCalls),
numFrameBuffers(stats.numFrameBuffers),
@@ -99,18 +99,18 @@ TestRunner::TestRunner(Manifest manifest_, UpdateResults updateResults_)
void TestRunner::registerProxyFileSource() {
static std::once_flag registerProxyFlag;
std::call_once(registerProxyFlag, [] {
auto* fileSourceManager = mbgl::FileSourceManager::get();
auto* fileSourceManager = mln::FileSourceManager::get();
auto resourceLoaderFactory = fileSourceManager->unRegisterFileSourceFactory(
mbgl::FileSourceType::ResourceLoader);
auto factory = [defaultFactory = std::move(resourceLoaderFactory)](const mbgl::ResourceOptions& resourceOptions,
const mbgl::ClientOptions& clientOptions) {
mln::FileSourceType::ResourceLoader);
auto factory = [defaultFactory = std::move(resourceLoaderFactory)](const mln::ResourceOptions& resourceOptions,
const mln::ClientOptions& clientOptions) {
assert(defaultFactory);
std::shared_ptr<FileSource> fileSource = defaultFactory(resourceOptions, clientOptions);
return std::make_unique<ProxyFileSource>(std::move(fileSource), resourceOptions, clientOptions);
};
fileSourceManager->registerFileSourceFactory(mbgl::FileSourceType::ResourceLoader, std::move(factory));
fileSourceManager->registerFileSourceFactory(mln::FileSourceType::ResourceLoader, std::move(factory));
});
}
@@ -122,13 +122,13 @@ void TestRunner::doShuffle(uint32_t seed) {
manifest.doShuffle(seed);
}
void TestRunner::checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
std::vector<mbgl::Feature>&& features,
void TestRunner::checkQueryTestResults(mln::PremultipliedImage&& actualImage,
std::vector<mln::Feature>&& features,
TestMetadata& metadata) {
const std::string& base = metadata.paths.defaultExpectations();
const std::vector<mbgl::filesystem::path>& expectations = metadata.paths.expectations;
const std::vector<mln::filesystem::path>& expectations = metadata.paths.expectations;
metadata.actual = mbgl::encodePNG(actualImage);
metadata.actual = mln::encodePNG(actualImage);
if (actualImage.size.isEmpty()) {
metadata.errorMessage = "Invalid size for actual image";
@@ -145,22 +145,22 @@ void TestRunner::checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
}
if (updateResults == UpdateResults::PLATFORM) {
mbgl::filesystem::create_directories(expectations.back());
mbgl::util::write_file(expectations.back().string() + "/expected.json", metadata.actualJson);
mln::filesystem::create_directories(expectations.back());
mln::util::write_file(expectations.back().string() + "/expected.json", metadata.actualJson);
metadata.renderErrored++;
return;
} else if (updateResults == UpdateResults::DEFAULT) {
mbgl::util::write_file(base + "/expected.json", metadata.actualJson);
mln::util::write_file(base + "/expected.json", metadata.actualJson);
metadata.renderErrored++;
return;
}
mbgl::util::write_file(base + "/actual.json", metadata.actualJson);
mln::util::write_file(base + "/actual.json", metadata.actualJson);
std::vector<std::string> expectedJsonPaths;
mbgl::filesystem::path expectedMetricsPath;
mln::filesystem::path expectedMetricsPath;
for (auto rit = expectations.rbegin(); rit != expectations.rend(); ++rit) {
if (mbgl::filesystem::exists(*rit)) {
if (mln::filesystem::exists(*rit)) {
expectedJsonPaths = readExpectedJSONEntries(*rit);
if (!expectedJsonPaths.empty()) break;
}
@@ -174,10 +174,10 @@ void TestRunner::checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
for (const auto& entry : expectedJsonPaths) {
auto maybeExpectedJson = readJson(entry);
if (maybeExpectedJson.is<mbgl::JSDocument>()) {
auto& expected = maybeExpectedJson.get<mbgl::JSDocument>();
if (maybeExpectedJson.is<mln::JSDocument>()) {
auto& expected = maybeExpectedJson.get<mln::JSDocument>();
mbgl::JSDocument actual;
mln::JSDocument actual;
actual.Parse<0>(metadata.actualJson);
if (actual.HasParseError()) {
metadata.errorMessage = "Error parsing actual JSON for: " + metadata.paths.stylePath.string();
@@ -204,12 +204,12 @@ void TestRunner::checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
}
}
void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage, TestMetadata& metadata) {
void TestRunner::checkRenderTestResults(mln::PremultipliedImage&& actualImage, TestMetadata& metadata) {
const std::string& base = metadata.paths.defaultExpectations();
const std::vector<mbgl::filesystem::path>& expectations = metadata.paths.expectations;
const std::vector<mln::filesystem::path>& expectations = metadata.paths.expectations;
if (metadata.outputsImage) {
metadata.actual = mbgl::encodePNG(actualImage);
metadata.actual = mln::encodePNG(actualImage);
if (actualImage.size.isEmpty()) {
metadata.errorMessage = "Invalid size for actual image";
@@ -218,25 +218,25 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
}
if (updateResults == UpdateResults::PLATFORM) {
mbgl::filesystem::create_directories(expectations.back());
mbgl::util::write_file(expectations.back().string() + "/expected.png", mbgl::encodePNG(actualImage));
mln::filesystem::create_directories(expectations.back());
mln::util::write_file(expectations.back().string() + "/expected.png", mln::encodePNG(actualImage));
metadata.renderErrored++;
return;
} else if (updateResults == UpdateResults::DEFAULT) {
mbgl::util::write_file(base + "/expected.png", mbgl::encodePNG(actualImage));
mln::util::write_file(base + "/expected.png", mln::encodePNG(actualImage));
metadata.renderErrored++;
return;
}
mbgl::util::write_file(base + "/actual.png", metadata.actual);
mln::util::write_file(base + "/actual.png", metadata.actual);
mbgl::PremultipliedImage expectedImage{actualImage.size};
mbgl::PremultipliedImage imageDiff{actualImage.size};
mln::PremultipliedImage expectedImage{actualImage.size};
mln::PremultipliedImage imageDiff{actualImage.size};
double pixels = 0.0;
std::vector<std::string> expectedImagesPaths;
for (auto rit = expectations.rbegin(); rit != expectations.rend(); ++rit) {
if (mbgl::filesystem::exists(*rit)) {
if (mln::filesystem::exists(*rit)) {
expectedImagesPaths = readExpectedImageEntries(*rit);
if (!expectedImagesPaths.empty()) break;
}
@@ -249,7 +249,7 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
}
for (const auto& entry : expectedImagesPaths) {
std::optional<std::string> maybeExpectedImage = mbgl::util::readFile(entry);
std::optional<std::string> maybeExpectedImage = mln::util::readFile(entry);
if (!maybeExpectedImage) {
metadata.errorMessage = "Failed to load expected image " + entry;
metadata.renderErrored++;
@@ -258,7 +258,7 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
metadata.expected = *maybeExpectedImage;
expectedImage = mbgl::decodeImage(*maybeExpectedImage);
expectedImage = mln::decodeImage(*maybeExpectedImage);
pixels = static_cast<double>(mapbox::pixelmatch(actualImage.data.get(),
expectedImage.data.get(),
@@ -268,9 +268,9 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
0.1285) // Defined in GL JS
);
metadata.diff = mbgl::encodePNG(imageDiff);
metadata.diff = mln::encodePNG(imageDiff);
mbgl::util::write_file(base + "/diff.png", metadata.diff);
mln::util::write_file(base + "/diff.png", metadata.diff);
metadata.difference = pixels / expectedImage.size.area();
if (metadata.difference <= metadata.allowed) {
@@ -286,13 +286,13 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
void TestRunner::checkProbingResults(TestMetadata& resultMetadata) {
if (resultMetadata.metrics.isEmpty()) return;
const auto writeMetrics = [&resultMetadata](const mbgl::filesystem::path& path,
const auto writeMetrics = [&resultMetadata](const mln::filesystem::path& path,
const std::string& message = std::string()) {
try {
mbgl::filesystem::create_directories(path);
mbgl::util::write_file((path / "metrics.json").generic_string(), serializeMetrics(resultMetadata.metrics));
mln::filesystem::create_directories(path);
mln::util::write_file((path / "metrics.json").generic_string(), serializeMetrics(resultMetadata.metrics));
resultMetadata.errorMessage += message;
} catch (mbgl::filesystem::filesystem_error& ex) {
} catch (mln::filesystem::filesystem_error& ex) {
const auto msg = "Failed to write metrics. path='" + path.string() + "' err='" + ex.what() +
"' msg=" + message;
resultMetadata.errorMessage += msg;
@@ -300,7 +300,7 @@ void TestRunner::checkProbingResults(TestMetadata& resultMetadata) {
}
};
const std::vector<mbgl::filesystem::path>& expectedMetrics = resultMetadata.paths.expectedMetrics;
const std::vector<mln::filesystem::path>& expectedMetrics = resultMetadata.paths.expectedMetrics;
if (updateResults == UpdateResults::METRICS) {
writeMetrics(expectedMetrics.back(), " Updated expected metrics.");
resultMetadata.metricsErrored++;
@@ -311,7 +311,7 @@ void TestRunner::checkProbingResults(TestMetadata& resultMetadata) {
// the test style will only be checked in the very end.
std::vector<std::string> expectedMetricsPaths;
for (auto rit = expectedMetrics.rbegin(); rit != expectedMetrics.rend(); ++rit) {
if (mbgl::filesystem::exists(*rit)) {
if (mln::filesystem::exists(*rit)) {
expectedMetricsPaths = readExpectedMetricEntries(*rit);
if (!expectedMetricsPaths.empty()) break;
}
@@ -659,7 +659,7 @@ void resetContext(const TestMetadata& metadata, TestContext& ctx) {
ctx.getFrontend().setSize(metadata.size);
auto& map = ctx.getMap();
map.setSize(metadata.size);
map.setProjectionMode(mbgl::ProjectionMode()
map.setProjectionMode(mln::ProjectionMode()
.withAxonometric(metadata.axonometric)
.withXSkew(metadata.xSkew)
.withYSkew(metadata.ySkew));
@@ -690,15 +690,15 @@ uint32_t getImageTileOffset(const std::set<uint32_t>& dims, uint32_t dim, float
} // namespace
TestRunner::Impl::Impl(const TestMetadata& metadata,
const mbgl::ResourceOptions& resourceOptions,
const mbgl::ClientOptions& clientOptions)
const mln::ResourceOptions& resourceOptions,
const mln::ClientOptions& clientOptions)
: observer(std::make_unique<TestRunnerMapObserver>()),
frontend(metadata.size, metadata.pixelRatio, swapBehavior(metadata.mapMode)),
fileSource(mbgl::FileSourceManager::get()->getFileSource(
mbgl::FileSourceType::ResourceLoader, resourceOptions, clientOptions)),
fileSource(mln::FileSourceManager::get()->getFileSource(
mln::FileSourceType::ResourceLoader, resourceOptions, clientOptions)),
map(frontend,
*observer,
mbgl::MapOptions()
mln::MapOptions()
.withMapMode(metadata.mapMode)
.withSize(metadata.size)
.withPixelRatio(metadata.pixelRatio)
@@ -752,15 +752,14 @@ void TestRunner::run(TestMetadata& metadata) {
}
}
std::string key = mbgl::util::toString(uint32_t(metadata.mapMode)) + "/" +
mbgl::util::toString(metadata.pixelRatio) + "/" +
mbgl::util::toString(uint32_t(metadata.crossSourceCollisions));
std::string key = mln::util::toString(uint32_t(metadata.mapMode)) + "/" + mln::util::toString(metadata.pixelRatio) +
"/" + mln::util::toString(uint32_t(metadata.crossSourceCollisions));
if (maps.find(key) == maps.end()) {
maps[key] = std::make_unique<TestRunner::Impl>(
metadata,
mbgl::ResourceOptions().withCachePath(manifest.getCachePath()).withApiKey(manifest.getApiKey()),
mbgl::ClientOptions());
mln::ResourceOptions().withCachePath(manifest.getCachePath()).withApiKey(manifest.getApiKey()),
mln::ClientOptions());
}
ctx.runnerImpl = maps[key].get();
@@ -908,7 +907,7 @@ void TestRunner::run(TestMetadata& metadata) {
appendLabelCutOffResults(metadata, cutOffLabelsReport, duplicationsReport);
checkRenderTestResults(std::move(result.image), metadata);
} else {
std::vector<mbgl::Feature> features;
std::vector<mln::Feature> features;
assert(metadata.document["metadata"]["test"]["queryGeometry"].IsArray());
if (metadata.document["metadata"]["test"]["queryGeometry"][0].IsNumber() &&
metadata.document["metadata"]["test"]["queryGeometry"][1].IsNumber()) {
@@ -933,7 +932,7 @@ void TestRunner::appendLabelCutOffResults(TestMetadata& resultMetadata,
}
}
mbgl::HeadlessFrontend::RenderResult TestRunner::runTest(TestMetadata& metadata, TestContext& ctx) {
mln::HeadlessFrontend::RenderResult TestRunner::runTest(TestMetadata& metadata, TestContext& ctx) {
HeadlessFrontend::RenderResult result{};
for (const auto& operation : parseTestOperations(metadata)) {
if (!operation(ctx)) return result;

View File

@@ -12,10 +12,10 @@
class TestRunnerMapObserver;
struct TestMetadata;
class TestRunnerMapObserver : public mbgl::MapObserver {
class TestRunnerMapObserver : public mln::MapObserver {
public:
TestRunnerMapObserver() = default;
void onDidFailLoadingMap(mbgl::MapLoadError, const std::string&) override { mapLoadFailure = true; }
void onDidFailLoadingMap(mln::MapLoadError, const std::string&) override { mapLoadFailure = true; }
void onDidFinishRenderingMap(RenderMode mode) override final {
if (!finishRenderingMap) finishRenderingMap = mode == RenderMode::Full;
@@ -53,23 +53,23 @@ 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,
mln::HeadlessFrontend::RenderResult runTest(TestMetadata& metadata, TestContext& ctx);
void checkQueryTestResults(mln::PremultipliedImage&& actualImage,
std::vector<mln::Feature>&& features,
TestMetadata&);
void checkRenderTestResults(mbgl::PremultipliedImage&& image, TestMetadata&);
void checkRenderTestResults(mln::PremultipliedImage&& image, TestMetadata&);
void checkProbingResults(TestMetadata&);
void appendLabelCutOffResults(TestMetadata&, const std::string&, const std::string&);
void registerProxyFileSource();
struct Impl {
Impl(const TestMetadata&, const mbgl::ResourceOptions&, const mbgl::ClientOptions&);
Impl(const TestMetadata&, const mln::ResourceOptions&, const mln::ClientOptions&);
~Impl();
std::unique_ptr<TestRunnerMapObserver> observer;
mbgl::HeadlessFrontend frontend;
std::shared_ptr<mbgl::FileSource> fileSource;
mbgl::Map map;
mln::HeadlessFrontend frontend;
std::shared_ptr<mln::FileSource> fileSource;
mln::Map map;
};
std::unordered_map<std::string, std::unique_ptr<Impl>> maps;
Manifest manifest;