summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/fixtures/map/online/0-0-0.vector.pbfbin0 -> 482553 bytes
-rw-r--r--test/fixtures/map/online/sprite.json26
-rw-r--r--test/fixtures/map/online/sprite.pngbin0 -> 3351 bytes
-rw-r--r--test/fixtures/map/online/streets.json14
-rw-r--r--test/fixtures/map/online/style.json27
-rw-r--r--test/map/map.test.cpp55
-rw-r--r--test/src/mbgl/test/http_server.cpp10
-rw-r--r--test/src/mbgl/test/stub_map_observer.hpp7
8 files changed, 137 insertions, 2 deletions
diff --git a/test/fixtures/map/online/0-0-0.vector.pbf b/test/fixtures/map/online/0-0-0.vector.pbf
new file mode 100644
index 0000000000..a0f049ad43
--- /dev/null
+++ b/test/fixtures/map/online/0-0-0.vector.pbf
Binary files differ
diff --git a/test/fixtures/map/online/sprite.json b/test/fixtures/map/online/sprite.json
new file mode 100644
index 0000000000..7ec1526292
--- /dev/null
+++ b/test/fixtures/map/online/sprite.json
@@ -0,0 +1,26 @@
+{
+ "c": {
+ "x": 0,
+ "y": 0,
+ "width": 32,
+ "height": 32,
+ "pixelRatio": 1,
+ "sdf": false
+ },
+ "a": {
+ "x": 0,
+ "y": 0,
+ "width": 32,
+ "height": 32,
+ "pixelRatio": 1,
+ "sdf": false
+ },
+ "b": {
+ "x": 0,
+ "y": 0,
+ "width": 32,
+ "height": 32,
+ "pixelRatio": 1,
+ "sdf": false
+ }
+}
diff --git a/test/fixtures/map/online/sprite.png b/test/fixtures/map/online/sprite.png
new file mode 100644
index 0000000000..a02d8eb542
--- /dev/null
+++ b/test/fixtures/map/online/sprite.png
Binary files differ
diff --git a/test/fixtures/map/online/streets.json b/test/fixtures/map/online/streets.json
new file mode 100644
index 0000000000..adeb10aa78
--- /dev/null
+++ b/test/fixtures/map/online/streets.json
@@ -0,0 +1,14 @@
+{
+ "bounds": [ -180, -85.0511, 180, 85.0511 ],
+ "center": [ 0, 0, 0 ],
+ "description": "",
+ "format": "pbf",
+ "id": "streets",
+ "maskLevel": 8,
+ "maxzoom": 15,
+ "minzoom": 0,
+ "name": "Streets",
+ "scheme": "xyz",
+ "tilejson": "2.0.0",
+ "tiles": [ "http://127.0.0.1:3000/online/{z}-{x}-{y}.vector.pbf" ]
+}
diff --git a/test/fixtures/map/online/style.json b/test/fixtures/map/online/style.json
new file mode 100644
index 0000000000..9543c477aa
--- /dev/null
+++ b/test/fixtures/map/online/style.json
@@ -0,0 +1,27 @@
+{
+ "version": 8,
+ "name": "Water",
+ "sources": {
+ "mapbox": {
+ "type": "vector",
+ "url": "http://127.0.0.1:3000/online/streets.json"
+ }
+ },
+ "sprite": "http://127.0.0.1:3000/online/sprite",
+ "layers": [{
+ "id": "background",
+ "type": "background",
+ "paint": {
+ "background-color": "red"
+ }
+ }, {
+ "id": "water",
+ "type": "fill",
+ "source": "mapbox",
+ "source-layer": "water",
+ "paint": {
+ "fill-pattern": "noise",
+ "fill-antialias": false
+ }
+ }]
+}
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index e00f84eff0..0ec97fd3bc 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -10,12 +10,14 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/math/log2.hpp>
+#include <mbgl/renderer/update_parameters.hpp>
#include <mbgl/storage/file_source_manager.hpp>
#include <mbgl/storage/main_resource_loader.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/image.hpp>
+#include <mbgl/style/image_impl.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
@@ -36,13 +38,13 @@ using namespace mbgl;
using namespace mbgl::style;
using namespace std::literals::string_literals;
-template <class FileSource = StubFileSource>
+template <class FileSource = StubFileSource, class Frontend = HeadlessFrontend>
class MapTest {
public:
util::RunLoop runLoop;
std::shared_ptr<FileSource> fileSource;
StubMapObserver observer;
- HeadlessFrontend frontend;
+ Frontend frontend;
MapAdapter map;
MapTest(float pixelRatio = 1, MapMode mode = MapMode::Static)
@@ -1253,3 +1255,52 @@ TEST(Map, PrefetchDeltaOverrideCustomSource) {
// and current zoom level + parent tiles would be re-requested.
EXPECT_EQ(8, requestedTiles);
}
+
+// Test verifies that Style::Impl::onSpriteLoaded does not create duplicate
+// images when we get new spritesheet from the server and we merge it with
+// currently used spritesheet.
+TEST(Map, TEST_REQUIRES_SERVER(ExpiredSpriteSheet)) {
+ class ForwardingHeadlessFrontend : public HeadlessFrontend {
+ public:
+ using HeadlessFrontend::HeadlessFrontend;
+ ~ForwardingHeadlessFrontend() override = default;
+ void update(std::shared_ptr<UpdateParameters> params) override {
+ if (checkParams) checkParams(params);
+ HeadlessFrontend::update(std::move(params));
+ }
+ std::function<void(std::shared_ptr<UpdateParameters>)> checkParams;
+ };
+
+ MapTest<MainResourceLoader, ForwardingHeadlessFrontend> test{":memory:", ".", 1, MapMode::Continuous};
+
+ auto makeResponse = [](const std::string& path, bool expires = false) {
+ Response response;
+ response.data = std::make_shared<std::string>(util::read_file("test/fixtures/map/online/"s + path));
+ response.expires = expires ? Timestamp{Seconds(0)} : Timestamp::max();
+ return response;
+ };
+
+ test.observer.didFinishLoadingMapCallback = [&test] {
+ test.frontend.checkParams = [](std::shared_ptr<UpdateParameters> params) {
+ EXPECT_TRUE(std::is_sorted(params->images->begin(), params->images->end()));
+ EXPECT_TRUE(params->images->size() < 4u);
+ };
+
+ NetworkStatus::Set(NetworkStatus::Status::Online);
+
+ test.observer.didBecomeIdleCallback = [&test] { test.runLoop.stop(); };
+ };
+
+ NetworkStatus::Set(NetworkStatus::Status::Offline);
+ const std::string prefix = "http://127.0.0.1:3000/online/";
+ auto dbfs = FileSourceManager::get()->getFileSource(FileSourceType::Database, ResourceOptions{});
+ dbfs->forward(Resource::style(prefix + "style.json"), makeResponse("style.json"));
+ dbfs->forward(Resource::source(prefix + "streets.json"), makeResponse("streets.json"));
+ dbfs->forward(Resource::spriteJSON(prefix + "sprite", 1.0), makeResponse("sprite.json", true));
+ dbfs->forward(Resource::spriteImage(prefix + "sprite", 1.0), makeResponse("sprite.png", true));
+ dbfs->forward(Resource::tile(prefix + "{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0, Tileset::Scheme::XYZ),
+ makeResponse("0-0-0.vector.pbf"),
+ [&] { test.map.getStyle().loadURL(prefix + "style.json"); });
+
+ test.runLoop.run();
+}
diff --git a/test/src/mbgl/test/http_server.cpp b/test/src/mbgl/test/http_server.cpp
index 2b72bb2c94..5679b1188b 100644
--- a/test/src/mbgl/test/http_server.cpp
+++ b/test/src/mbgl/test/http_server.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/util/chrono.hpp>
+#include <mbgl/util/io.hpp>
#include <mbgl/util/logging.hpp>
// Limit to 4 threads (default is the nbr of CPU cores)
@@ -9,6 +10,8 @@
#include <atomic>
+using namespace std::literals::string_literals;
+
namespace mbgl {
namespace test {
@@ -182,6 +185,13 @@ void runServer(std::unique_ptr<httplib::Server>& server) {
res.set_content("Request " + std::string(numbers), "text/plain");
});
+ server->Get(R"(/online/(.*))", [](const Request req, Response& res) {
+ res.status = 200;
+ auto file = "test/fixtures/map/online/"s + std::string(req.matches[1]);
+ auto content = util::read_file(file);
+ res.set_content(content, "text/plain");
+ });
+
server->listen("127.0.0.1", 3000);
}
diff --git a/test/src/mbgl/test/stub_map_observer.hpp b/test/src/mbgl/test/stub_map_observer.hpp
index 89ee4e7953..63e42fa6ab 100644
--- a/test/src/mbgl/test/stub_map_observer.hpp
+++ b/test/src/mbgl/test/stub_map_observer.hpp
@@ -38,11 +38,18 @@ public:
}
}
+ void onDidBecomeIdle() final {
+ if (didBecomeIdleCallback) {
+ didBecomeIdleCallback();
+ }
+ }
+
std::function<void()> willStartLoadingMapCallback;
std::function<void()> didFinishLoadingMapCallback;
std::function<void()> didFailLoadingMapCallback;
std::function<void()> didFinishLoadingStyleCallback;
std::function<void(RenderFrameStatus)> didFinishRenderingFrameCallback;
+ std::function<void()> didBecomeIdleCallback;
};