diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-04-24 10:25:43 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2018-05-21 13:26:49 -0400 |
commit | 9accdee5d8da29481e400276d1ee10c431575356 (patch) | |
tree | a0a96ebdf5daee1250fbea93f69c93dad81b7c67 | |
parent | 11b8eb80e3192ba9c91787e34d30144f2c5fbded (diff) | |
download | qtlocation-mapboxgl-9accdee5d8da29481e400276d1ee10c431575356.tar.gz |
Use built-in expectation functionality to replace performSelector dance.
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MGLCameraTransitionTests.mm | 31 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MGLShapeSourceTests.m | 10 | ||||
-rw-r--r-- | platform/macos/CHANGELOG.md | 1 |
4 files changed, 21 insertions, 22 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index ef89b20c43..f066501e27 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -15,6 +15,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Other changes * Unknown tokens in URLs are now preserved, rather than replaced with an empty string. ([#11787](https://github.com/mapbox/mapbox-gl-native/issues/11787)) +* Adjusted when and how the camera transition update and finish callbacks are called, fixing recursion bugs. ([#5833](https://github.com/mapbox/mapbox-gl-native/issues/5833), [#11180](https://github.com/mapbox/mapbox-gl-native/issues/11180)) ## 4.0.1 - May 14, 2018 diff --git a/platform/ios/Integration Tests/MGLCameraTransitionTests.mm b/platform/ios/Integration Tests/MGLCameraTransitionTests.mm index c8cc57e0b2..c895f47983 100644 --- a/platform/ios/Integration Tests/MGLCameraTransitionTests.mm +++ b/platform/ios/Integration Tests/MGLCameraTransitionTests.mm @@ -9,9 +9,10 @@ - (void)testSetAndResetNorthWithDispatchAsyncInDelegateMethod { XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + expectation.expectedFulfillmentCount = 2; + expectation.assertForOverFulfill = YES; __weak typeof(self) weakself = self; - __block NSInteger delegateCallCount = 0; self.regionDidChange = ^(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated) { @@ -19,7 +20,7 @@ if (!strongSelf) return; - delegateCallCount++; + [expectation fulfill]; MGLTestAssert(strongSelf, mapView.userTrackingMode != MGLUserTrackingModeFollowWithHeading); if (mapView.direction != 0.0) { @@ -27,26 +28,22 @@ [mapView resetNorth]; }); } - - [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; - [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:0.5]; }; [self.mapView setDirection:90 animated:YES]; // loop, render, and wait [self waitForExpectations:@[expectation] timeout:1.5]; - - XCTAssert(delegateCallCount == 2, @"Expecting 2 regionDidChange callbacks, got %ld", delegateCallCount); // Once for the setDirection and once for the reset north } - (void)testSetAndResetNorthInDelegateMethod { XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + expectation.expectedFulfillmentCount = 2; + expectation.assertForOverFulfill = YES; __weak typeof(self) weakself = self; - __block NSInteger delegateCallCount = 0; self.regionDidChange = ^(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated) { @@ -54,22 +51,17 @@ if (!strongSelf) return; - delegateCallCount++; + [expectation fulfill]; MGLTestAssert(strongSelf, mapView.userTrackingMode != MGLUserTrackingModeFollowWithHeading); if (mapView.direction != 0.0) { NSLog(@"Reset to north"); [mapView resetNorth]; } - - [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; - [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:0.5]; }; [self.mapView setDirection:90 animated:YES]; [self waitForExpectations:@[expectation] timeout:1.5]; - - XCTAssert(delegateCallCount == 2, @"Expecting 2 regionDidChange callbacks, got %ld", delegateCallCount); // Once for the setDirection and once for the reset north } @@ -111,6 +103,8 @@ - (void)testSetCenterCoordinateInDelegateMethod { XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + expectation.expectedFulfillmentCount = 2; + expectation.assertForOverFulfill = YES; __weak typeof(self) weakself = self; __block NSInteger delegateCallCount = 0; @@ -177,15 +171,12 @@ delegateCallCount++; - [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; - [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:0.5]; + [expectation fulfill]; }; // Should take MGLAnimationDuration seconds (0.3) [self.mapView setCenterCoordinate:target zoomLevel:15.0 animated:YES]; [self waitForExpectations:@[expectation] timeout:1.5]; - - XCTAssert(delegateCallCount == 2, @"Expecting 2 regionDidChange callbacks, got %ld", delegateCallCount); // Once for the setDirection and once for the reset north } - (void)testFlyToCameraInDelegateMethod { @@ -194,6 +185,8 @@ __weak typeof(self) weakself = self; __block NSInteger delegateCallCount = 0; + expectation.expectedFulfillmentCount = 3; + expectation.assertForOverFulfill = YES; CLLocationCoordinate2D target = CLLocationCoordinate2DMake(40.0, 40.0); CLLocationCoordinate2D target2 = CLLocationCoordinate2DMake(30.0, 30.0); @@ -277,6 +270,8 @@ } delegateCallCount++; + + [expectation fulfill]; }; // Should take MGLAnimationDuration diff --git a/platform/ios/Integration Tests/MGLShapeSourceTests.m b/platform/ios/Integration Tests/MGLShapeSourceTests.m index 7eb7c453cc..088a9b011e 100644 --- a/platform/ios/Integration Tests/MGLShapeSourceTests.m +++ b/platform/ios/Integration Tests/MGLShapeSourceTests.m @@ -36,6 +36,8 @@ [self.style addLayer:layer]; XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + expectation.expectedFulfillmentCount = 1; + expectation.assertForOverFulfill = YES; __weak typeof(self) weakself = self; __block NSInteger delegateCallCount = 0; @@ -62,8 +64,7 @@ shapeSource.shape = nil; } - [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; - [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:0.5]; + [expectation fulfill]; }; // setCenterCoordinate is NOT animated here. @@ -94,6 +95,8 @@ [self.style addLayer:layer]; XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + expectation.expectedFulfillmentCount = 1; + expectation.assertForOverFulfill = YES; __block NSInteger delegateCallCount = 0; __weak typeof(self) weakself = self; @@ -111,8 +114,7 @@ MGLTestFail(weakself); } - [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; - [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:0.5]; + [expectation fulfill]; }; // Should take MGLAnimationDuration seconds (0.3) diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 0b3db6becb..8aa145efa2 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -13,6 +13,7 @@ ### Other changes * Unknown tokens in URLs are now preserved, rather than replaced with an empty string. ([#11787](https://github.com/mapbox/mapbox-gl-native/issues/11787)) +* Adjusted when and how the camera transition update and finish callbacks are called, fixing recursion bugs. ([#5833](https://github.com/mapbox/mapbox-gl-native/issues/5833), [#11180](https://github.com/mapbox/mapbox-gl-native/issues/11180)) ## 0.7.1 |