diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/src/mbgl/test/stub_style_observer.hpp | 7 | ||||
-rw-r--r-- | test/style/source.cpp | 39 |
2 files changed, 45 insertions, 1 deletions
diff --git a/test/src/mbgl/test/stub_style_observer.hpp b/test/src/mbgl/test/stub_style_observer.hpp index aa780121f5..7189fd8af4 100644 --- a/test/src/mbgl/test/stub_style_observer.hpp +++ b/test/src/mbgl/test/stub_style_observer.hpp @@ -6,7 +6,7 @@ using namespace mbgl; using namespace mbgl::style; /** - * An implementation of style::Observer that forwards all methods to dynamically-settable lambas. + * An implementation of style::Observer that forwards all methods to dynamically-settable lambdas. */ class StubStyleObserver : public style::Observer { public: @@ -30,6 +30,10 @@ public: if (sourceLoaded) sourceLoaded(source); } + void onSourceAttributionChanged(Source& source, const std::string& attribution) override { + if (sourceAttributionChanged) sourceAttributionChanged(source, attribution); + } + void onSourceError(Source& source, std::exception_ptr error) override { if (sourceError) sourceError(source, error); } @@ -52,6 +56,7 @@ public: std::function<void ()> spriteLoaded; std::function<void (std::exception_ptr)> spriteError; std::function<void (Source&)> sourceLoaded; + std::function<void (Source&, std::string)> sourceAttributionChanged; std::function<void (Source&, std::exception_ptr)> sourceError; std::function<void (Source&, const OverscaledTileID&)> tileChanged; std::function<void (Source&, const OverscaledTileID&, std::exception_ptr)> tileError; diff --git a/test/style/source.cpp b/test/style/source.cpp index 519ca9288e..859aa82893 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -342,3 +342,42 @@ TEST(Source, VectorTileCancel) { test.run(); } + +TEST(Source, RasterTileAttribution) { + SourceTest test; + + std::string mapboxOSM = ("<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox</a> " + "<a href='http://www.openstreetmap.org/about/' target='_blank'>©️ OpenStreetMap</a>"); + + test.fileSource.tileResponse = [&] (const Resource&) { + Response response; + response.noContent = true; + return response; + }; + + test.fileSource.sourceResponse = [&] (const Resource& resource) { + EXPECT_EQ("url", resource.url); + Response response; + response.data = std::make_unique<std::string>(R"TILEJSON({ "tilejson": "2.1.0", "attribution": ")TILEJSON" + + mapboxOSM + + R"TILEJSON(", "tiles": [ "tiles" ] })TILEJSON"); + return response; + }; + + test.observer.sourceAttributionChanged = [&] (Source&, std::string attribution) { + EXPECT_EQ(mapboxOSM, attribution); + EXPECT_FALSE(mapboxOSM.find("©️ OpenStreetMap") == std::string::npos); + test.end(); + }; + + test.observer.tileError = [&] (Source&, const OverscaledTileID&, std::exception_ptr) { + FAIL() << "Should never be called"; + }; + + RasterSource source("source", "url", 512); + source.baseImpl->setObserver(&test.observer); + source.baseImpl->loadDescription(test.fileSource); + source.baseImpl->updateTiles(test.updateParameters); + + test.run(); +} |