diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-03-11 10:26:19 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-03-13 17:14:53 +0200 |
commit | 8be135231d9efe41a3b12037518d02b36104e8cf (patch) | |
tree | efecd5380232f899aed2cd5824dc16f057f0469a /test/style/property_expression.test.cpp | |
parent | 8a51362bccbd6487dd1ed8518443b16ba6114fd8 (diff) | |
download | qtlocation-mapboxgl-8be135231d9efe41a3b12037518d02b36104e8cf.tar.gz |
[core] Add possibility of overriding paint properties inside format expression #14062
* [core] Add format override expression and formatted section to evaluation context
* [core] Add textColor to TaggedString's formatted section
* [core] Add FormatSectionOverrides and introduce overridable properties
* [core] Populate symbol layer paint properties for text sections
* [core] Add benchmark for style that uses text-color override
* [core] Add unit test for FormatOverrideExpression
* [core] Add unit test for FormatSectionOverrides
Diffstat (limited to 'test/style/property_expression.test.cpp')
-rw-r--r-- | test/style/property_expression.test.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/style/property_expression.test.cpp b/test/style/property_expression.test.cpp index e4ee5f115f..75c8c59490 100644 --- a/test/style/property_expression.test.cpp +++ b/test/style/property_expression.test.cpp @@ -5,9 +5,11 @@ #include <mbgl/renderer/property_evaluator.hpp> #include <mbgl/renderer/property_evaluation_parameters.hpp> #include <mbgl/style/expression/dsl.hpp> +#include <mbgl/style/expression/format_section_override.hpp> using namespace mbgl; using namespace mbgl::style; +using namespace mbgl::style::expression; using namespace mbgl::style::expression::dsl; using namespace std::string_literals; @@ -24,10 +26,23 @@ static StubGeometryTileFeature oneString { PropertyMap {{ "property", "1"s }} }; +static StubGeometryTileFeature oneColor { + PropertyMap {{ "color", "red"s }} +}; + float evaluate(PropertyValue<float> value, float zoom) { return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0)); } +template<typename T> +auto createOverride(expression::type::Type exprType, + PossiblyEvaluatedPropertyValue<T> propValue, + std::string propName) { + return std::make_unique<FormatSectionOverride<T>>(std::move(exprType), + std::move(propValue), + std::move(propName)); +} + TEST(PropertyExpression, Constant) { EXPECT_EQ(2.0f, evaluate(PropertyValue<float>(2.0), 0)); EXPECT_EQ(3.8f, evaluate(PropertyValue<float>(3.8), 0)); @@ -121,3 +136,38 @@ TEST(PropertyExpression, Issue8460) { EXPECT_NEAR(600.0f, fn2.evaluate(18.0f, oneInteger, -1.0f), 0.00); EXPECT_NEAR(600.0f, fn2.evaluate(19.0f, oneInteger, -1.0f), 0.00); } + +TEST(PropertyExpression, FormatSectionOverride) { + using Value = expression::Value; + Value formattedSection = + std::unordered_map<std::string, Value>{ {"text-color", Value{Color::blue()}} }; + auto ctx = expression::EvaluationContext(&oneDouble).withFormattedSection(&formattedSection); + PossiblyEvaluatedPropertyValue<Color> constantValueRed(Color::red()); + PossiblyEvaluatedPropertyValue<Color> constantValueGreen(Color::green()); + PossiblyEvaluatedPropertyValue<Color> ddsValueRed(toColor(string(get("color")))); + + // Evaluation test + { + auto override1 = createOverride(expression::type::Color, constantValueGreen, "text-color"); + PropertyExpression<Color> propExpr(std::move(override1)); + EXPECT_EQ(Color::green(), propExpr.evaluate(15.0f, oneDouble, Color())); + EXPECT_EQ(Color::green(), propExpr.evaluate(oneDouble, Color())); + EXPECT_EQ(Color::blue(), propExpr.evaluate(ctx)); + + auto override2 = createOverride(expression::type::Color, ddsValueRed, "text-color"); + PropertyExpression<Color> propExprDDS(std::move(override2)); + EXPECT_EQ(Color::red(), propExprDDS.evaluate(oneColor, Color())); + EXPECT_EQ(Color::blue(), propExprDDS.evaluate(ctx)); + } + + // Equality test + { + auto override1 = createOverride(expression::type::Color, constantValueRed, "text-color"); + auto override2 = createOverride(expression::type::Color, constantValueGreen, "text-color"); + auto override3 = createOverride(expression::type::Color, constantValueGreen, "text-halo-color"); + auto override4 = createOverride(expression::type::Color, ddsValueRed, "text-color"); + EXPECT_TRUE(*override1 != *override2); + EXPECT_TRUE(*override2 != *override3); + EXPECT_TRUE(*override1 != *override4); + } +} |