summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/api/query.test.cpp2
-rw-r--r--test/fixtures/expression_equality/image.a.json4
-rw-r--r--test/fixtures/expression_equality/image.b.json4
-rw-r--r--test/style/expression/expression.test.cpp3
-rw-r--r--test/style/property_expression.test.cpp71
-rw-r--r--test/style/style_layer.test.cpp13
-rw-r--r--test/util/merge_lines.test.cpp14
7 files changed, 86 insertions, 25 deletions
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index 54ae89767a..9116a3746d 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -55,7 +55,7 @@ std::vector<Feature> getTopClusterFeature(QueryTest& test) {
source->loadDescription(*test.fileSource);
auto clusterLayer = std::make_unique<SymbolLayer>("cluster_layer"s, "cluster_source"s);
- clusterLayer->setIconImage("test-icon"s);
+ clusterLayer->setIconImage({"test-icon"s});
clusterLayer->setIconSize(12.0f);
test.map.jumpTo(CameraOptions().withCenter(coordinate).withZoom(0.0));
diff --git a/test/fixtures/expression_equality/image.a.json b/test/fixtures/expression_equality/image.a.json
new file mode 100644
index 0000000000..930b21dd0e
--- /dev/null
+++ b/test/fixtures/expression_equality/image.a.json
@@ -0,0 +1,4 @@
+[
+ "image",
+ "maki-11"
+] \ No newline at end of file
diff --git a/test/fixtures/expression_equality/image.b.json b/test/fixtures/expression_equality/image.b.json
new file mode 100644
index 0000000000..edec7d0497
--- /dev/null
+++ b/test/fixtures/expression_equality/image.b.json
@@ -0,0 +1,4 @@
+[
+ "image",
+ "bicycle-15"
+] \ No newline at end of file
diff --git a/test/style/expression/expression.test.cpp b/test/style/expression/expression.test.cpp
index ef9f7b7930..a289d7600b 100644
--- a/test/style/expression/expression.test.cpp
+++ b/test/style/expression/expression.test.cpp
@@ -35,7 +35,8 @@ TEST(Expression, IsExpression) {
// TODO: "interpolate-hcl": https://github.com/mapbox/mapbox-gl-native/issues/8720
// TODO: "interpolate-lab": https://github.com/mapbox/mapbox-gl-native/issues/8720
- if (name == "interpolate-hcl" || name == "interpolate-lab") {
+ // TODO: "in": https://github.com/mapbox/mapbox-gl-native/issues/15893
+ if (name == "interpolate-hcl" || name == "interpolate-lab" || name == "in") {
if (expression::isExpression(conversion::Convertible(expression))) {
ASSERT_TRUE(false) << "Expression name" << name << "is implemented - please update Expression.IsExpression test.";
}
diff --git a/test/style/property_expression.test.cpp b/test/style/property_expression.test.cpp
index 75c8c59490..6334fcbe39 100644
--- a/test/style/property_expression.test.cpp
+++ b/test/style/property_expression.test.cpp
@@ -14,21 +14,17 @@ using namespace mbgl::style::expression::dsl;
using namespace std::string_literals;
-static StubGeometryTileFeature oneInteger {
- PropertyMap {{ "property", uint64_t(1) }}
-};
+static const StubGeometryTileFeature oneInteger{PropertyMap{{"property", uint64_t(1)}}};
-static StubGeometryTileFeature oneDouble {
- PropertyMap {{ "property", 1.0 }}
-};
+static const StubGeometryTileFeature oneDouble{PropertyMap{{"property", 1.0}}};
-static StubGeometryTileFeature oneString {
- PropertyMap {{ "property", "1"s }}
-};
+static const StubGeometryTileFeature oneString{PropertyMap{{"property", "1"s}}};
-static StubGeometryTileFeature oneColor {
- PropertyMap {{ "color", "red"s }}
-};
+static const StubGeometryTileFeature oneColor{PropertyMap{{"color", "red"s}}};
+
+static const StubGeometryTileFeature oneImage{PropertyMap{{"image_name", "maki-11"s}}};
+
+static const StubGeometryTileFeature emptyTileFeature{PropertyMap{}};
float evaluate(PropertyValue<float> value, float zoom) {
return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
@@ -171,3 +167,54 @@ TEST(PropertyExpression, FormatSectionOverride) {
EXPECT_TRUE(*override1 != *override4);
}
}
+
+TEST(PropertyExpression, ImageExpression) {
+ const std::set<std::string> emptySet;
+ const std::set<std::string> availableImages = {"maki-11", "airport-11", "bicycle-15"};
+
+ // evaluation test without available images
+ {
+ PropertyExpression<expression::Image> propExpr(image(literal("airport-11")));
+ auto evaluatedImage = propExpr.evaluate(emptyTileFeature, emptySet, expression::Image());
+ EXPECT_FALSE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), "airport-11"s);
+
+ PropertyExpression<expression::Image> ddPropExpr(image(get(literal("image_name"s))));
+ evaluatedImage = ddPropExpr.evaluate(oneImage, emptySet, expression::Image());
+ EXPECT_FALSE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), "maki-11"s);
+
+ evaluatedImage = ddPropExpr.evaluate(emptyTileFeature, emptySet, expression::Image());
+ EXPECT_FALSE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), ""s);
+ }
+
+ // evaluation test with available images
+ {
+ PropertyExpression<expression::Image> propExpr(image(literal("airport-11")));
+ auto evaluatedImage = propExpr.evaluate(emptyTileFeature, availableImages, expression::Image());
+ EXPECT_TRUE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), "airport-11"s);
+
+ PropertyExpression<expression::Image> ddPropExpr(image(get(literal("image_name"s))));
+ evaluatedImage = ddPropExpr.evaluate(oneImage, availableImages, expression::Image());
+ EXPECT_TRUE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), "maki-11"s);
+
+ evaluatedImage = ddPropExpr.evaluate(emptyTileFeature, availableImages, expression::Image());
+ EXPECT_FALSE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), ""s);
+ }
+
+ // evaluation with zoom
+ {
+ auto expr = step(zoom(), image(literal("airport-11")), 18.0, image(literal("bicycle-15")));
+ PropertyExpression<expression::Image> propExpr(std::move(expr));
+ auto evaluatedImage = propExpr.evaluate(0.0, emptyTileFeature, availableImages, expression::Image());
+ EXPECT_TRUE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), "airport-11"s);
+ evaluatedImage = propExpr.evaluate(18.0, emptyTileFeature, availableImages, expression::Image());
+ EXPECT_TRUE(evaluatedImage.isAvailable());
+ EXPECT_EQ(evaluatedImage.id(), "bicycle-15"s);
+ }
+}
diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp
index dfced634b7..2d6ef5881a 100644
--- a/test/style/style_layer.test.cpp
+++ b/test/style/style_layer.test.cpp
@@ -1,7 +1,7 @@
#include <mbgl/style/expression/dsl.hpp>
-#include <mbgl/style/expression/match.hpp>
#include <mbgl/style/expression/format_expression.hpp>
-#include <mbgl/style/style_impl.hpp>
+#include <mbgl/style/expression/image.hpp>
+#include <mbgl/style/expression/match.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
@@ -16,12 +16,13 @@
#include <mbgl/style/layers/raster_layer_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
-#include <mbgl/test/util.hpp>
-#include <mbgl/test/stub_layer_observer.hpp>
+#include <mbgl/style/style_impl.hpp>
#include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/stub_layer_observer.hpp>
+#include <mbgl/test/util.hpp>
#include <mbgl/util/color.hpp>
-#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/io.hpp>
+#include <mbgl/util/run_loop.hpp>
#include <memory>
@@ -37,7 +38,7 @@ const auto color = Color { 1, 0, 0, 1 };
const auto opacity = 1.0f;
const auto radius = 1.0f;
const auto blur = 1.0f;
-const auto pattern = std::string { "foo" };
+const auto pattern = PropertyValue<expression::Image>{"foo"};
const auto antialias = false;
const auto translate = std::array<float, 2> {{ 0, 0 }};
const auto translateAnchor = TranslateAnchorType::Map;
diff --git a/test/util/merge_lines.test.cpp b/test/util/merge_lines.test.cpp
index 5dc846ad6e..5137a245e5 100644
--- a/test/util/merge_lines.test.cpp
+++ b/test/util/merge_lines.test.cpp
@@ -19,11 +19,15 @@ LineString<int16_t> emptyLine;
class SymbolFeatureStub : public SymbolFeature {
public:
- SymbolFeatureStub(FeatureIdentifier id_, FeatureType type_, GeometryCollection geometry_,
- PropertyMap properties_, optional<std::u16string> text_,
- optional<std::string> icon_, std::size_t index_) :
- SymbolFeature(std::make_unique<StubGeometryTileFeature>(std::move(id_), type_, std::move(geometry_), std::move(properties_)))
- {
+ SymbolFeatureStub(FeatureIdentifier id_,
+ FeatureType type_,
+ GeometryCollection geometry_,
+ PropertyMap properties_,
+ optional<std::u16string> text_,
+ optional<style::expression::Image> icon_,
+ std::size_t index_)
+ : SymbolFeature(std::make_unique<StubGeometryTileFeature>(
+ std::move(id_), type_, std::move(geometry_), std::move(properties_))) {
if (text_) {
formattedText = TaggedString(*text_, SectionOptions(1.0, {}));
}