diff options
Diffstat (limited to 'test/style')
-rw-r--r-- | test/style/conversion/function.test.cpp | 14 | ||||
-rw-r--r-- | test/style/conversion/layer.test.cpp | 18 | ||||
-rw-r--r-- | test/style/conversion/light.test.cpp | 14 | ||||
-rw-r--r-- | test/style/conversion/stringify.test.cpp | 17 | ||||
-rw-r--r-- | test/style/filter.test.cpp | 8 | ||||
-rw-r--r-- | test/style/function/exponential_stops.test.cpp | 20 | ||||
-rw-r--r-- | test/style/function/interval_stops.test.cpp | 20 | ||||
-rw-r--r-- | test/style/function/source_function.test.cpp | 9 | ||||
-rw-r--r-- | test/style/properties.test.cpp (renamed from test/style/paint_property.test.cpp) | 43 | ||||
-rw-r--r-- | test/style/source.test.cpp | 231 | ||||
-rw-r--r-- | test/style/style.test.cpp | 42 | ||||
-rw-r--r-- | test/style/style_image.test.cpp | 26 | ||||
-rw-r--r-- | test/style/style_layer.test.cpp | 47 | ||||
-rw-r--r-- | test/style/style_parser.test.cpp | 4 |
14 files changed, 327 insertions, 186 deletions
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index 08637d40cb..1eff94d939 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -19,26 +19,26 @@ TEST(StyleConversion, Function) { return convert<CameraFunction<float>, JSValue>(doc, error); }; - auto fn1 = parseFunction("{\"stops\":[]}"); + auto fn1 = parseFunction(R"({"stops":[]})"); ASSERT_FALSE(fn1); ASSERT_EQ("function must have at least one stop", error.message); - auto fn2 = parseFunction("{\"stops\":[1]}"); + auto fn2 = parseFunction(R"({"stops":[1]})"); ASSERT_FALSE(fn2); ASSERT_EQ("function stop must be an array", error.message); - auto fn3 = parseFunction("{\"stops\":[[]]}"); + auto fn3 = parseFunction(R"({"stops":[[]]})"); ASSERT_FALSE(fn3); ASSERT_EQ("function stop must have two elements", error.message); - auto fn4 = parseFunction("{\"stops\":[[-1,-1]]}"); + auto fn4 = parseFunction(R"({"stops":[[-1,-1]]})"); ASSERT_TRUE(bool(fn4)); - auto fn5 = parseFunction("{\"stops\":[[0,1,2]]}"); + auto fn5 = parseFunction(R"({"stops":[[0,1,2]]})"); ASSERT_FALSE(fn5); ASSERT_EQ("function stop must have two elements", error.message); - auto fn6 = parseFunction("{\"stops\":[[0,\"x\"]]}"); + auto fn6 = parseFunction(R"({"stops":[[0,"x"]]})"); ASSERT_FALSE(fn6); ASSERT_EQ("value must be a number", error.message); @@ -50,7 +50,7 @@ TEST(StyleConversion, Function) { ASSERT_FALSE(fn8); ASSERT_EQ("function must be an object", error.message); - auto fn9 = parseFunction("{\"stops\":[[0,0]],\"base\":false}"); + auto fn9 = parseFunction(R"({"stops":[[0,0]],"base":false})"); ASSERT_FALSE(fn9); ASSERT_EQ("function base must be a number", error.message); } diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index ae8d4058ab..d51d7d33e2 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -27,21 +27,11 @@ TEST(StyleConversion, LayerTransition) { "duration": 400, "delay": 500 } - }, - "paint.class": { - "background-color-transition": { - "duration": 100 - } } })JSON"); - ASSERT_EQ(400ms, *layer->as<BackgroundLayer>()->impl->cascading - .get<BackgroundColor>().getTransition({}).duration); - ASSERT_EQ(500ms, *layer->as<BackgroundLayer>()->impl->cascading - .get<BackgroundColor>().getTransition({}).delay); - - ASSERT_EQ(100ms, *layer->as<BackgroundLayer>()->impl->cascading - .get<BackgroundColor>().getTransition({"class"}).duration); - ASSERT_FALSE(bool(layer->as<BackgroundLayer>()->impl->cascading - .get<BackgroundColor>().getTransition({"class"}).delay)); + ASSERT_EQ(400ms, *layer->as<BackgroundLayer>()->impl().paint + .get<BackgroundColor>().options.duration); + ASSERT_EQ(500ms, *layer->as<BackgroundLayer>()->impl().paint + .get<BackgroundColor>().options.delay); } diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp index a2185906d6..28e22b3550 100644 --- a/test/style/conversion/light.test.cpp +++ b/test/style/conversion/light.test.cpp @@ -30,7 +30,7 @@ TEST(StyleConversion, Light) { } { - auto light = parseLight("{\"color\":{\"stops\":[[14,\"blue\"],[16,\"red\"]]},\"intensity\":0.3,\"position\":[3,90,90]}"); + auto light = parseLight(R"({"color":{"stops":[[14,"blue"],[16,"red"]]},"intensity":0.3,"position":[3,90,90]})"); ASSERT_TRUE((bool) light); ASSERT_TRUE(light->getAnchor().isUndefined()); @@ -54,7 +54,7 @@ TEST(StyleConversion, Light) { } { - auto light = parseLight("{\"color\":\"blue\",\"intensity\":0.3,\"color-transition\":{\"duration\":1000}}"); + auto light = parseLight(R"({"color":"blue","intensity":0.3,"color-transition":{"duration":1000}})"); ASSERT_TRUE((bool) light); ASSERT_FALSE(light->getColor().isUndefined()); @@ -65,35 +65,35 @@ TEST(StyleConversion, Light) { } { - auto light = parseLight("{\"intensity\":false}"); + auto light = parseLight(R"({"intensity":false})"); ASSERT_FALSE((bool) light); ASSERT_EQ("value must be a number", error.message); } { - auto light = parseLight("{\"intensity\":{\"stops\":[[15,\"red\"],[17,\"blue\"]]}}"); + auto light = parseLight(R"({"intensity":{"stops":[[15,"red"],[17,"blue"]]}})"); ASSERT_FALSE((bool) light); ASSERT_EQ("value must be a number", error.message); } { - auto light = parseLight("{\"color\":5}"); + auto light = parseLight(R"({"color":5})"); ASSERT_FALSE((bool) light); ASSERT_EQ("value must be a string", error.message); } { - auto light = parseLight("{\"position\":[0,5]}"); + auto light = parseLight(R"({"position":[0,5]})"); ASSERT_FALSE((bool) light); ASSERT_EQ("value must be an array of 3 numbers", error.message); } { - auto light = parseLight("{\"anchor\":\"something\"}"); + auto light = parseLight(R"({"anchor":"something"})"); ASSERT_FALSE((bool) light); ASSERT_EQ("value must be a valid enumeration value", error.message); diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 1dae20b26b..0b2940a0e0 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -121,10 +121,17 @@ TEST(Stringify, PropertyValue) { } TEST(Stringify, Layout) { - ASSERT_EQ(stringify(SymbolLayoutProperties()), "{}"); - - SymbolLayoutProperties layout; - layout.unevaluated.get<SymbolAvoidEdges>() = true; - layout.unevaluated.get<IconPadding>() = 2.0; + auto stringify = [] (const SymbolLayoutProperties::Unevaluated& layout) { + rapidjson::StringBuffer s; + rapidjson::Writer<rapidjson::StringBuffer> writer(s); + layout.stringify(writer); + return std::string(s.GetString()); + }; + + ASSERT_EQ(stringify(SymbolLayoutProperties::Unevaluated()), "{}"); + + SymbolLayoutProperties::Unevaluated layout; + layout.get<SymbolAvoidEdges>() = true; + layout.get<IconPadding>() = 2.0; ASSERT_EQ(stringify(layout), "{\"symbol-avoid-edges\":true,\"icon-padding\":2.0}"); } diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index c70792d8ef..96de125945 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -29,13 +29,13 @@ Feature feature(const PropertyMap& properties, const Geometry<double>& geometry } TEST(Filter, EqualsString) { - Filter f = parse("[\"==\", \"foo\", \"bar\"]"); + Filter f = parse(R"(["==", "foo", "bar"])"); ASSERT_TRUE(f(feature({{ "foo", std::string("bar") }}))); ASSERT_FALSE(f(feature({{ "foo", std::string("baz") }}))); } TEST(Filter, EqualsNumber) { - Filter f = parse("[\"==\", \"foo\", 0]"); + Filter f = parse(R"(["==", "foo", 0])"); ASSERT_TRUE(f(feature({{ "foo", int64_t(0) }}))); ASSERT_TRUE(f(feature({{ "foo", uint64_t(0) }}))); ASSERT_TRUE(f(feature({{ "foo", double(0) }}))); @@ -50,13 +50,13 @@ TEST(Filter, EqualsNumber) { } TEST(Filter, EqualsType) { - Filter f = parse("[\"==\", \"$type\", \"LineString\"]"); + Filter f = parse(R"(["==", "$type", "LineString"])"); ASSERT_FALSE(f(feature({{}}, Point<double>()))); ASSERT_TRUE(f(feature({{}}, LineString<double>()))); } TEST(Filter, InType) { - Filter f = parse("[\"in\", \"$type\", \"LineString\", \"Polygon\"]"); + Filter f = parse(R"(["in", "$type", "LineString", "Polygon"])"); ASSERT_FALSE(f(feature({{}}, Point<double>()))); ASSERT_TRUE(f(feature({{}}, LineString<double>()))); ASSERT_TRUE(f(feature({{}}, Polygon<double>()))); diff --git a/test/style/function/exponential_stops.test.cpp b/test/style/function/exponential_stops.test.cpp new file mode 100644 index 0000000000..81438ec952 --- /dev/null +++ b/test/style/function/exponential_stops.test.cpp @@ -0,0 +1,20 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/style/function/exponential_stops.hpp> + +using namespace mbgl; +using namespace mbgl::style; + +TEST(ExponentialStops, Empty) { + ExponentialStops<float> stops; + EXPECT_FALSE(bool(stops.evaluate(0))); +} + +TEST(ExponentialStops, NonNumericInput) { + ExponentialStops<float> stops(std::map<float, float> {{0.0f, 0.0f}}); + EXPECT_FALSE(bool(stops.evaluate(Value(NullValue())))); + EXPECT_FALSE(bool(stops.evaluate(Value(false)))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::string())))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::vector<Value>())))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::unordered_map<std::string, Value>())))); +} diff --git a/test/style/function/interval_stops.test.cpp b/test/style/function/interval_stops.test.cpp new file mode 100644 index 0000000000..8a5e74b8b6 --- /dev/null +++ b/test/style/function/interval_stops.test.cpp @@ -0,0 +1,20 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/style/function/interval_stops.hpp> + +using namespace mbgl; +using namespace mbgl::style; + +TEST(IntervalStops, Empty) { + IntervalStops<float> stops; + EXPECT_FALSE(bool(stops.evaluate(0))); +} + +TEST(IntervalStops, NonNumericInput) { + IntervalStops<float> stops(std::map<float, float> {{0.0f, 0.0f}}); + EXPECT_FALSE(bool(stops.evaluate(Value(NullValue())))); + EXPECT_FALSE(bool(stops.evaluate(Value(false)))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::string())))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::vector<Value>())))); + EXPECT_FALSE(bool(stops.evaluate(Value(std::unordered_map<std::string, Value>())))); +} diff --git a/test/style/function/source_function.test.cpp b/test/style/function/source_function.test.cpp index 260620c8d0..46ad961002 100644 --- a/test/style/function/source_function.test.cpp +++ b/test/style/function/source_function.test.cpp @@ -76,11 +76,14 @@ TEST(SourceFunction, Categorical) { EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ int64_t(1), 1.0f }})) .evaluate(oneString, 0.0f)); - EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ "1"s, 1.0f }})) + CategoricalStops<float>::Stops stops; + stops["1"s] = 1.0f; + + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>(stops)) .evaluate(oneInteger, 0.0f)); - EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>({{ "1"s, 1.0f }})) + EXPECT_EQ(0.0f, SourceFunction<float>("property", CategoricalStops<float>(stops)) .evaluate(oneDouble, 0.0f)); - EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ "1"s, 1.0f }})) + EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>(stops)) .evaluate(oneString, 0.0f)); EXPECT_EQ(1.0f, SourceFunction<float>("property", CategoricalStops<float>({{ true, 1.0f }})) diff --git a/test/style/paint_property.test.cpp b/test/style/properties.test.cpp index fcca05f3bd..279fadb8c2 100644 --- a/test/style/paint_property.test.cpp +++ b/test/style/properties.test.cpp @@ -1,13 +1,14 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/paint_property.hpp> -#include <mbgl/renderer/transitioning_property.hpp> +#include <mbgl/style/properties.hpp> +#include <mbgl/renderer/property_evaluator.hpp> +#include <mbgl/renderer/data_driven_property_evaluator.hpp> using namespace mbgl; using namespace mbgl::style; using namespace std::literals::chrono_literals; -float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration delta = Duration::zero()) { +float evaluate(Transitioning<PropertyValue<float>>& property, Duration delta = Duration::zero()) { ZoomHistory zoomHistory; zoomHistory.update(0, TimePoint::min() + delta); @@ -25,7 +26,7 @@ float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration d return property.evaluate(evaluator, parameters.now); } -PossiblyEvaluatedPropertyValue<float> evaluate(TransitioningProperty<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) { +PossiblyEvaluatedPropertyValue<float> evaluate(Transitioning<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) { ZoomHistory zoomHistory; zoomHistory.update(0, TimePoint::min() + delta); @@ -43,15 +44,15 @@ PossiblyEvaluatedPropertyValue<float> evaluate(TransitioningProperty<DataDrivenP return property.evaluate(evaluator, parameters.now); } -TEST(TransitioningProperty, EvaluateDefaultValue) { - TransitioningProperty<PropertyValue<float>> property; +TEST(TransitioningPropertyValue, EvaluateDefaultValue) { + Transitioning<PropertyValue<float>> property; ASSERT_EQ(0.0f, evaluate(property)); } -TEST(TransitioningProperty, EvaluateUntransitionedConstant) { - TransitioningProperty<PropertyValue<float>> property { +TEST(TransitioningPropertyValue, EvaluateUntransitionedConstant) { + Transitioning<PropertyValue<float>> property { PropertyValue<float>(1.0f), - TransitioningProperty<PropertyValue<float>>(), + Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min() }; @@ -59,18 +60,18 @@ TEST(TransitioningProperty, EvaluateUntransitionedConstant) { ASSERT_EQ(1.0f, evaluate(property)); } -TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) { +TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithoutDelay) { TransitionOptions transition; transition.duration = { 1000ms }; - TransitioningProperty<PropertyValue<float>> t0 { + Transitioning<PropertyValue<float>> t0 { PropertyValue<float>(0.0f), - TransitioningProperty<PropertyValue<float>>(), + Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min() }; - TransitioningProperty<PropertyValue<float>> t1 { + Transitioning<PropertyValue<float>> t1 { PropertyValue<float>(1.0f), t0, transition, @@ -82,19 +83,19 @@ TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) { ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 1500ms)); } -TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) { +TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithDelay) { TransitionOptions transition; transition.delay = { 1000ms }; transition.duration = { 1000ms }; - TransitioningProperty<PropertyValue<float>> t0 { + Transitioning<PropertyValue<float>> t0 { PropertyValue<float>(0.0f), - TransitioningProperty<PropertyValue<float>>(), + Transitioning<PropertyValue<float>>(), TransitionOptions(), TimePoint::min() }; - TransitioningProperty<PropertyValue<float>> t1 { + Transitioning<PropertyValue<float>> t1 { PropertyValue<float>(1.0f), t0, transition, @@ -108,14 +109,14 @@ TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) { ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 2500ms)); } -TEST(TransitioningProperty, EvaluateDataDrivenValue) { +TEST(TransitioningDataDrivenPropertyValue, Evaluate) { TransitionOptions transition; transition.delay = { 1000ms }; transition.duration = { 1000ms }; - TransitioningProperty<DataDrivenPropertyValue<float>> t0 { + Transitioning<DataDrivenPropertyValue<float>> t0 { DataDrivenPropertyValue<float>(0.0f), - TransitioningProperty<DataDrivenPropertyValue<float>>(), + Transitioning<DataDrivenPropertyValue<float>>(), TransitionOptions(), TimePoint::min() }; @@ -125,7 +126,7 @@ TEST(TransitioningProperty, EvaluateDataDrivenValue) { IdentityStops<float>() }; - TransitioningProperty<DataDrivenPropertyValue<float>> t1 { + Transitioning<DataDrivenPropertyValue<float>> t1 { DataDrivenPropertyValue<float>(sourceFunction), t0, transition, diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index c60a473589..919260ffe9 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -3,10 +3,14 @@ #include <mbgl/test/stub_style_observer.hpp> #include <mbgl/test/stub_render_source_observer.hpp> +#include <mbgl/style/style.hpp> #include <mbgl/style/source_impl.hpp> #include <mbgl/style/sources/raster_source.hpp> #include <mbgl/style/sources/vector_source.hpp> #include <mbgl/style/sources/geojson_source.hpp> +#include <mbgl/style/sources/image_source.hpp> +#include <mbgl/style/layers/raster_layer.cpp> +#include <mbgl/style/layers/line_layer.hpp> #include <mbgl/renderer/sources/render_raster_source.hpp> #include <mbgl/renderer/sources/render_vector_source.hpp> @@ -16,6 +20,9 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/io.hpp> +#include <mbgl/util/premultiply.hpp> +#include <mbgl/util/image.hpp> + #include <mbgl/util/tileset.hpp> #include <mbgl/util/default_thread_pool.hpp> #include <mbgl/util/logging.hpp> @@ -23,12 +30,10 @@ #include <mbgl/util/range.hpp> #include <mbgl/map/transform.hpp> -#include <mbgl/style/style.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 <mbgl/renderer/image_manager.hpp> +#include <mbgl/text/glyph_manager.hpp> #include <cstdint> @@ -43,8 +48,10 @@ public: Transform transform; TransformState transformState; ThreadPool threadPool { 1 }; - AnnotationManager annotationManager { 1.0 }; - style::Style style { threadPool, fileSource, 1.0 }; + Style style { loop, fileSource, 1 }; + AnnotationManager annotationManager { style }; + ImageManager imageManager; + GlyphManager glyphManager { fileSource }; TileParameters tileParameters { 1.0, @@ -54,7 +61,9 @@ public: fileSource, MapMode::Continuous, annotationManager, - style + imageManager, + glyphManager, + 0 }; SourceTest() { @@ -95,8 +104,8 @@ TEST(Source, LoadingFail) { }; VectorSource source("source", "url"); - source.baseImpl->setObserver(&test.styleObserver); - source.baseImpl->loadDescription(test.fileSource); + source.setObserver(&test.styleObserver); + source.loadDescription(test.fileSource); test.run(); } @@ -118,8 +127,8 @@ TEST(Source, LoadingCorrupt) { }; VectorSource source("source", "url"); - source.baseImpl->setObserver(&test.styleObserver); - source.baseImpl->loadDescription(test.fileSource); + source.setObserver(&test.styleObserver); + source.loadDescription(test.fileSource); test.run(); } @@ -133,14 +142,17 @@ TEST(Source, RasterTileEmpty) { return response; }; + RasterLayer layer("id", "source"); + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; RasterSource source("source", tileset, 512); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) { - EXPECT_EQ("source", source_.baseImpl.id); + EXPECT_EQ("source", source_.baseImpl->id); test.end(); }; @@ -148,9 +160,13 @@ TEST(Source, RasterTileEmpty) { FAIL() << "Should never be called"; }; - RenderRasterSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -164,14 +180,19 @@ TEST(Source, VectorTileEmpty) { return response; }; + LineLayer layer("id", "source"); + layer.setSourceLayer("water"); + + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; VectorSource source("source", tileset); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileChanged = [&] (RenderSource& source_, const OverscaledTileID&) { - EXPECT_EQ("source", source_.baseImpl.id); + EXPECT_EQ("source", source_.baseImpl->id); test.end(); }; @@ -179,9 +200,13 @@ TEST(Source, VectorTileEmpty) { FAIL() << "Should never be called"; }; - RenderVectorSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -197,22 +222,29 @@ TEST(Source, RasterTileFail) { return response; }; + RasterLayer layer("id", "source"); + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; RasterSource source("source", tileset, 512); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) { - EXPECT_EQ(SourceType::Raster, source_.baseImpl.type); + EXPECT_EQ(SourceType::Raster, source_.baseImpl->type); EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID); EXPECT_EQ("Failed by the test case", util::toString(error)); test.end(); }; - RenderRasterSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -228,22 +260,31 @@ TEST(Source, VectorTileFail) { return response; }; + LineLayer layer("id", "source"); + layer.setSourceLayer("water"); + + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; VectorSource source("source", tileset); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) { - EXPECT_EQ(SourceType::Vector, source_.baseImpl.type); + EXPECT_EQ(SourceType::Vector, source_.baseImpl->type); EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID); EXPECT_EQ("Failed by the test case", util::toString(error)); test.end(); }; - RenderVectorSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -257,23 +298,30 @@ TEST(Source, RasterTileCorrupt) { return response; }; + RasterLayer layer("id", "source"); + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; RasterSource source("source", tileset, 512); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) { - EXPECT_EQ(source_.baseImpl.type, SourceType::Raster); + EXPECT_EQ(source_.baseImpl->type, SourceType::Raster); EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID); EXPECT_TRUE(bool(error)); // Not asserting on platform-specific error text. test.end(); }; - RenderRasterSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -287,27 +335,31 @@ TEST(Source, VectorTileCorrupt) { return response; }; - // Need to have at least one layer that uses the source. - auto layer = std::make_unique<LineLayer>("id", "source"); - layer->setSourceLayer("water"); - test.style.addLayer(std::move(layer)); + LineLayer layer("id", "source"); + layer.setSourceLayer("water"); + + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; Tileset tileset; tileset.tiles = { "tiles" }; VectorSource source("source", tileset); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileError = [&] (RenderSource& source_, const OverscaledTileID& tileID, std::exception_ptr error) { - EXPECT_EQ(source_.baseImpl.type, SourceType::Vector); + EXPECT_EQ(source_.baseImpl->type, SourceType::Vector); EXPECT_EQ(OverscaledTileID(0, 0, 0), tileID); EXPECT_EQ(util::toString(error), "unknown pbf field type exception"); test.end(); }; - RenderVectorSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -320,11 +372,14 @@ TEST(Source, RasterTileCancel) { return optional<Response>(); }; + RasterLayer layer("id", "source"); + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; RasterSource source("source", tileset, 512); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) { FAIL() << "Should never be called"; @@ -334,9 +389,13 @@ TEST(Source, RasterTileCancel) { FAIL() << "Should never be called"; }; - RenderRasterSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -349,11 +408,16 @@ TEST(Source, VectorTileCancel) { return optional<Response>(); }; + LineLayer layer("id", "source"); + layer.setSourceLayer("water"); + + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + Tileset tileset; tileset.tiles = { "tiles" }; VectorSource source("source", tileset); - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); test.renderSourceObserver.tileChanged = [&] (RenderSource&, const OverscaledTileID&) { FAIL() << "Should never be called"; @@ -363,9 +427,13 @@ TEST(Source, VectorTileCancel) { FAIL() << "Should never be called"; }; - RenderVectorSource renderSource(*source.impl); - renderSource.setObserver(&test.renderSourceObserver); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->setObserver(&test.renderSourceObserver); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -373,6 +441,9 @@ TEST(Source, VectorTileCancel) { TEST(Source, RasterTileAttribution) { SourceTest test; + RasterLayer layer("id", "source"); + std::vector<Immutable<Layer::Impl>> layers {{ layer.baseImpl }}; + std::string mapboxOSM = ("<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox</a> " "<a href='http://www.openstreetmap.org/about/' target='_blank'>©️ OpenStreetMap</a>"); @@ -398,11 +469,15 @@ TEST(Source, RasterTileAttribution) { }; RasterSource source("source", "url", 512); - source.baseImpl->setObserver(&test.styleObserver); - source.baseImpl->loadDescription(test.fileSource); + source.setObserver(&test.styleObserver); + source.loadDescription(test.fileSource); - RenderRasterSource renderSource(*source.impl); - renderSource.updateTiles(test.tileParameters); + auto renderSource = RenderSource::create(source.baseImpl); + renderSource->update(source.baseImpl, + layers, + true, + true, + test.tileParameters); test.run(); } @@ -413,7 +488,7 @@ TEST(Source, GeoJSonSourceUrlUpdate) { test.fileSource.sourceResponse = [&] (const Resource& resource) { EXPECT_EQ("url", resource.url); Response response; - response.data = std::make_unique<std::string>("{\"geometry\": {\"type\": \"Point\", \"coordinates\": [1.1, 1.1]}, \"type\": \"Feature\", \"properties\": {}}"); + response.data = std::make_unique<std::string>(R"({"geometry": {"type": "Point", "coordinates": [1.1, 1.1]}, "type": "Feature", "properties": {}})"); return response; }; @@ -423,10 +498,10 @@ TEST(Source, GeoJSonSourceUrlUpdate) { }; GeoJSONSource source("source"); - source.baseImpl->setObserver(&test.styleObserver); + source.setObserver(&test.styleObserver); // Load initial, so the source state will be loaded=true - source.baseImpl->loadDescription(test.fileSource); + source.loadDescription(test.fileSource); // Schedule an update test.loop.invoke([&] () { @@ -436,3 +511,39 @@ TEST(Source, GeoJSonSourceUrlUpdate) { test.run(); } + +TEST(Source, ImageSourceImageUpdate) { + SourceTest test; + + test.fileSource.response = [&] (const Resource& resource) { + EXPECT_EQ("http://url", resource.url); + Response response; + response.data = std::make_unique<std::string>(util::read_file("test/fixtures/image/no_profile.png")); + return response; + }; + test.styleObserver.sourceChanged = [&] (Source&) { + // Should be called (test will hang if it doesn't) + test.end(); + }; + std::array<LatLng, 4> coords; + + ImageSource source("source", coords); + source.setURL("http://url"); + source.setObserver(&test.styleObserver); + + // Load initial, so the source state will be loaded=true + source.loadDescription(test.fileSource); + PremultipliedImage rgba({ 1, 1 }); + rgba.data[0] = 255; + rgba.data[1] = 254; + rgba.data[2] = 253; + rgba.data[3] = 0; + + // Schedule an update + test.loop.invoke([&] () { + // Update the url + source.setImage(std::move(rgba)); + }); + + test.run(); +} diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index 841c7b291b..9bdab37ac6 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -2,7 +2,7 @@ #include <mbgl/test/stub_file_source.hpp> #include <mbgl/test/fixture_log_observer.hpp> -#include <mbgl/style/style.hpp> +#include <mbgl/style/style_impl.hpp> #include <mbgl/style/source_impl.hpp> #include <mbgl/style/sources/vector_source.hpp> #include <mbgl/style/layer.hpp> @@ -21,34 +21,34 @@ TEST(Style, Properties) { ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; - style.setJSON(R"STYLE({"name": "Test"})STYLE"); + style.loadJSON(R"STYLE({"name": "Test"})STYLE"); ASSERT_EQ("Test", style.getName()); - style.setJSON(R"STYLE({"center": [10, 20]})STYLE"); + style.loadJSON(R"STYLE({"center": [10, 20]})STYLE"); ASSERT_EQ("", style.getName()); - ASSERT_EQ((LatLng{20, 10}), style.getDefaultLatLng()); + ASSERT_EQ((LatLng{20, 10}), *style.getDefaultCamera().center); - style.setJSON(R"STYLE({"bearing": 24})STYLE"); + style.loadJSON(R"STYLE({"bearing": 24})STYLE"); ASSERT_EQ("", style.getName()); - ASSERT_EQ((LatLng{0, 0}), style.getDefaultLatLng()); - ASSERT_EQ(24, style.getDefaultBearing()); + ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center); + ASSERT_EQ(24, *style.getDefaultCamera().angle); - style.setJSON(R"STYLE({"zoom": 13.3})STYLE"); + style.loadJSON(R"STYLE({"zoom": 13.3})STYLE"); ASSERT_EQ("", style.getName()); - ASSERT_EQ(13.3, style.getDefaultZoom()); + ASSERT_EQ(13.3, *style.getDefaultCamera().zoom); - style.setJSON(R"STYLE({"pitch": 60})STYLE"); + style.loadJSON(R"STYLE({"pitch": 60})STYLE"); ASSERT_EQ("", style.getName()); - ASSERT_EQ(60, style.getDefaultPitch()); + ASSERT_EQ(60, *style.getDefaultCamera().pitch); - style.setJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE"); + style.loadJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE"); ASSERT_EQ("", style.getName()); - ASSERT_EQ((LatLng{0, 0}), style.getDefaultLatLng()); - ASSERT_EQ(0, style.getDefaultBearing()); - ASSERT_EQ(0, style.getDefaultZoom()); - ASSERT_EQ(0, style.getDefaultPitch()); + ASSERT_EQ(LatLng {}, *style.getDefaultCamera().center); + ASSERT_EQ(0, *style.getDefaultCamera().zoom); + ASSERT_EQ(0, *style.getDefaultCamera().angle); + ASSERT_EQ(0, *style.getDefaultCamera().pitch); } TEST(Style, DuplicateSource) { @@ -56,9 +56,9 @@ TEST(Style, DuplicateSource) { ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; - style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); + style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); @@ -78,9 +78,9 @@ TEST(Style, RemoveSourceInUse) { ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; + Style::Impl style { threadPool, fileSource, 1.0 }; - style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); + style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); style.addLayer(std::make_unique<LineLayer>("layerId", "sourceId")); diff --git a/test/style/style_image.test.cpp b/test/style/style_image.test.cpp index 319120df83..e49bf37582 100644 --- a/test/style/style_image.test.cpp +++ b/test/style/style_image.test.cpp @@ -8,7 +8,7 @@ using namespace mbgl; TEST(StyleImage, ZeroWidth) { try { - style::Image(PremultipliedImage({ 0, 16 }), 2.0); + style::Image("test", PremultipliedImage({ 0, 16 }), 2.0); FAIL() << "Expected exception"; } catch (util::SpriteImageException& ex) { EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what()); @@ -17,7 +17,7 @@ TEST(StyleImage, ZeroWidth) { TEST(StyleImage, ZeroHeight) { try { - style::Image(PremultipliedImage({ 16, 0 }), 2.0); + style::Image("test", PremultipliedImage({ 16, 0 }), 2.0); FAIL() << "Expected exception"; } catch (util::SpriteImageException& ex) { EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what()); @@ -26,7 +26,7 @@ TEST(StyleImage, ZeroHeight) { TEST(StyleImage, ZeroRatio) { try { - style::Image(PremultipliedImage({ 16, 16 }), 0.0); + style::Image("test", PremultipliedImage({ 16, 16 }), 0.0); FAIL() << "Expected exception"; } catch (util::SpriteImageException& ex) { EXPECT_STREQ("Sprite pixelRatio may not be <= 0", ex.what()); @@ -34,19 +34,15 @@ TEST(StyleImage, ZeroRatio) { } TEST(StyleImage, Retina) { - style::Image image(PremultipliedImage({ 32, 24 }), 2.0); - EXPECT_EQ(16, image.getWidth()); - EXPECT_EQ(32u, image.image.size.width); - EXPECT_EQ(12, image.getHeight()); - EXPECT_EQ(24u, image.image.size.height); - EXPECT_EQ(2, image.pixelRatio); + style::Image image("test", PremultipliedImage({ 32, 24 }), 2.0); + EXPECT_EQ(32u, image.getImage().size.width); + EXPECT_EQ(24u, image.getImage().size.height); + EXPECT_EQ(2, image.getPixelRatio()); } TEST(StyleImage, FractionalRatio) { - style::Image image(PremultipliedImage({ 20, 12 }), 1.5); - EXPECT_EQ(float(20.0 / 1.5), image.getWidth()); - EXPECT_EQ(20u, image.image.size.width); - EXPECT_EQ(float(12.0 / 1.5), image.getHeight()); - EXPECT_EQ(12u, image.image.size.height); - EXPECT_EQ(1.5, image.pixelRatio); + style::Image image("test", PremultipliedImage({ 20, 12 }), 1.5); + EXPECT_EQ(20u, image.getImage().size.width); + EXPECT_EQ(12u, image.getImage().size.height); + EXPECT_EQ(1.5, image.getPixelRatio()); } diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index 657dc24a70..77acca2868 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -1,7 +1,7 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_layer_observer.hpp> #include <mbgl/test/stub_file_source.hpp> -#include <mbgl/style/style.hpp> +#include <mbgl/style/style_impl.hpp> #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> #include <mbgl/style/layers/circle_layer.hpp> @@ -28,15 +28,6 @@ using namespace mbgl::style; namespace { -template <class T, class... Params> void testClone(Params... params) { - auto layer = std::make_unique<T>(std::forward<Params>(params)...); - auto clone = layer->baseImpl->clone(); - EXPECT_NE(layer.get(), clone.get()); - EXPECT_TRUE(reinterpret_cast<typename T::Impl*>(clone->baseImpl.get())); - layer->impl->id = "test"; - EXPECT_EQ("test", layer->baseImpl->clone()->getID()); -} - const auto color = Color { 1, 0, 0, 1 }; const auto opacity = 1.0f; const auto radius = 1.0f; @@ -61,16 +52,6 @@ const auto duration = 1.0f; } // namespace -TEST(Layer, Clone) { - testClone<BackgroundLayer>("background"); - testClone<CircleLayer>("circle", "source"); - testClone<CustomLayer>("custom", [](void*){}, [](void*, const CustomLayerRenderParameters&){}, [](void*){}, nullptr), - testClone<FillLayer>("fill", "source"); - testClone<LineLayer>("line", "source"); - testClone<RasterLayer>("raster", "source"); - testClone<SymbolLayer>("symbol", "source"); -} - TEST(Layer, BackgroundProperties) { auto layer = std::make_unique<BackgroundLayer>("background"); EXPECT_TRUE(layer->is<BackgroundLayer>()); @@ -222,11 +203,11 @@ TEST(Layer, RasterProperties) { TEST(Layer, Observer) { auto layer = std::make_unique<LineLayer>("line", "source"); StubLayerObserver observer; - layer->baseImpl->setObserver(&observer); + layer->setObserver(&observer); // Notifies observer on filter change. bool filterChanged = false; - observer.layerFilterChanged = [&] (Layer& layer_) { + observer.layerChanged = [&] (Layer& layer_) { EXPECT_EQ(layer.get(), &layer_); filterChanged = true; }; @@ -235,7 +216,7 @@ TEST(Layer, Observer) { // Notifies observer on visibility change. bool visibilityChanged = false; - observer.layerVisibilityChanged = [&] (Layer& layer_) { + observer.layerChanged = [&] (Layer& layer_) { EXPECT_EQ(layer.get(), &layer_); visibilityChanged = true; }; @@ -244,7 +225,7 @@ TEST(Layer, Observer) { // Notifies observer on paint property change. bool paintPropertyChanged = false; - observer.layerPaintPropertyChanged = [&] (Layer& layer_) { + observer.layerChanged = [&] (Layer& layer_) { EXPECT_EQ(layer.get(), &layer_); paintPropertyChanged = true; }; @@ -253,7 +234,7 @@ TEST(Layer, Observer) { // Notifies observer on layout property change. bool layoutPropertyChanged = false; - observer.layerLayoutPropertyChanged = [&] (Layer& layer_, const char *) { + observer.layerChanged = [&] (Layer& layer_) { EXPECT_EQ(layer.get(), &layer_); layoutPropertyChanged = true; }; @@ -262,16 +243,28 @@ TEST(Layer, Observer) { // Does not notify observer on no-op visibility change. visibilityChanged = false; + observer.layerChanged = [&] (Layer& layer_) { + EXPECT_EQ(layer.get(), &layer_); + visibilityChanged = true; + }; layer->setVisibility(VisibilityType::None); EXPECT_FALSE(visibilityChanged); // Does not notify observer on no-op paint property change. paintPropertyChanged = false; + observer.layerChanged = [&] (Layer& layer_) { + EXPECT_EQ(layer.get(), &layer_); + paintPropertyChanged = true; + }; layer->setLineColor(color); EXPECT_FALSE(paintPropertyChanged); // Does not notify observer on no-op layout property change. layoutPropertyChanged = false; + observer.layerChanged = [&] (Layer& layer_) { + EXPECT_EQ(layer.get(), &layer_); + layoutPropertyChanged = true; + }; layer->setLineCap(lineCap); EXPECT_FALSE(layoutPropertyChanged); } @@ -282,8 +275,8 @@ TEST(Layer, DuplicateLayer) { // Setup style ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; - style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); + Style::Impl style { threadPool, fileSource, 1.0 }; + style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); // Add initial layer style.addLayer(std::make_unique<LineLayer>("line", "unusedsource")); diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp index e3c1da582f..5fa81b47e9 100644 --- a/test/style/style_parser.test.cpp +++ b/test/style/style_parser.test.cpp @@ -16,8 +16,8 @@ using namespace mbgl; -typedef std::pair<uint32_t, std::string> Message; -typedef std::vector<Message> Messages; +using Message = std::pair<uint32_t, std::string>; +using Messages = std::vector<Message>; class StyleParserTest : public ::testing::TestWithParam<std::string> {}; |