diff options
Diffstat (limited to 'test/map/map.test.cpp')
-rw-r--r-- | test/map/map.test.cpp | 153 |
1 files changed, 140 insertions, 13 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 09e1b92336..0eebc93f32 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -259,10 +259,7 @@ TEST(Map, Offline) { test.map.getStyle().loadURL(prefix + "style.json"); - test::checkImage("test/fixtures/map/offline", - test.frontend.render(test.map), - 0.0015, - 0.1); + test::checkImage("test/fixtures/map/offline", test.frontend.render(test.map).image, 0.0015, 0.1); NetworkStatus::Set(NetworkStatus::Status::Online); } @@ -608,7 +605,7 @@ TEST(Map, AddLayer) { layer->setBackgroundColor({ { 1, 0, 0, 1 } }); test.map.getStyle().addLayer(std::move(layer)); - test::checkImage("test/fixtures/map/add_layer", test.frontend.render(test.map)); + test::checkImage("test/fixtures/map/add_layer", test.frontend.render(test.map).image); } TEST(Map, WithoutVAOExtension) { @@ -623,7 +620,7 @@ TEST(Map, WithoutVAOExtension) { test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); - test::checkImage("test/fixtures/map/no_vao", test.frontend.render(test.map), 0.002); + test::checkImage("test/fixtures/map/no_vao", test.frontend.render(test.map).image, 0.002); } TEST(Map, RemoveLayer) { @@ -636,7 +633,7 @@ TEST(Map, RemoveLayer) { test.map.getStyle().addLayer(std::move(layer)); test.map.getStyle().removeLayer("background"); - test::checkImage("test/fixtures/map/remove_layer", test.frontend.render(test.map)); + test::checkImage("test/fixtures/map/remove_layer", test.frontend.render(test.map).image); } TEST(Map, DisabledSources) { @@ -694,9 +691,9 @@ TEST(Map, DisabledSources) { } )STYLE"); - test::checkImage("test/fixtures/map/disabled_layers/first", test.frontend.render(test.map)); + test::checkImage("test/fixtures/map/disabled_layers/first", test.frontend.render(test.map).image); test.map.jumpTo(CameraOptions().withZoom(0.5)); - test::checkImage("test/fixtures/map/disabled_layers/second", test.frontend.render(test.map)); + test::checkImage("test/fixtures/map/disabled_layers/second", test.frontend.render(test.map).image); } TEST(Map, DontLoadUnneededTiles) { @@ -815,10 +812,7 @@ TEST(Map, NoContentTiles) { }] })STYLE"); - test::checkImage("test/fixtures/map/nocontent", - test.frontend.render(test.map), - 0.0015, - 0.1); + test::checkImage("test/fixtures/map/nocontent", test.frontend.render(test.map).image, 0.0015, 0.1); } // https://github.com/mapbox/mapbox-gl-native/issues/12432 @@ -926,4 +920,137 @@ TEST(Map, Issue15342) { }; test.runLoop.run(); +} + +TEST(Map, UniversalStyleGetter) { + MapTest<> test; + + test.map.getStyle().loadJSON(R"STYLE({ + "sources": { + "mapbox": { + "type": "vector", + "tiles": ["http://example.com/{z}-{x}-{y}.vector.pbf"] + } + }, + "layers": [{ + "id": "line", + "type": "line", + "source": "mapbox", + "paint": { + "line-color": "red", + "line-opacity": 0.5, + "line-width": ["get", "width"] + }, + "layout": { + "line-cap": "butt" + } + }] + })STYLE"); + + Layer* lineLayer = test.map.getStyle().getLayer("line"); + ASSERT_TRUE(lineLayer); + + StyleProperty nonexistent = lineLayer->getProperty("nonexistent"); + ASSERT_FALSE(nonexistent.getValue()); + EXPECT_EQ(StyleProperty::Kind::Undefined, nonexistent.getKind()); + + StyleProperty undefined = lineLayer->getProperty("line-blur"); + ASSERT_FALSE(undefined.getValue()); + EXPECT_EQ(StyleProperty::Kind::Undefined, undefined.getKind()); + + StyleProperty lineColor = lineLayer->getProperty("line-color"); + ASSERT_TRUE(lineColor.getValue()); + EXPECT_EQ(StyleProperty::Kind::Constant, lineColor.getKind()); + ASSERT_TRUE(lineColor.getValue().getObject()); + const auto& color = *(lineColor.getValue().getObject()); + EXPECT_EQ(1.0, *color.at("r").getDouble()); + EXPECT_EQ(0.0, *color.at("g").getDouble()); + EXPECT_EQ(0.0, *color.at("b").getDouble()); + EXPECT_EQ(1.0, *color.at("a").getDouble()); + + StyleProperty lineOpacity = lineLayer->getProperty("line-opacity"); + ASSERT_TRUE(lineOpacity.getValue()); + EXPECT_EQ(StyleProperty::Kind::Constant, lineOpacity.getKind()); + ASSERT_TRUE(lineOpacity.getValue().getDouble()); + EXPECT_EQ(0.5, *lineOpacity.getValue().getDouble()); + + StyleProperty lineOpacityTransition = lineLayer->getProperty("line-opacity-transition"); + ASSERT_TRUE(lineOpacityTransition.getValue()); + EXPECT_EQ(StyleProperty::Kind::Transition, lineOpacityTransition.getKind()); + ASSERT_TRUE(lineOpacityTransition.getValue().getArray()); + EXPECT_EQ(3u, lineOpacityTransition.getValue().getArray()->size()); + + StyleProperty lineWidth = lineLayer->getProperty("line-width"); + ASSERT_TRUE(lineWidth.getValue()); + EXPECT_EQ(StyleProperty::Kind::Expression, lineWidth.getKind()); + ASSERT_TRUE(lineWidth.getValue().getArray()); + + const auto& expression = *lineWidth.getValue().getArray(); + EXPECT_EQ(2u, expression.size()); + ASSERT_TRUE(expression[0].getString()); + EXPECT_EQ("number", *expression[0].getString()); + ASSERT_TRUE(expression[1].getArray()); + const auto& operation = *expression[1].getArray(); + EXPECT_EQ(2, operation.size()); + ASSERT_TRUE(operation[0].getString()); + EXPECT_EQ("get", *operation[0].getString()); + ASSERT_TRUE(operation[1].getString()); + EXPECT_EQ("width", *operation[1].getString()); + + StyleProperty lineCap = lineLayer->getProperty("line-cap"); + ASSERT_TRUE(lineCap.getValue()); + EXPECT_EQ(StyleProperty::Kind::Constant, lineCap.getKind()); + ASSERT_TRUE(lineCap.getValue().getString()); + EXPECT_EQ(std::string("butt"), *lineCap.getValue().getString()); +} + +TEST(Map, NoHangOnMissingImage) { + MapTest<> test; + + test.fileSource->tileResponse = [&](const Resource&) { + Response result; + result.data = std::make_shared<std::string>(util::read_file("test/fixtures/map/issue12432/0-0-0.mvt")); + return result; + }; + + test.fileSource->spriteImageResponse = [&](const Resource&) { + Response result; + result.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/sprite.png")); + return result; + }; + + test.fileSource->spriteJSONResponse = [&](const Resource&) { + Response result; + result.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/sprite.json")); + return result; + }; + + const std::string style{R"STYLE({ + "version": 8, + "sprite": "http://example.com/sprites/sprite", + "sources": { + "mapbox": { + "type": "vector", + "tiles": ["http://example.com/{z}-{x}-{y}.vector.pbf"] + } + }, + "layers": [{ + "id": "background", + "type": "background", + "paint": {"background-color": "white"} + },{ + "id": "water", + "type": "fill", + "source": "mapbox", + "source-layer": "water", + "paint": {"fill-pattern": "missing"} + }] + })STYLE"}; + test.map.getStyle().loadJSON(style); + test.frontend.render(test.map); + + test.map.getStyle().loadJSON(style); + test.map.jumpTo(test.map.getStyle().getDefaultCamera()); + // The test passes if the following call does not hang. + test.frontend.render(test.map); }
\ No newline at end of file |