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
|
#include "../fixtures/util.hpp"
#include "../fixtures/fixture_log_observer.hpp"
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/exception.hpp>
#include <future>
using namespace mbgl;
TEST(API, RenderWithoutCallback) {
FixtureLogObserver* log = new FixtureLogObserver();
Log::setObserver(std::unique_ptr<Log::Observer>(log));
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
view.resize(128, 512);
OnlineFileSource fileSource(nullptr);
std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, MapMode::Still);
map->renderStill(nullptr);
// Force Map thread to join.
map.reset();
const FixtureLogObserver::LogMessage logMessage {
EventSeverity::Error,
Event::General,
int64_t(-1),
"StillImageCallback not set",
};
EXPECT_EQ(log->count(logMessage), 1u);
}
TEST(API, RenderWithoutStyle) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
view.resize(128, 512);
OnlineFileSource fileSource(nullptr);
Map map(view, fileSource, MapMode::Still);
std::promise<std::exception_ptr> promise;
map.renderStill([&promise](std::exception_ptr error, PremultipliedImage&&) {
promise.set_value(error);
});
try {
std::rethrow_exception(promise.get_future().get());
} catch (const util::MisuseException& ex) {
EXPECT_EQ(std::string(ex.what()), "Map doesn't have a style");
} catch (const std::exception&) {
EXPECT_TRUE(false) << "Unhandled exception.";
}
}
|