Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] layer visibility test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Dec 7, 2016
1 parent 500d948 commit f631efd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"lodash": "^4.16.4",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#597115a1e1bd982944b068f8accde34eada74fc2",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#0c6f3e00193248474349cd730e232eb5ffcd9bf4",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#989fb6d1a148930aa66409a96671dfce6e3e1535",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"request": "^2.72.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 43 additions & 1 deletion test/map/map.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/async_task.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/util/color.hpp>
#include <mapbox/geojson.hpp>

using namespace mbgl;
using namespace mbgl::style;
Expand Down Expand Up @@ -444,7 +449,6 @@ TEST(Map, DontLoadUnneededTiles) {
}
}


class MockBackend : public HeadlessBackend {
public:
MockBackend(std::shared_ptr<HeadlessDisplay> display_)
Expand Down Expand Up @@ -505,3 +509,41 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
map.setStyleJSON(util::read_file("test/fixtures/api/water.json"));
util::RunLoop::Get()->run();
}

TEST(Map, MakeLayerVisible) {
MapTest test;

Map map(test.backend, test.view.size, 1, test.fileSource, test.threadPool, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));

// Check initial state (forces render)
test::checkImage("test/fixtures/map/make_layer_visible/pre", test::render(map, test.view));

mapbox::geojson::point geometry{ 0.0, 0.0 };
auto source = std::make_unique<GeoJSONSource>("source");
source->setGeoJSON(geometry);
map.addSource(std::move(source));

auto layer = std::make_unique<CircleLayer>("layer", "source");
layer->setCircleRadius(8.0);
layer->setCircleColor({{ 1, 0, 0, 1 }});
map.addLayer(std::move(layer));

// Check layer is rendered
map.getLayer("layer")->setVisibility(VisibilityType::Visible);
test::checkImage("test/fixtures/map/make_layer_visible/result", test::render(map, test.view));
ASSERT_TRUE(map.getSource("source")->baseImpl->enabled);

// Make the layer invisible (disables the source)
map.getLayer("layer")->setVisibility(VisibilityType::None);

// Check initial state (forces render)
test::checkImage("test/fixtures/map/make_layer_visible/pre", test::render(map, test.view));
ASSERT_FALSE(map.getSource("source")->baseImpl->enabled);

// Check after enabling
map.getLayer("layer")->setVisibility(VisibilityType::Visible);
test::checkImage("test/fixtures/map/make_layer_visible/result", test::render(map, test.view));
ASSERT_TRUE(map.getSource("source")->baseImpl->enabled);
}

0 comments on commit f631efd

Please sign in to comment.