[tests] Add unit test for style loading failures
This commit is contained in:
@@ -43,10 +43,12 @@ public:
|
||||
void invalidate() override;
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
void notifyMapChange(MapChange) override;
|
||||
|
||||
PremultipliedImage readStillImage() override;
|
||||
|
||||
void resize(uint16_t width, uint16_t height);
|
||||
void setMapChangeCallback(std::function<void(MapChange)>&& cb) { mapChangeCallback = std::move(cb); }
|
||||
|
||||
private:
|
||||
// Implementation specific functions
|
||||
@@ -85,6 +87,8 @@ private:
|
||||
GLXPbuffer glxPbuffer = 0;
|
||||
#endif
|
||||
|
||||
std::function<void(MapChange)> mapChangeCallback;
|
||||
|
||||
GLuint fbo = 0;
|
||||
GLuint fboDepthStencil = 0;
|
||||
GLuint fboColor = 0;
|
||||
|
||||
@@ -107,4 +107,10 @@ void HeadlessView::invalidate() {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void HeadlessView::notifyMapChange(MapChange change) {
|
||||
if (mapChangeCallback) {
|
||||
mapChangeCallback(change);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -60,11 +60,20 @@ TEST(Map, SetStyleInvalidJSON) {
|
||||
|
||||
Log::setObserver(std::make_unique<FixtureLogObserver>());
|
||||
|
||||
bool fail = false;
|
||||
test.view.setMapChangeCallback([&](MapChange change) {
|
||||
if (change == mbgl::MapChangeDidFailLoadingMap) {
|
||||
fail = true;
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
map.setStyleJSON("invalid");
|
||||
}
|
||||
|
||||
EXPECT_TRUE(fail);
|
||||
|
||||
auto observer = Log::removeObserver();
|
||||
auto flo = dynamic_cast<FixtureLogObserver*>(observer.get());
|
||||
EXPECT_EQ(1u, flo->count({ EventSeverity::Error, Event::ParseStyle, -1,
|
||||
@@ -73,6 +82,29 @@ TEST(Map, SetStyleInvalidJSON) {
|
||||
EXPECT_TRUE(unchecked.empty()) << unchecked;
|
||||
}
|
||||
|
||||
TEST(Map, SetStyleInvalidURL) {
|
||||
MapTest test;
|
||||
|
||||
test.fileSource.styleResponse = [] (const Resource&) {
|
||||
Response response;
|
||||
response.error = std::make_unique<Response::Error>(
|
||||
Response::Error::Reason::Other,
|
||||
"Failed by the test case");
|
||||
return response;
|
||||
};
|
||||
|
||||
test.view.setMapChangeCallback([&](MapChange change) {
|
||||
if (change == mbgl::MapChangeDidFailLoadingMap) {
|
||||
test.runLoop.stop();
|
||||
}
|
||||
});
|
||||
|
||||
Map map(test.view, test.fileSource, MapMode::Still);
|
||||
map.setStyleURL("mapbox://bar");
|
||||
|
||||
test.runLoop.run();
|
||||
}
|
||||
|
||||
TEST(Map, DoubleStyleLoad) {
|
||||
MapTest test;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user