diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/style/style_layer.cpp | 208 |
1 files changed, 200 insertions, 8 deletions
diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp index ed8904dabd..8af7a07d30 100644 --- a/test/style/style_layer.cpp +++ b/test/style/style_layer.cpp @@ -1,19 +1,211 @@ #include <mbgl/test/util.hpp> #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/circle_layer_impl.hpp> +#include <mbgl/style/layers/custom_layer.hpp> +#include <mbgl/style/layers/custom_layer_impl.hpp> +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/fill_layer_impl.hpp> +#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/line_layer_impl.hpp> +#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/raster_layer_impl.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/style/layers/symbol_layer_impl.hpp> using namespace mbgl; using namespace mbgl::style; -TEST(Layer, Clone) { - std::unique_ptr<Layer> layer = std::make_unique<BackgroundLayer>("id"); - std::unique_ptr<Layer> clone = layer->baseImpl->clone(); - EXPECT_NE(layer.get(), clone.get()); - EXPECT_TRUE(reinterpret_cast<BackgroundLayer::Impl*>(clone->baseImpl.get())); -} +namespace { -TEST(Layer, CloneCopiesBaseProperties) { - std::unique_ptr<BackgroundLayer> layer = std::make_unique<BackgroundLayer>("id"); +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 = PropertyValue<Color> {{{ 1, 0, 0, 1 }}}; +const auto opacity = PropertyValue<float> { 1.0f }; +const auto radius = PropertyValue<float> { 1.0f }; +const auto blur = PropertyValue<float> { 1.0f }; +const auto pattern = PropertyValue<std::string> { "foo" }; +const auto antialias = PropertyValue<bool> { false }; +const auto translate = PropertyValue<std::array<float, 2>> {{{ 0, 0 }}}; +const auto translateAnchor = PropertyValue<TranslateAnchorType> { TranslateAnchorType::Map }; +const auto lineCap = PropertyValue<LineCapType> { LineCapType::Round }; +const auto lineJoin = PropertyValue<LineJoinType> { LineJoinType::Miter }; +const auto miterLimit = PropertyValue<float> { 1.0f }; +const auto roundLimit = PropertyValue<float> { 1.0f }; +const auto width = PropertyValue<float> { 1.0f }; +const auto gapWidth = PropertyValue<float> { 1.0f }; +const auto offset = PropertyValue<float> { 1.0f }; +const auto dashArray = PropertyValue<std::vector<float>> {{}}; +const auto hueRotate = PropertyValue<float> { 1.0f }; +const auto brightness = PropertyValue<float> { 1.0f }; +const auto saturation = PropertyValue<float> { 1.0f }; +const auto contrast = PropertyValue<float> { 1.0f }; +const auto duration = PropertyValue<float> { 1.0f }; + +} // namespace + +TEST(Layer, Clone) { + testClone<BackgroundLayer>("background"); + testClone<CircleLayer>("circle"); + testClone<CustomLayer>("custom", [](void*){}, [](void*, const CustomLayerRenderParameters&){}, [](void*){}, nullptr), + testClone<FillLayer>("fill"); + testClone<LineLayer>("line"); + testClone<RasterLayer>("raster"); + testClone<SymbolLayer>("symbol"); +} + +TEST(Layer, BackgroundProperties) { + auto layer = std::make_unique<BackgroundLayer>("background"); + EXPECT_TRUE(layer->is<BackgroundLayer>()); + + // Paint properties + + layer->setBackgroundColor(color); + EXPECT_EQ(layer->getBackgroundColor().asConstant(), color.asConstant()); + + layer->setBackgroundOpacity(opacity); + EXPECT_EQ(layer->getBackgroundOpacity().asConstant(), opacity.asConstant()); + + layer->setBackgroundPattern(pattern); + EXPECT_EQ(layer->getBackgroundPattern().asConstant(), pattern.asConstant()); +} + +TEST(Layer, CircleProperties) { + auto layer = std::make_unique<CircleLayer>("circle"); + EXPECT_TRUE(layer->is<CircleLayer>()); + + // Paint properties + + layer->setCircleColor(color); + EXPECT_EQ(layer->getCircleColor().asConstant(), color.asConstant()); + + layer->setCircleOpacity(opacity); + EXPECT_EQ(layer->getCircleOpacity().asConstant(), opacity.asConstant()); + + layer->setCircleRadius(radius); + EXPECT_EQ(layer->getCircleRadius().asConstant(), radius.asConstant()); + + layer->setCircleBlur(blur); + EXPECT_EQ(layer->getCircleBlur().asConstant(), blur.asConstant()); + + layer->setCircleTranslate(translate); + EXPECT_EQ(layer->getCircleTranslate().asConstant(), translate.asConstant()); + + layer->setCircleTranslateAnchor(translateAnchor); + EXPECT_EQ(layer->getCircleTranslateAnchor().asConstant(), translateAnchor.asConstant()); +} + +TEST(Layer, FillProperties) { + auto layer = std::make_unique<FillLayer>("fill"); + EXPECT_TRUE(layer->is<FillLayer>()); + + // Paint properties + + layer->setFillColor(color); + EXPECT_EQ(layer->getFillColor().asConstant(), color.asConstant()); + + layer->setFillOutlineColor(color); + EXPECT_EQ(layer->getFillOutlineColor().asConstant(), color.asConstant()); + + layer->setFillOpacity(opacity); + EXPECT_EQ(layer->getFillOpacity().asConstant(), opacity.asConstant()); + + layer->setFillPattern(pattern); + EXPECT_EQ(layer->getFillPattern().asConstant(), pattern.asConstant()); + + layer->setFillAntialias(antialias); + EXPECT_EQ(layer->getFillAntialias().asConstant(), antialias.asConstant()); + + layer->setFillTranslate(translate); + EXPECT_EQ(layer->getFillTranslate().asConstant(), translate.asConstant()); + + layer->setFillTranslateAnchor(translateAnchor); + EXPECT_EQ(layer->getFillTranslateAnchor().asConstant(), translateAnchor.asConstant()); +} + +TEST(Layer, LineProperties) { + auto layer = std::make_unique<LineLayer>("line"); + EXPECT_TRUE(layer->is<LineLayer>()); + + // Layout properties + + layer->setLineCap(lineCap); + EXPECT_EQ(layer->getLineCap().asConstant(), lineCap.asConstant()); + + layer->setLineJoin(lineJoin); + EXPECT_EQ(layer->getLineJoin().asConstant(), lineJoin.asConstant()); + + layer->setLineMiterLimit(miterLimit); + EXPECT_EQ(layer->getLineMiterLimit().asConstant(), miterLimit.asConstant()); + + layer->setLineRoundLimit(roundLimit); + EXPECT_EQ(layer->getLineRoundLimit().asConstant(), roundLimit.asConstant()); + + // Paint properties + + layer->setLineColor(color); + EXPECT_EQ(layer->getLineColor().asConstant(), color.asConstant()); + + layer->setLineOpacity(opacity); + EXPECT_EQ(layer->getLineOpacity().asConstant(), opacity.asConstant()); + + layer->setLineTranslate(translate); + EXPECT_EQ(layer->getLineTranslate().asConstant(), translate.asConstant()); + + layer->setLineTranslateAnchor(translateAnchor); + EXPECT_EQ(layer->getLineTranslateAnchor().asConstant(), translateAnchor.asConstant()); + + layer->setLineWidth(width); + EXPECT_EQ(layer->getLineWidth().asConstant(), width.asConstant()); + + layer->setLineGapWidth(gapWidth); + EXPECT_EQ(layer->getLineGapWidth().asConstant(), gapWidth.asConstant()); + + layer->setLineOffset(offset); + EXPECT_EQ(layer->getLineOffset().asConstant(), offset.asConstant()); + + layer->setLineBlur(blur); + EXPECT_EQ(layer->getLineBlur().asConstant(), blur.asConstant()); + + layer->setLineDasharray(dashArray); + EXPECT_EQ(layer->getLineDasharray().asConstant(), dashArray.asConstant()); + + layer->setLinePattern(pattern); + EXPECT_EQ(layer->getLinePattern().asConstant(), pattern.asConstant()); +} + +TEST(Layer, RasterProperties) { + auto layer = std::make_unique<RasterLayer>("raster"); + EXPECT_TRUE(layer->is<RasterLayer>()); + + // Paint properties + + layer->setRasterOpacity(opacity); + EXPECT_EQ(layer->getRasterOpacity().asConstant(), opacity.asConstant()); + + layer->setRasterHueRotate(hueRotate); + EXPECT_EQ(layer->getRasterHueRotate().asConstant(), hueRotate.asConstant()); + + layer->setRasterBrightnessMin(brightness); + EXPECT_EQ(layer->getRasterBrightnessMin().asConstant(), brightness.asConstant()); + + layer->setRasterBrightnessMax(brightness); + EXPECT_EQ(layer->getRasterBrightnessMax().asConstant(), brightness.asConstant()); + + layer->setRasterSaturation(saturation); + EXPECT_EQ(layer->getRasterSaturation().asConstant(), saturation.asConstant()); + + layer->setRasterContrast(contrast); + EXPECT_EQ(layer->getRasterContrast().asConstant(), contrast.asConstant()); + + layer->setRasterFadeDuration(duration); + EXPECT_EQ(layer->getRasterFadeDuration().asConstant(), duration.asConstant()); +} |