#include #include #include #include #include #include #include #include #include #include #include #include using namespace mbgl; using namespace mbgl::style; TEST(Style, Properties) { util::RunLoop loop; ThreadPool threadPool{ 1 }; StubFileSource fileSource; Style::Impl style { threadPool, fileSource, 1.0 }; style.loadJSON(R"STYLE({"name": "Test"})STYLE"); ASSERT_EQ("Test", style.getName()); style.loadJSON(R"STYLE({"center": [10, 20]})STYLE"); ASSERT_EQ("", style.getName()); ASSERT_EQ((LatLng{20, 10}), style.getDefaultLatLng()); style.loadJSON(R"STYLE({"bearing": 24})STYLE"); ASSERT_EQ("", style.getName()); ASSERT_EQ((LatLng{0, 0}), style.getDefaultLatLng()); ASSERT_EQ(24, style.getDefaultBearing()); style.loadJSON(R"STYLE({"zoom": 13.3})STYLE"); ASSERT_EQ("", style.getName()); ASSERT_EQ(13.3, style.getDefaultZoom()); style.loadJSON(R"STYLE({"pitch": 60})STYLE"); ASSERT_EQ("", style.getName()); ASSERT_EQ(60, style.getDefaultPitch()); 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()); } TEST(Style, DuplicateSource) { util::RunLoop loop; ThreadPool threadPool{ 1 }; StubFileSource fileSource; Style::Impl style { threadPool, fileSource, 1.0 }; style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); style.addSource(std::make_unique("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); try { style.addSource(std::make_unique("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); FAIL() << "Should not have been allowed to add a duplicate source id"; } catch (std::runtime_error) { // Expected } } TEST(Style, RemoveSourceInUse) { util::RunLoop loop; auto log = new FixtureLogObserver(); Log::setObserver(std::unique_ptr(log)); ThreadPool threadPool{ 1 }; StubFileSource fileSource; Style::Impl style { threadPool, fileSource, 1.0 }; style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); style.addSource(std::make_unique("sourceId", "mapbox://mapbox.mapbox-terrain-v2")); style.addLayer(std::make_unique("layerId", "sourceId")); // Should not remove the source auto removed = style.removeSource("sourceId"); ASSERT_EQ(nullptr, removed); ASSERT_NE(nullptr, style.getSource("sourceId")); const FixtureLogObserver::LogMessage logMessage { EventSeverity::Warning, Event::General, int64_t(-1), "Source 'sourceId' is in use, cannot remove", }; EXPECT_EQ(log->count(logMessage), 1u); }