summaryrefslogtreecommitdiff
path: root/test/style
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-05-29 14:13:52 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-05-30 13:07:03 +0300
commit005dc6d122d5ae0c8d20d2f7297649d2bbae9ac8 (patch)
treef4012a6af2af5ded570bee4c530e66dd4a306f7b /test/style
parentff3dc29ffd371227a0013ed14176d5c5d6d96b0b (diff)
downloadqtlocation-mapboxgl-005dc6d122d5ae0c8d20d2f7297649d2bbae9ac8.tar.gz
[core] check source usage before remove
Diffstat (limited to 'test/style')
-rw-r--r--test/style/style.test.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp
index b529abad4a..841c7b291b 100644
--- a/test/style/style.test.cpp
+++ b/test/style/style.test.cpp
@@ -1,10 +1,12 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/layer.hpp>
+#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/default_thread_pool.hpp>
@@ -67,3 +69,33 @@ TEST(Style, DuplicateSource) {
// Expected
}
}
+
+TEST(Style, RemoveSourceInUse) {
+ util::RunLoop loop;
+
+ auto log = new FixtureLogObserver();
+ Log::setObserver(std::unique_ptr<Log::Observer>(log));
+
+ ThreadPool threadPool{ 1 };
+ StubFileSource fileSource;
+ Style style { threadPool, fileSource, 1.0 };
+
+ style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+
+ style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2"));
+ style.addLayer(std::make_unique<LineLayer>("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);
+}