From ef76f22c4f5f41a55a31f1fdf829755aabd1c6a3 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Fri, 8 May 2020 18:53:34 +0300 Subject: [test] Add StyleConversion.SetSourceGenericProperties test --- test/CMakeLists.txt | 1 + test/map/map.test.cpp | 10 +++--- test/style/conversion/layer.test.cpp | 2 +- test/style/conversion/source.test.cpp | 58 +++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 test/style/conversion/source.test.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2ead99e4d8..a9337b5274 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,6 +47,7 @@ add_library( ${PROJECT_SOURCE_DIR}/test/style/conversion/layer.test.cpp ${PROJECT_SOURCE_DIR}/test/style/conversion/light.test.cpp ${PROJECT_SOURCE_DIR}/test/style/conversion/property_value.test.cpp + ${PROJECT_SOURCE_DIR}/test/style/conversion/source.test.cpp ${PROJECT_SOURCE_DIR}/test/style/conversion/stringify.test.cpp ${PROJECT_SOURCE_DIR}/test/style/conversion/tileset.test.cpp ${PROJECT_SOURCE_DIR}/test/style/expression/expression.test.cpp diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 7ccd519181..0370f51707 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -1124,12 +1124,10 @@ TEST(Map, UniversalStyleGetter) { Source* imageSource = test.map.getStyle().getSource("image"); ASSERT_TRUE(imageSource); checkConstProperty(imageSource, "url", "https://docs.mapbox.com/mapbox-gl-js/assets/radar.gif"); - std::vector expectedCoordinates{ - std::vector{-80.425, 46.437}, - std::vector{-71.516, 46.437}, - std::vector{-71.516, 37.936}, - std::vector{-80.425, 37.936} - }; + std::vector expectedCoordinates{std::vector{-80.425, 46.437}, + std::vector{-71.516, 46.437}, + std::vector{-71.516, 37.936}, + std::vector{-80.425, 37.936}}; checkConstProperty(imageSource, "coordinates", expectedCoordinates); // Non-existent diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index 079d7ce5a5..9d04c48d28 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -132,7 +132,7 @@ TEST(StyleConversion, OverrideDefaults) { EXPECT_EQ(2u, roundTrippedObject.at("paint").getObject()->size()); } -TEST(StyleConversion, SetGenericProperties) { +TEST(StyleConversion, SetLayerGenericProperties) { auto layer = parseLayer(R"JSON({ "type": "symbol", "id": "symbol", diff --git a/test/style/conversion/source.test.cpp b/test/style/conversion/source.test.cpp new file mode 100644 index 0000000000..e889e01d1d --- /dev/null +++ b/test/style/conversion/source.test.cpp @@ -0,0 +1,58 @@ +#include + +#include +#include + +using namespace mbgl; +using namespace mbgl::style; +using namespace mbgl::style::conversion; +namespace { + +std::unique_ptr parseSource(const std::string& src, const std::string& sourceName) { + Error error; + auto source = convertJSON>(src, error, sourceName); + if (source) return std::move(*source); + return nullptr; +} + +void checkConstProperty(std::unique_ptr& source, const std::string& propertyName, const mbgl::Value& expected) { + Value value = source->getProperty(propertyName); + EXPECT_EQ(expected, value) << propertyName; +} + +void checkSetProperty(std::unique_ptr& source, const std::string& propertyName, const JSValue& value) { + auto error = source->setProperty(propertyName, Convertible(&value)); + EXPECT_EQ(nullopt, error) << error->message; +} + +} // namespace + +TEST(StyleConversion, SetSourceGenericProperties) { + auto source = parseSource(R"JSON({ + "type": "vector", + "tiles": ["http://example.com/{z}-{x}-{y}.vector.pbf"], + "scheme": "xyz", + "minzoom": 11, + "maxzoom": 16, + "attribution": "mapbox", + "bounds": [-180, -73, -120, 73] + })JSON", + "vector_source"); + + ASSERT_NE(nullptr, source); + checkConstProperty(source, "volatile", false); + checkSetProperty(source, "volatile", JSValue(true)); + checkConstProperty(source, "volatile", true); + + checkConstProperty(source, "minimum-tile-update-interval", 0.0); + checkSetProperty(source, "minimum-tile-update-interval", JSValue(10.5)); + checkConstProperty(source, "minimum-tile-update-interval", 10.5); + + checkConstProperty(source, "prefetch-zoom-delta", NullValue()); + checkSetProperty(source, "prefetch-zoom-delta", JSValue(0)); + checkConstProperty(source, "prefetch-zoom-delta", 0u); + + checkConstProperty(source, "max-overscale-factor-for-parent-tiles", NullValue()); + checkSetProperty(source, "max-overscale-factor-for-parent-tiles", JSValue(2)); + checkConstProperty(source, "max-overscale-factor-for-parent-tiles", 2u); +} \ No newline at end of file -- cgit v1.2.1