summaryrefslogtreecommitdiff
path: root/test/style
diff options
context:
space:
mode:
Diffstat (limited to 'test/style')
-rw-r--r--test/style/conversion/function.test.cpp30
-rw-r--r--test/style/conversion/geojson_options.test.cpp12
-rw-r--r--test/style/conversion/layer.test.cpp13
-rw-r--r--test/style/filter.test.cpp5
-rw-r--r--test/style/function/composite_function.test.cpp46
-rw-r--r--test/style/source.test.cpp35
6 files changed, 114 insertions, 27 deletions
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp
index 5a3ec93917..08637d40cb 100644
--- a/test/style/conversion/function.test.cpp
+++ b/test/style/conversion/function.test.cpp
@@ -10,45 +10,47 @@ using namespace mbgl;
using namespace mbgl::style;
using namespace mbgl::style::conversion;
-auto parseFunction(const std::string& src) {
- JSDocument doc;
- doc.Parse<0>(src);
- return convert<CameraFunction<float>>(doc);
-}
-
TEST(StyleConversion, Function) {
+ Error error;
+
+ auto parseFunction = [&](const std::string& src) {
+ JSDocument doc;
+ doc.Parse<0>(src);
+ return convert<CameraFunction<float>, JSValue>(doc, error);
+ };
+
auto fn1 = parseFunction("{\"stops\":[]}");
ASSERT_FALSE(fn1);
- ASSERT_EQ("function must have at least one stop", fn1.error().message);
+ ASSERT_EQ("function must have at least one stop", error.message);
auto fn2 = parseFunction("{\"stops\":[1]}");
ASSERT_FALSE(fn2);
- ASSERT_EQ("function stop must be an array", fn2.error().message);
+ ASSERT_EQ("function stop must be an array", error.message);
auto fn3 = parseFunction("{\"stops\":[[]]}");
ASSERT_FALSE(fn3);
- ASSERT_EQ("function stop must have two elements", fn3.error().message);
+ ASSERT_EQ("function stop must have two elements", error.message);
auto fn4 = parseFunction("{\"stops\":[[-1,-1]]}");
ASSERT_TRUE(bool(fn4));
auto fn5 = parseFunction("{\"stops\":[[0,1,2]]}");
ASSERT_FALSE(fn5);
- ASSERT_EQ("function stop must have two elements", fn5.error().message);
+ ASSERT_EQ("function stop must have two elements", error.message);
auto fn6 = parseFunction("{\"stops\":[[0,\"x\"]]}");
ASSERT_FALSE(fn6);
- ASSERT_EQ("value must be a number", fn6.error().message);
+ ASSERT_EQ("value must be a number", error.message);
auto fn7 = parseFunction("{}");
ASSERT_FALSE(fn7);
- ASSERT_EQ("function value must specify stops", fn7.error().message);
+ ASSERT_EQ("function value must specify stops", error.message);
auto fn8 = parseFunction("[]");
ASSERT_FALSE(fn8);
- ASSERT_EQ("function must be an object", fn8.error().message);
+ ASSERT_EQ("function must be an object", error.message);
auto fn9 = parseFunction("{\"stops\":[[0,0]],\"base\":false}");
ASSERT_FALSE(fn9);
- ASSERT_EQ("function base must be a number", fn9.error().message);
+ ASSERT_EQ("function base must be a number", error.message);
}
diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp
index ddf261ea52..e6bd984f36 100644
--- a/test/style/conversion/geojson_options.test.cpp
+++ b/test/style/conversion/geojson_options.test.cpp
@@ -12,21 +12,24 @@ using namespace mbgl::style::conversion;
TEST(GeoJSONOptions, Basic) {
ValueMap map;
Value raw(map);
- Result<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw);
+ Error error;
+ mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error);
ASSERT_TRUE((bool) converted);
}
TEST(GeoJSONOptions, ErrorHandling) {
ValueMap map {{"maxzoom", std::string{"should not be a string"}}};
Value raw(map);
- Result<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw);
+ Error error;
+ mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error);
ASSERT_FALSE((bool) converted);
}
TEST(GeoJSONOptions, RetainsDefaults) {
ValueMap map;
Value raw(map);
- GeoJSONOptions converted = *convert<GeoJSONOptions>(raw);
+ Error error;
+ GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error);
GeoJSONOptions defaults;
// GeoJSON-VT
@@ -54,7 +57,8 @@ TEST(GeoJSONOptions, FullConversion) {
{"clusterMaxZoom", 5.0f}
};
Value raw(map);
- GeoJSONOptions converted = *convert<GeoJSONOptions>(raw);
+ Error error;
+ GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error);
// GeoJSON-VT
ASSERT_EQ(converted.maxzoom, 1);
diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp
index b27c1841ee..cfe2662fb8 100644
--- a/test/style/conversion/layer.test.cpp
+++ b/test/style/conversion/layer.test.cpp
@@ -11,10 +11,11 @@ using namespace mbgl::style;
using namespace mbgl::style::conversion;
using namespace std::literals::chrono_literals;
-auto parseLayer(const std::string& src) {
+std::unique_ptr<Layer> parseLayer(const std::string& src) {
JSDocument doc;
doc.Parse<0>(src);
- return convert<std::unique_ptr<Layer>, JSValue>(doc);
+ Error error;
+ return std::move(*convert<std::unique_ptr<Layer>, JSValue>(doc, error));
}
TEST(StyleConversion, LayerTransition) {
@@ -34,13 +35,13 @@ TEST(StyleConversion, LayerTransition) {
}
})JSON");
- ASSERT_EQ(400ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading
+ ASSERT_EQ(400ms, *layer->as<BackgroundLayer>()->impl->paint.cascading
.get<BackgroundColor>().getTransition({}).duration);
- ASSERT_EQ(500ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading
+ ASSERT_EQ(500ms, *layer->as<BackgroundLayer>()->impl->paint.cascading
.get<BackgroundColor>().getTransition({}).delay);
- ASSERT_EQ(100ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading
+ ASSERT_EQ(100ms, *layer->as<BackgroundLayer>()->impl->paint.cascading
.get<BackgroundColor>().getTransition({"class"}).duration);
- ASSERT_FALSE(bool((*layer)->as<BackgroundLayer>()->impl->paint.cascading
+ ASSERT_FALSE(bool(layer->as<BackgroundLayer>()->impl->paint.cascading
.get<BackgroundColor>().getTransition({"class"}).delay));
}
diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp
index 33b64978f5..c70792d8ef 100644
--- a/test/style/filter.test.cpp
+++ b/test/style/filter.test.cpp
@@ -16,7 +16,10 @@ using namespace mbgl::style;
Filter parse(const char * expression) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
doc.Parse<0>(expression);
- return *conversion::convert<Filter>(doc);
+ conversion::Error error;
+ optional<Filter> filter = conversion::convert<Filter, JSValue>(doc, error);
+ EXPECT_TRUE(bool(filter));
+ return *filter;
}
Feature feature(const PropertyMap& properties, const Geometry<double>& geometry = Point<double>()) {
diff --git a/test/style/function/composite_function.test.cpp b/test/style/function/composite_function.test.cpp
new file mode 100644
index 0000000000..e0804d4b27
--- /dev/null
+++ b/test/style/function/composite_function.test.cpp
@@ -0,0 +1,46 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/test/stub_geometry_tile_feature.hpp>
+
+#include <mbgl/style/function/composite_function.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+using namespace std::string_literals;
+
+static StubGeometryTileFeature oneInteger {
+ PropertyMap {{ "property", uint64_t(1) }}
+};
+
+TEST(CompositeFunction, ZoomInterpolation) {
+ EXPECT_EQ(40.0f, CompositeFunction<float>("property", CompositeExponentialStops<float>({
+ {0.0f, {{uint64_t(1), 24.0f}}},
+ {1.5f, {{uint64_t(1), 36.0f}}},
+ {3.0f, {{uint64_t(1), 48.0f}}}
+ }), 0.0f)
+ .evaluate(2.0f, oneInteger, -1.0f)) << "Should interpolate between stops";
+
+ EXPECT_EQ(33.0, CompositeFunction<float>("property", CompositeExponentialStops<float>({
+ {5.0f, {{uint64_t(1), 33.0f}}},
+ {10.0f, {{uint64_t(1), 66.0f}}}
+ }), 0.0f)
+ .evaluate(0.0f, oneInteger, -1.0f)) << "Use first stop output for input values from -inf to first stop";
+
+ EXPECT_EQ(66.0, CompositeFunction<float>("property", CompositeExponentialStops<float>({
+ {0.0f, {{uint64_t(1), 33.0f}}},
+ {10.0f, {{uint64_t(1), 66.0f}}}
+ }), 0.0f)
+ .evaluate(20.0f, oneInteger, -1.0f)) << "Use last stop output for input values from last stop to +inf";
+
+ EXPECT_EQ(66.0f, CompositeFunction<float>("property", CompositeExponentialStops<float>({
+ {0.0f, {{uint64_t(1), 33.0f}}},
+ {10.0f, {{uint64_t(1), 66.0f}}}
+ }), 0.0f)
+ .evaluate(10.0f, oneInteger, -1.0f)) << "Should interpolate TO the last stop.";
+
+ EXPECT_EQ(33.0f, CompositeFunction<float>("property", CompositeExponentialStops<float>({
+ {0.0f, {{uint64_t(1), 33.0f}}},
+ {10.0f, {{uint64_t(1), 66.0f}}}
+ }), 0.0f)
+ .evaluate(0.0f, oneInteger, -1.0f)) << "Should interpolate TO the first stop";
+}
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index fb7737e417..f637f1ccde 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -13,15 +13,20 @@
#include <mbgl/util/tileset.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/logging.hpp>
+#include <mbgl/util/optional.hpp>
+#include <mbgl/util/range.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/update_parameters.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
+#include <mbgl/annotation/annotation_source.hpp>
#include <mapbox/geojsonvt.hpp>
+#include <cstdint>
+
using namespace mbgl;
class SourceTest {
@@ -65,6 +70,32 @@ public:
}
};
+TEST(Source, DefaultZoomRange) {
+ VectorSource vectorSource("vectorSource", "url");
+ EXPECT_FALSE(vectorSource.getZoomRange());
+ vectorSource.baseImpl->loaded = true;
+ EXPECT_EQ(vectorSource.getZoomRange()->min, 0u);
+ EXPECT_EQ(vectorSource.getZoomRange()->max, 22u);
+
+ GeoJSONSource geojsonSource("source");
+ EXPECT_FALSE(geojsonSource.getZoomRange());
+ geojsonSource.baseImpl->loaded = true;
+ EXPECT_EQ(geojsonSource.getZoomRange()->min, 0u);
+ EXPECT_EQ(geojsonSource.getZoomRange()->max, 18u);
+
+ Tileset tileset;
+ RasterSource rasterSource("source", tileset, 512);
+ EXPECT_FALSE(rasterSource.getZoomRange());
+ rasterSource.baseImpl->loaded = true;
+ EXPECT_EQ(rasterSource.getZoomRange()->min, 0u);
+ EXPECT_EQ(rasterSource.getZoomRange()->max, 22u);
+ EXPECT_EQ(*rasterSource.getZoomRange(), tileset.zoomRange);
+
+ AnnotationSource annotationSource;
+ EXPECT_EQ(annotationSource.getZoomRange()->min, 0u);
+ EXPECT_EQ(annotationSource.getZoomRange()->max, 22u);
+}
+
TEST(Source, LoadingFail) {
SourceTest test;
@@ -364,8 +395,8 @@ TEST(Source, RasterTileAttribution) {
return response;
};
- test.observer.sourceAttributionChanged = [&] (Source&, std::string attribution) {
- EXPECT_EQ(mapboxOSM, attribution);
+ test.observer.sourceChanged = [&] (Source& source) {
+ EXPECT_EQ(mapboxOSM, source.getAttribution());
EXPECT_FALSE(mapboxOSM.find("©️ OpenStreetMap") == std::string::npos);
test.end();
};