[core] guard against duplicate source id’s

This commit is contained in:
Ivo van Dongen
2016-11-28 17:35:10 +02:00
committed by Jesse Bounds
parent 8317a11a10
commit 2c4e7ae70f
2 changed files with 31 additions and 0 deletions

View File

@@ -3,10 +3,13 @@
#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/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <memory>
using namespace mbgl;
using namespace mbgl::style;
@@ -113,3 +116,21 @@ TEST(Style, Properties) {
ASSERT_EQ(0, style.getDefaultZoom());
ASSERT_EQ(0, style.getDefaultPitch());
}
TEST(Style, DuplicateSource) {
util::RunLoop loop;
StubFileSource fileSource;
Style style { 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"));
try {
style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2"));
FAIL() << "Should not have been allowed to add a duplicate source id";
} catch (std::runtime_error) {
//Expected
}
}