diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-04-16 23:46:24 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2018-05-21 13:05:04 -0400 |
commit | a73d2ad6c3f06eed638e0eb97e8d19b6cf15218e (patch) | |
tree | f0731d307dbca838fe9bf6dd151587c72863d709 | |
parent | ace5bb18a188d866ef4be7464c4d8f14cfdfd537 (diff) | |
download | qtlocation-mapboxgl-a73d2ad6c3f06eed638e0eb97e8d19b6cf15218e.tar.gz |
Add failing test for camera transition (reset north). Renaming of test classes.
-rw-r--r-- | platform/ios/Integration Tests/MGLCameraTransitionTests.m | 72 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MGLMapViewIntegrationTest.h | 8 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MGLMapViewIntegrationTest.m | 12 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MGLShapeSourceTests.m (renamed from platform/ios/Integration Tests/MBShapeSourceTests.m) | 14 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 12 |
5 files changed, 99 insertions, 19 deletions
diff --git a/platform/ios/Integration Tests/MGLCameraTransitionTests.m b/platform/ios/Integration Tests/MGLCameraTransitionTests.m new file mode 100644 index 0000000000..ef3cea608c --- /dev/null +++ b/platform/ios/Integration Tests/MGLCameraTransitionTests.m @@ -0,0 +1,72 @@ +#import "MGLMapViewIntegrationTest.h" + +@interface MBCameraTransitionTests : MGLMapViewIntegrationTest +@end + +@implementation MBCameraTransitionTests + +- (void)testSetAndResetNorthWithDispatchAsync { + + XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + + __weak typeof(self) weakself = self; + __block NSInteger delegateCallCount = 0; + + self.regionDidChange = ^(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated) { + + MBCameraTransitionTests *strongSelf = weakself; + + if (!strongSelf) return; + + delegateCallCount++; + + if (mapView.userTrackingMode != MGLUserTrackingModeFollowWithHeading && mapView.direction != 0.0) { + dispatch_async(dispatch_get_main_queue(), ^{ + [mapView resetNorth]; + }); + } + + [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; + [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:5.0]; + }; + + [self.mapView setDirection:90 animated:YES]; + + // loop, render, and wait + [self waitForExpectations:@[expectation] timeout:10.0]; + + XCTAssert(delegateCallCount == 2, @"Expecting 2 regionDidChange callbacks, got %ld", delegateCallCount); // Once for the setDirection and once for the reset north +} + + +- (void)testSetAndResetNorth { + + XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; + + __weak typeof(self) weakself = self; + __block NSInteger delegateCallCount = 0; + + self.regionDidChange = ^(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated) { + + MBCameraTransitionTests *strongSelf = weakself; + + if (!strongSelf) return; + + delegateCallCount++; + + if (mapView.userTrackingMode != MGLUserTrackingModeFollowWithHeading && mapView.direction != 0.0) { + NSLog(@"resetting north"); + [mapView resetNorth]; + } + + [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; + [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:5.0]; + }; + + [self.mapView setDirection:90 animated:YES]; + [self waitForExpectations:@[expectation] timeout:10.0]; + + XCTAssert(delegateCallCount == 2, @"delegateCallCount = %ld", delegateCallCount); // Once for the setDirection and once for the reset north +} + +@end diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h index ab5d2cc46f..177a1622a4 100644 --- a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h +++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h @@ -4,15 +4,17 @@ #define TestFailWithSelf(myself, ...) \ _XCTPrimitiveFail(myself, __VA_ARGS__) +#define TestAssertWithSelf(expression, myself, ...) \ + _XCTPrimitiveAssertTrue(myself, expression, @#expression, __VA_ARGS__) + @interface MGLMapViewIntegrationTest : XCTestCase <MGLMapViewDelegate> @property (nonatomic) MGLMapView *mapView; @property (nonatomic) MGLStyle *style; @property (nonatomic) XCTestExpectation *styleLoadingExpectation; @property (nonatomic) XCTestExpectation *renderFinishedExpectation; -@property (nonatomic) void (^regionDidChange)(MGLMapView *mapView, BOOL animated); +@property (nonatomic) void (^regionWillChange)(MGLMapView *mapView, BOOL animated); @property (nonatomic) void (^regionIsChanging)(MGLMapView *mapView); - - +@property (nonatomic) void (^regionDidChange)(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated); // Utility methods - (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout; diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m index fc3229c83b..c42b8eef89 100644 --- a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m +++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m @@ -45,9 +45,9 @@ self.renderFinishedExpectation = nil; } -- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated { - if (self.regionDidChange) { - self.regionDidChange(mapView, animated); +- (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated { + if (self.regionWillChange) { + self.regionWillChange(mapView, animated); } } @@ -57,6 +57,12 @@ } } +- (void)mapView:(MGLMapView *)mapView regionDidChangeWithReason:(MGLCameraChangeReason)reason animated:(BOOL)animated { + if (self.regionDidChange) { + self.regionDidChange(mapView, reason, animated); + } +} + #pragma mark - Utilities - (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout { diff --git a/platform/ios/Integration Tests/MBShapeSourceTests.m b/platform/ios/Integration Tests/MGLShapeSourceTests.m index 6a5c2942e4..7df697ab32 100644 --- a/platform/ios/Integration Tests/MBShapeSourceTests.m +++ b/platform/ios/Integration Tests/MGLShapeSourceTests.m @@ -8,10 +8,10 @@ #import "MGLMapViewIntegrationTest.h" -@interface MBShapeSourceTests : MGLMapViewIntegrationTest +@interface MGLShapeSourceTests : MGLMapViewIntegrationTest @end -@implementation MBShapeSourceTests +@implementation MGLShapeSourceTests - (void)testSettingShapeSourceToNilInRegionDidChange { @@ -40,9 +40,9 @@ __weak typeof(self) weakself = self; __block NSInteger delegateCallCount = 0; - self.regionDidChange = ^(MGLMapView *mapView, BOOL animated) { + self.regionDidChange = ^(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated) { - MBShapeSourceTests *strongSelf = weakself; + MGLShapeSourceTests *strongSelf = weakself; if (!strongSelf) return; @@ -98,15 +98,11 @@ __weak typeof(self) weakself = self; self.regionIsChanging = ^(MGLMapView *mapView) { - // Setting the shapeSource.shape = nil, was causing an infinite loop, so here - // we check for a runaway call. 10 here is arbitrary. We could argue that this - // should check that the call count is only 1, however in this case we particularly - // want to check for the infinite loop. // See https://github.com/mapbox/mapbox-gl-native/issues/11180 shapeSource.shape = nil; }; - self.regionDidChange = ^(MGLMapView *mapView, BOOL animated) { + self.regionDidChange = ^(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated) { delegateCallCount++; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 20da765986..ad7bc29e8f 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -363,9 +363,10 @@ AC518E00201BB55A00EBC820 /* MGLTelemetryConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */; }; AC518E03201BB56000EBC820 /* MGLTelemetryConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */; }; AC518E04201BB56100EBC820 /* MGLTelemetryConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */; }; - CA0C27922076C804001CE5B7 /* MBShapeSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C27912076C804001CE5B7 /* MBShapeSourceTests.m */; }; + CA0C27922076C804001CE5B7 /* MGLShapeSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C27912076C804001CE5B7 /* MGLShapeSourceTests.m */; }; CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */; }; CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */; }; + CA34C9C3207FD272005C1A06 /* MGLCameraTransitionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA34C9C2207FD272005C1A06 /* MGLCameraTransitionTests.m */; }; CA55CD41202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; }; CA55CD42202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; }; CAA69DA4206DCD0E007279CD /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA4A26961CB6E795000B7809 /* Mapbox.framework */; }; @@ -997,10 +998,11 @@ 96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationHeadingIndicator.h; sourceTree = "<group>"; }; AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLTelemetryConfig.h; sourceTree = "<group>"; }; AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLTelemetryConfig.m; sourceTree = "<group>"; }; - CA0C27912076C804001CE5B7 /* MBShapeSourceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBShapeSourceTests.m; sourceTree = "<group>"; }; + CA0C27912076C804001CE5B7 /* MGLShapeSourceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLShapeSourceTests.m; sourceTree = "<group>"; }; CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewIntegrationTest.m; sourceTree = "<group>"; }; CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLMapViewIntegrationTest.h; sourceTree = "<group>"; }; CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLStyleLayerIntegrationTests.m; sourceTree = "<group>"; }; + CA34C9C2207FD272005C1A06 /* MGLCameraTransitionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLCameraTransitionTests.m; sourceTree = "<group>"; }; CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCameraChangeReason.h; sourceTree = "<group>"; }; DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; }; DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; }; @@ -1355,7 +1357,8 @@ children = ( 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.m */, 16376B0B1FFD9DAF0000563E /* Info.plist */, - CA0C27912076C804001CE5B7 /* MBShapeSourceTests.m */, + CA34C9C2207FD272005C1A06 /* MGLCameraTransitionTests.m */, + CA0C27912076C804001CE5B7 /* MGLShapeSourceTests.m */, CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */, CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */, CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */, @@ -2812,9 +2815,10 @@ buildActionMask = 2147483647; files = ( CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */, + CA34C9C3207FD272005C1A06 /* MGLCameraTransitionTests.m in Sources */, 16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */, CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */, - CA0C27922076C804001CE5B7 /* MBShapeSourceTests.m in Sources */, + CA0C27922076C804001CE5B7 /* MGLShapeSourceTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |