summaryrefslogtreecommitdiff
path: root/test/map
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-13 16:16:38 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-15 14:53:32 +0200
commitfc70cbf1e12e27737c7a256682524cd617d18f71 (patch)
tree10bf1b6c629bb4c642d060182ab1443cdf0084a4 /test/map
parent98f5b71e6db748a2576e9fc6f17b9e76505df1aa (diff)
downloadqtlocation-mapboxgl-fc70cbf1e12e27737c7a256682524cd617d18f71.tar.gz
[core] Replace MapChange enum with MapObserver
Diffstat (limited to 'test/map')
-rw-r--r--test/map/map.test.cpp70
-rw-r--r--test/map/transform.test.cpp2
2 files changed, 45 insertions, 27 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 618c2e6a74..c5d579be3a 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -24,9 +24,37 @@ using namespace mbgl;
using namespace mbgl::style;
using namespace std::literals::string_literals;
+class BackendTest : public HeadlessBackend {
+public:
+ BackendTest() : HeadlessBackend(test::sharedDisplay()) {}
+
+ void setDidFailLoadingMapCallback(std::function<void()>&& callback) {
+ didFailLoadingMapCallback = std::move(callback);
+ }
+
+ void setDidFinishLoadingStyleCallback(std::function<void()>&& callback) {
+ didFinishLoadingStyleCallback = std::move(callback);
+ }
+
+ void onDidFailLoadingMap() final {
+ if (didFailLoadingMapCallback) {
+ didFailLoadingMapCallback();
+ }
+ }
+
+ void onDidFinishLoadingStyle() final {
+ if (didFinishLoadingStyleCallback) {
+ didFinishLoadingStyleCallback();
+ }
+ }
+
+ std::function<void()> didFailLoadingMapCallback;
+ std::function<void()> didFinishLoadingStyleCallback;
+};
+
struct MapTest {
util::RunLoop runLoop;
- HeadlessBackend backend { test::sharedDisplay() };
+ BackendTest backend;
OffscreenView view { backend.getContext() };
StubFileSource fileSource;
ThreadPool threadPool { 4 };
@@ -85,10 +113,8 @@ TEST(Map, SetStyleInvalidJSON) {
Log::setObserver(std::make_unique<FixtureLogObserver>());
bool fail = false;
- test.backend.setMapChangeCallback([&](MapChange change) {
- if (change == mbgl::MapChangeDidFailLoadingMap) {
- fail = true;
- }
+ test.backend.setDidFailLoadingMapCallback([&]() {
+ fail = true;
});
{
@@ -118,10 +144,8 @@ TEST(Map, SetStyleInvalidURL) {
return response;
};
- test.backend.setMapChangeCallback([&](MapChange change) {
- if (change == mbgl::MapChangeDidFailLoadingMap) {
- test.runLoop.stop();
- }
+ test.backend.setDidFailLoadingMapCallback([&]() {
+ test.runLoop.stop();
});
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
@@ -233,10 +257,8 @@ TEST(Map, StyleLoadedSignal) {
// The map should emit a signal on style loaded
bool emitted = false;
- test.backend.setMapChangeCallback([&](MapChange change) {
- if (change == mbgl::MapChangeDidFinishLoadingStyle) {
- emitted = true;
- }
+ test.backend.setDidFinishLoadingStyleCallback([&]() {
+ emitted = true;
});
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
EXPECT_TRUE(emitted);
@@ -255,10 +277,8 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNetworkErrorRetry)) {
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
map.setStyleURL("http://127.0.0.1:3000/style-fail-once-500");
- test.backend.setMapChangeCallback([&](MapChange change) {
- if (change == mbgl::MapChangeDidFinishLoadingStyle) {
- test.runLoop.stop();
- }
+ test.backend.setDidFinishLoadingStyleCallback([&]() {
+ test.runLoop.stop();
});
test.runLoop.run();
@@ -275,16 +295,14 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
util::Timer timer;
// Not found errors should not trigger a retry like other errors.
- test.backend.setMapChangeCallback([&](MapChange change) {
- if (change == mbgl::MapChangeDidFinishLoadingStyle) {
- FAIL() << "Should not retry on not found!";
- }
+ test.backend.setDidFinishLoadingStyleCallback([&]() {
+ FAIL() << "Should not retry on not found!";
+ });
- if (change == mbgl::MapChangeDidFailLoadingMap) {
- timer.start(Milliseconds(1100), 0s, [&] {
- test.runLoop.stop();
- });
- }
+ test.backend.setDidFailLoadingMapCallback([&]() {
+ timer.start(Milliseconds(1100), 0s, [&] {
+ test.runLoop.stop();
+ });
});
test.runLoop.run();
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp
index 9125b6ef1d..5bff4ee5ef 100644
--- a/test/map/transform.test.cpp
+++ b/test/map/transform.test.cpp
@@ -215,7 +215,7 @@ TEST(Transform, ConstrainHeightOnly) {
TEST(Transform, ConstrainWidthAndHeight) {
LatLng loc;
- Transform transform(nullptr, ConstrainMode::WidthAndHeight);
+ Transform transform(MapObserver::nullObserver(), ConstrainMode::WidthAndHeight);
transform.resize({ 1000, 1000 });
transform.setScale(std::pow(2, util::MAX_ZOOM));