diff options
author | zmiao <miao.zhao@mapbox.com> | 2020-02-07 15:34:01 +0200 |
---|---|---|
committer | zmiao <miao.zhao@mapbox.com> | 2020-02-12 12:24:05 +0200 |
commit | 2963afa010e75bb8bc3c20150c06c5779121077d (patch) | |
tree | 009843afa585563a0bb0d2dfee41edfe1ec70baf /expression-test | |
parent | 1bd2ccf2398004b02b479e6ad3144f52e7631b2a (diff) | |
download | qtlocation-mapboxgl-2963afa010e75bb8bc3c20150c06c5779121077d.tar.gz |
Add support for expression test
Fix polygon within algorithm
Add Unit tests
Fix incorrect metrics folder for ios-render-test-runner job
Diffstat (limited to 'expression-test')
-rw-r--r-- | expression-test/expression_test_parser.cpp | 30 | ||||
-rw-r--r-- | expression-test/expression_test_parser.hpp | 3 | ||||
-rw-r--r-- | expression-test/expression_test_runner.cpp | 10 |
3 files changed, 37 insertions, 6 deletions
diff --git a/expression-test/expression_test_parser.cpp b/expression-test/expression_test_parser.cpp index 44f8bebf5e..0d414cc2c0 100644 --- a/expression-test/expression_test_parser.cpp +++ b/expression-test/expression_test_parser.cpp @@ -14,6 +14,8 @@ #include <args.hxx> +#include <regex> + using namespace mbgl; using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -254,6 +256,19 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) { heatmapDensity = evaluationContext["heatmapDensity"].GetDouble(); } + // Parse canonicalID + optional<CanonicalTileID> canonical; + if (evaluationContext.HasMember("canonicalID")) { + assert(evaluationContext["canonicalID"].IsObject()); + assert( + evaluationContext["canonicalID"].HasMember("z") && evaluationContext["canonicalID"]["z"].IsNumber() && + evaluationContext["canonicalID"].HasMember("x") && evaluationContext["canonicalID"]["x"].IsNumber() && + evaluationContext["canonicalID"].HasMember("y") && evaluationContext["canonicalID"]["y"].IsNumber()); + canonical = CanonicalTileID(evaluationContext["canonicalID"]["z"].GetUint(), + evaluationContext["canonicalID"]["x"].GetUint(), + evaluationContext["canonicalID"]["y"].GetUint()); + } + // Parse availableImages std::set<std::string> availableImages; if (evaluationContext.HasMember("availableImages")) { @@ -282,8 +297,11 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) { feature.id = mapbox::geojson::convert<mapbox::feature::identifier>(featureObject["id"]); } - data.inputs.emplace_back( - std::move(zoom), std::move(heatmapDensity), std::move(availableImages), std::move(feature)); + data.inputs.emplace_back(std::move(zoom), + std::move(heatmapDensity), + std::move(canonical), + std::move(availableImages), + std::move(feature)); } return true; } @@ -294,11 +312,11 @@ std::tuple<filesystem::path, std::vector<filesystem::path>, bool, uint32_t> pars args::ArgumentParser argumentParser("Mapbox GL Expression Test Runner"); args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", { 'h', "help" }); - args::Flag shuffleFlag(argumentParser, "shuffle", "Toggle shuffling the tests order", - { 's', "shuffle" }); + args::Flag shuffleFlag(argumentParser, "shuffle", "Toggle shuffling the tests order", {'s', "shuffle"}); args::ValueFlag<uint32_t> seedValue(argumentParser, "seed", "Shuffle seed (default: random)", { "seed" }); args::PositionalList<std::string> testNameValues(argumentParser, "URL", "Test name(s)"); + args::ValueFlag<std::string> testFilterValue(argumentParser, "filter", "Test filter regex", {'f', "filter"}); try { argumentParser.ParseCLI(argc, argv); @@ -336,6 +354,7 @@ std::tuple<filesystem::path, std::vector<filesystem::path>, bool, uint32_t> pars paths.emplace_back(rootPath); } + auto testFilter = testFilterValue ? args::get(testFilterValue) : std::string{}; // Recursively traverse through the test paths and collect test directories containing "test.json". std::vector<filesystem::path> testPaths; testPaths.reserve(paths.size()); @@ -346,6 +365,9 @@ std::tuple<filesystem::path, std::vector<filesystem::path>, bool, uint32_t> pars } for (auto& testPath : filesystem::recursive_directory_iterator(path)) { + if (!testFilter.empty() && !std::regex_search(testPath.path().string(), std::regex(testFilter))) { + continue; + } if (testPath.path().filename() == "test.json") { testPaths.emplace_back(testPath.path()); } diff --git a/expression-test/expression_test_parser.hpp b/expression-test/expression_test_parser.hpp index 842d8a1563..b73dbf0539 100644 --- a/expression-test/expression_test_parser.hpp +++ b/expression-test/expression_test_parser.hpp @@ -16,14 +16,17 @@ using namespace mbgl; struct Input { Input(optional<float> zoom_, optional<double> heatmapDensity_, + optional<CanonicalTileID> canonical_, std::set<std::string> availableImages_, Feature feature_) : zoom(std::move(zoom_)), heatmapDensity(std::move(heatmapDensity_)), + canonical(std::move(canonical_)), availableImages(std::move(availableImages_)), feature(std::move(feature_)) {} optional<float> zoom; optional<double> heatmapDensity; + optional<CanonicalTileID> canonical; std::set<std::string> availableImages; Feature feature; }; diff --git a/expression-test/expression_test_runner.cpp b/expression-test/expression_test_runner.cpp index 436e449921..c0d4511636 100644 --- a/expression-test/expression_test_runner.cpp +++ b/expression-test/expression_test_runner.cpp @@ -104,8 +104,14 @@ TestRunOutput runExpressionTest(TestData& data, const std::string& rootPath, con std::vector<Value> outputs; if (!data.inputs.empty()) { for (const auto& input : data.inputs) { - auto evaluationResult = - expression->evaluate(input.zoom, input.feature, input.heatmapDensity, input.availableImages); + mbgl::style::expression::EvaluationResult evaluationResult; + if (input.canonical) { + evaluationResult = expression->evaluate( + input.zoom, input.feature, input.heatmapDensity, input.availableImages, *input.canonical); + } else { + evaluationResult = + expression->evaluate(input.zoom, input.feature, input.heatmapDensity, input.availableImages); + } if (!evaluationResult) { std::unordered_map<std::string, Value> error{{"error", Value{evaluationResult.error().message}}}; outputs.emplace_back(Value{std::move(error)}); |