[test] ensure static rendering finishes when a tile can't be loaded

This commit is contained in:
Konstantin Käfer
2016-01-15 12:33:40 +01:00
parent 8a964fb931
commit 5fe586633c
4 changed files with 103 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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" ]
}

View File

@@ -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"
}
}]
}

View File

@@ -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',