diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/src/mbgl/test/stub_style_observer.hpp | 5 | ||||
-rw-r--r-- | test/style/source.test.cpp | 34 |
2 files changed, 39 insertions, 0 deletions
diff --git a/test/src/mbgl/test/stub_style_observer.hpp b/test/src/mbgl/test/stub_style_observer.hpp index 7189fd8af4..95280565ff 100644 --- a/test/src/mbgl/test/stub_style_observer.hpp +++ b/test/src/mbgl/test/stub_style_observer.hpp @@ -38,6 +38,10 @@ public: if (sourceError) sourceError(source, error); } + void onSourceDescriptionChanged(Source& source) override { + if (sourceDescriptionChanged) sourceDescriptionChanged(source); + } + void onTileChanged(Source& source, const OverscaledTileID& tileID) override { if (tileChanged) tileChanged(source, tileID); }; @@ -58,6 +62,7 @@ public: std::function<void (Source&)> sourceLoaded; std::function<void (Source&, std::string)> sourceAttributionChanged; std::function<void (Source&, std::exception_ptr)> sourceError; + std::function<void (Source&)> sourceDescriptionChanged; std::function<void (Source&, const OverscaledTileID&)> tileChanged; std::function<void (Source&, const OverscaledTileID&, std::exception_ptr)> tileError; std::function<void (std::exception_ptr)> resourceError; diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 859aa82893..3270894a59 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -381,3 +381,37 @@ TEST(Source, RasterTileAttribution) { test.run(); } + +TEST(Source, GeoJSonSourceUrlUpdate) { + SourceTest test; + + test.fileSource.sourceResponse = [&] (const Resource& resource) { + EXPECT_EQ("url", resource.url); + Response response; + response.data = std::make_unique<std::string>("{\"geometry\": {\"type\": \"Point\", \"coordinates\": [1.1, 1.1]}, \"type\": \"Feature\", \"properties\": {}}"); + return response; + }; + + test.observer.sourceDescriptionChanged = [&] (Source&) { + //Should be called (test will hang if it doesn't) + test.end(); + }; + + test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) { + FAIL() << "Should never be called"; + }; + + GeoJSONSource source("source"); + source.baseImpl->setObserver(&test.observer); + + //Load initial, so the source state will be loaded=true + source.baseImpl->loadDescription(test.fileSource); + + //Schedule an update + test.loop.invoke([&] () { + //Update the url + source.setURL(std::string("http://source-url.ext")); + }); + + test.run(); +} |