summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-01-15 12:33:40 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-01-15 12:48:23 +0100
commit5fe586633cb15c99f77ca478446679acf42fddd1 (patch)
tree575b299b0d9a9c500b143be54a6f268ff2cad18c /test
parent8a964fb9313e57b71c64b8c0739ec84f163dc537 (diff)
downloadqtlocation-mapboxgl-5fe586633cb15c99f77ca478446679acf42fddd1.tar.gz
[test] ensure static rendering finishes when a tile can't be loaded
Diffstat (limited to 'test')
-rw-r--r--test/api/render_missing.cpp63
-rw-r--r--test/fixtures/api/assets/streets_missing_tiles.json14
-rw-r--r--test/fixtures/api/water_missing_tiles.json25
-rw-r--r--test/test.gypi1
4 files changed, 103 insertions, 0 deletions
diff --git a/test/api/render_missing.cpp b/test/api/render_missing.cpp
new file mode 100644
index 0000000000..5d63689d0a
--- /dev/null
+++ b/test/api/render_missing.cpp
@@ -0,0 +1,63 @@
+#include "../fixtures/util.hpp"
+#include "../fixtures/fixture_log_observer.hpp"
+
+#include <mbgl/map/map.hpp>
+#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/storage/default_file_source.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/io.hpp>
+
+#include <future>
+
+TEST(API, RenderMissingTile) {
+ using namespace mbgl;
+
+ const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json");
+
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1, 256, 512);
+#ifdef MBGL_ASSET_ZIP
+ // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/`
+ DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip");
+#else
+ DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
+#endif
+
+ Log::setObserver(std::make_unique<FixtureLogObserver>());
+
+ Map map(view, fileSource, MapMode::Still);
+
+ std::string message;
+
+ // This host does not respond (== connection error).
+ map.setStyleJSON(style, "");
+ std::promise<void> promise;
+ map.renderStill([&promise, &message](std::exception_ptr err, PremultipliedImage&&) {
+ ASSERT_TRUE(err.operator bool());
+ try {
+ std::rethrow_exception(err);
+ } catch (const std::exception& ex) {
+ message = ex.what();
+#ifdef MBGL_HTTP_NSURL
+ EXPECT_STREQ("Could not connect to the server.", ex.what());
+#elif MBGL_HTTP_CURL
+ const char* prefix = "Couldn't connect to server:";
+ EXPECT_EQ(0, strncmp(prefix, ex.what(), strlen(prefix))) << "Full message is: \""
+ << ex.what() << "\"";
+#else
+ FAIL();
+#endif
+ }
+ promise.set_value();
+ });
+ promise.get_future().get();
+
+ auto observer = Log::removeObserver();
+ auto flo = dynamic_cast<FixtureLogObserver*>(observer.get());
+ EXPECT_EQ(1, flo->count(FixtureLog::Message(
+ EventSeverity::Error, Event::Style, -1,
+ std::string("Failed to load tile 0/0/0 for source mapbox: " + message))));
+ auto unchecked = flo->unchecked();
+ EXPECT_TRUE(unchecked.empty()) << unchecked;
+}
diff --git a/test/fixtures/api/assets/streets_missing_tiles.json b/test/fixtures/api/assets/streets_missing_tiles.json
new file mode 100644
index 0000000000..671665caeb
--- /dev/null
+++ b/test/fixtures/api/assets/streets_missing_tiles.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:3001/{z}-{x}-{y}.vector.pbf" ]
+}
diff --git a/test/fixtures/api/water_missing_tiles.json b/test/fixtures/api/water_missing_tiles.json
new file mode 100644
index 0000000000..c9ed77318d
--- /dev/null
+++ b/test/fixtures/api/water_missing_tiles.json
@@ -0,0 +1,25 @@
+{
+ "version": 8,
+ "name": "Water",
+ "sources": {
+ "mapbox": {
+ "type": "vector",
+ "url": "asset://streets_missing_tiles.json"
+ }
+ },
+ "layers": [{
+ "id": "background",
+ "type": "background",
+ "paint": {
+ "background-color": "red"
+ }
+ }, {
+ "id": "water",
+ "type": "fill",
+ "source": "mapbox",
+ "source-layer": "water",
+ "paint": {
+ "fill-color": "blue"
+ }
+ }]
+}
diff --git a/test/test.gypi b/test/test.gypi
index 8b13db4c6b..194744198e 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -41,6 +41,7 @@
'api/annotations.cpp',
'api/api_misuse.cpp',
'api/repeated_render.cpp',
+ 'api/render_missing.cpp',
'api/set_style.cpp',
'api/custom_layer.cpp',