1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <mbgl/test/util.hpp>
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_backend.hpp>
#include <mbgl/platform/default/offscreen_view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <future>
#if TEST_HAS_SERVER
#define TEST_REQUIRES_SERVER(name) name
#else
#define TEST_REQUIRES_SERVER(name) DISABLED_ ## name
#endif
TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
using namespace mbgl;
util::RunLoop loop;
const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json");
HeadlessBackend backend;
OffscreenView view(backend.getContext(), { 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
ThreadPool threadPool(4);
Log::setObserver(std::make_unique<FixtureLogObserver>());
Map map(backend, view.size, 1, fileSource, threadPool, MapMode::Still);
std::string message;
// This host does not respond (== connection error).
// Are you seeing this test fail? Make sure you don't have a server running on port 3001!
map.setStyleJSON(style);
map.renderStill(view, [&](std::exception_ptr err) {
ASSERT_TRUE(err.operator bool());
try {
std::rethrow_exception(err);
} catch (const std::exception& ex) {
message = ex.what();
EXPECT_TRUE(message.find("onnect") != std::string::npos); // [C|c]onnect
}
loop.stop();
});
loop.run();
auto observer = Log::removeObserver();
auto flo = dynamic_cast<FixtureLogObserver*>(observer.get());
EXPECT_EQ(1u, flo->count(FixtureLog::Message(
EventSeverity::Error, Event::Style, -1,
std::string("Failed to load tile 0/0/0=>0 for source mapbox: " + message))));
auto unchecked = flo->unchecked();
EXPECT_TRUE(unchecked.empty()) << unchecked;
}
|