Add support for parsing MLT-format vector tile sources (#3246)
Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
@@ -131,6 +131,57 @@ ArgumentsTuple parseArguments(int argc, char** argv) {
|
||||
updateResults,
|
||||
std::move(testFilter)};
|
||||
}
|
||||
|
||||
void runWithAlternateSources(TestRunner& runner, TestMetadata& metadata, bool& errored, bool& passed) {
|
||||
constexpr auto replacementsKey = "source-replace";
|
||||
constexpr auto targetKey = "replace";
|
||||
constexpr auto sourceKey = "with";
|
||||
constexpr auto sourcesKey = "sources";
|
||||
|
||||
if (!metadata.document.HasMember("metadata") || !metadata.document["metadata"].HasMember("test")) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& testElement = metadata.document["metadata"]["test"];
|
||||
if (!testElement.HasMember(replacementsKey) || !testElement[replacementsKey].IsArray()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& replacesElement = testElement[replacementsKey];
|
||||
if (!replacesElement.IsArray() || replacesElement.Empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& sources = metadata.document[sourcesKey];
|
||||
|
||||
// Each item in the source replacements array...
|
||||
for (auto i = replacesElement.Begin(); i != replacesElement.End(); ++i) {
|
||||
const auto& entry = *i;
|
||||
if (entry.IsObject() && entry.HasMember(targetKey) && entry.HasMember(sourceKey) &&
|
||||
entry[targetKey].IsString() && entry[sourceKey].IsString()) {
|
||||
const auto* targetName = entry[targetKey].GetString();
|
||||
const auto* sourceName = entry[sourceKey].GetString();
|
||||
if (sources.HasMember(targetName) && sources[targetName].IsObject() && sources.HasMember(sourceName) &&
|
||||
sources[sourceName].IsObject()) {
|
||||
// Swap the named sources
|
||||
sources[targetName].Swap(sources[sourceName]);
|
||||
|
||||
// run the test again with the new source
|
||||
runner.run(metadata);
|
||||
|
||||
// Restore the original source
|
||||
sources[targetName].Swap(sources[sourceName]);
|
||||
|
||||
// stop if the test fails
|
||||
errored = metadata.metricsErrored || metadata.renderErrored || metadata.labelCutOffFound;
|
||||
passed = !errored && !metadata.metricsFailed && !metadata.renderFailed;
|
||||
if (!passed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
namespace mbgl {
|
||||
|
||||
@@ -200,7 +251,7 @@ int runRenderTests(int argc, char** argv, std::function<void()> testStatus) {
|
||||
if (it != ignores.end()) {
|
||||
metadata.ignoredTest = shouldIgnore = true;
|
||||
ignoreReason = it->second;
|
||||
if (ignoreReason.rfind("skip", 0) == 0) {
|
||||
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 + ")");
|
||||
continue;
|
||||
@@ -217,6 +268,10 @@ int runRenderTests(int argc, char** argv, std::function<void()> testStatus) {
|
||||
bool errored = metadata.metricsErrored || metadata.renderErrored || metadata.labelCutOffFound;
|
||||
bool passed = !errored && !metadata.metricsFailed && !metadata.renderFailed;
|
||||
|
||||
if (passed) {
|
||||
runWithAlternateSources(runner, metadata, errored, passed);
|
||||
}
|
||||
|
||||
if (shouldIgnore) {
|
||||
if (passed) {
|
||||
status = "ignored passed";
|
||||
|
||||
Reference in New Issue
Block a user