diff options
author | Jason Wray <jason@mapbox.com> | 2019-07-12 13:34:09 -0700 |
---|---|---|
committer | Jason Wray <friedbunny@users.noreply.github.com> | 2019-07-17 12:38:15 -0700 |
commit | 4e1ba601b3028cccfa3ca3d5bec986eee9f24b02 (patch) | |
tree | 77fd833f334f6db52547d2343cde6e3c7216beab /platform/ios/test | |
parent | 3ced4a943b38cff8ae1d3cebf7968b2844de565d (diff) | |
download | qtlocation-mapboxgl-4e1ba601b3028cccfa3ca3d5bec986eee9f24b02.tar.gz |
[ios] Clean-up direction and compass tests
Diffstat (limited to 'platform/ios/test')
-rw-r--r-- | platform/ios/test/MGLMapViewCompassViewTests.mm (renamed from platform/ios/test/MGLCompassButtonTests.m) | 26 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewDirectionTests.mm | 77 |
2 files changed, 52 insertions, 51 deletions
diff --git a/platform/ios/test/MGLCompassButtonTests.m b/platform/ios/test/MGLMapViewCompassViewTests.mm index f41de0a2e2..aaec4b0bf7 100644 --- a/platform/ios/test/MGLCompassButtonTests.m +++ b/platform/ios/test/MGLMapViewCompassViewTests.mm @@ -1,18 +1,14 @@ #import <Mapbox/Mapbox.h> #import <XCTest/XCTest.h> -#import "../../ios/src/MGLCompassButton_Private.h" +#import <mbgl/math/wrap.hpp> @interface MGLMapView (MGLCompassButtonTests) - - (void)resetNorthAnimated:(BOOL)animated; - @end @interface MGLCompassButtonTests : XCTestCase - @property (nonatomic) MGLMapView *mapView; - @end @implementation MGLCompassButtonTests @@ -34,8 +30,9 @@ - (void)testCompassButton { XCTAssertNotNil(self.mapView.compassView); + XCTAssertTrue([self.mapView.compassView isKindOfClass:[MGLCompassButton class]]); XCTAssertTrue(self.mapView.compassView.userInteractionEnabled); - XCTAssertEqual(self.mapView.compassView.gestureRecognizers.count, 1); + XCTAssertEqual(self.mapView.compassView.gestureRecognizers.count, (unsigned long)1); XCTAssertEqual(self.mapView.compassView.accessibilityTraits, UIAccessibilityTraitButton); XCTAssertNotNil(self.mapView.compassView.accessibilityLabel); XCTAssertNotNil(self.mapView.compassView.accessibilityHint); @@ -81,4 +78,21 @@ XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should continue to be visible when direction is north."); } +- (void)testCompassRotation { + self.mapView.zoomLevel = 15; + + for (NSNumber *degrees in @[@-999, @-359, @-240, @-180, @-90, @-45, @0, @45, @90, @180, @240, @360, @999]) { + self.mapView.direction = [degrees doubleValue]; + CGFloat wrappedDirection = mbgl::util::wrap(-self.mapView.direction, 0., 360.); + CGAffineTransform rotation = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(wrappedDirection)); + XCTAssertTrue(CGAffineTransformEqualToTransform(self.mapView.compassView.transform, rotation), + @"Compass transform direction %f° should equal wrapped transform direction %f° (~%.f°).", [self degreesFromAffineTransform:self.mapView.compassView.transform], [self degreesFromAffineTransform:rotation], wrappedDirection); + } +} + +- (CGFloat)degreesFromAffineTransform:(CGAffineTransform)transform { + CGFloat angle = atan2f(transform.b, transform.a); + return MGLDegreesFromRadians(angle); +} + @end diff --git a/platform/ios/test/MGLMapViewDirectionTests.mm b/platform/ios/test/MGLMapViewDirectionTests.mm index d3990b581b..ef29b4227e 100644 --- a/platform/ios/test/MGLMapViewDirectionTests.mm +++ b/platform/ios/test/MGLMapViewDirectionTests.mm @@ -3,8 +3,6 @@ #import <mbgl/math/wrap.hpp> -static MGLMapView *mapView; - @interface MGLMapView (MGLMapViewDirectionTests) - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate; - (void)resetNorthAnimated:(BOOL)animated; @@ -15,6 +13,7 @@ static MGLMapView *mapView; @end @interface MGLMapViewDirectionTests : XCTestCase +@property (nonatomic) MGLMapView *mapView; @end @implementation MGLMapViewDirectionTests @@ -24,35 +23,35 @@ static MGLMapView *mapView; [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 64, 64) styleURL:styleURL]; + self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 64, 64) styleURL:styleURL]; } - (void)tearDown { - mapView = nil; + self.mapView = nil; [MGLAccountManager setAccessToken:nil]; [super tearDown]; } - (void)testDirection { - mapView.zoomLevel = 0; - mapView.direction = 30; - XCTAssertEqual(mapView.direction, 0, @"Rotation is not allowed at world-scale zoom levels."); + self.mapView.zoomLevel = 0; + self.mapView.direction = 30; + XCTAssertEqual(self.mapView.direction, 0, @"Rotation is not allowed at world-scale zoom levels."); - mapView.zoomLevel = 15; + self.mapView.zoomLevel = 15; for (NSNumber *degrees in @[@-999, @-359, @-240, @-180, @-90, @-45, @0, @45, @90, @180, @240, @360, @999]) { double inputDegrees = [degrees doubleValue]; double wrappedDegrees = mbgl::util::wrap(inputDegrees, 0., 360.); - mapView.direction = inputDegrees; - XCTAssertEqualWithAccuracy(mapView.direction, wrappedDegrees, 0.001); + self.mapView.direction = inputDegrees; + XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedDegrees, 0.001); } - [mapView resetNorthAnimated:NO]; - XCTAssertEqual(mapView.direction, 0, @"Reset-to-north should set direction to 0°."); + [self.mapView resetNorthAnimated:NO]; + XCTAssertEqual(self.mapView.direction, 0, @"Reset-to-north should set direction to 0°."); } - (void)testRotateEnabled { - mapView.zoomLevel = 10; + self.mapView.zoomLevel = 10; UIRotationGestureRecognizer *gesture = [[UIRotationGestureRecognizer alloc] initWithTarget:nil action:nil]; gesture.state = UIGestureRecognizerStateBegan; @@ -61,63 +60,51 @@ static MGLMapView *mapView; // Disabled { - mapView.rotateEnabled = NO; - XCTAssertEqual(mapView.allowsRotating, NO); + self.mapView.rotateEnabled = NO; + XCTAssertEqual(self.mapView.allowsRotating, NO); - [mapView handleRotateGesture:gesture]; - XCTAssertNotEqual(mapView.direction, wrappedRotation, @"Gestural rotation should not work when rotation is disabled."); + [self.mapView handleRotateGesture:gesture]; + XCTAssertNotEqual(self.mapView.direction, wrappedRotation, @"Gestural rotation should not work when rotation is disabled."); - mapView.direction = 45.f; - XCTAssertEqualWithAccuracy(mapView.direction, 45, 0.001, @"Programmatic rotation is allowed when rotateEnabled = NO."); + self.mapView.direction = 45.f; + XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001, @"Programmatic rotation is allowed when rotateEnabled = NO."); } // Enabled { - [mapView resetNorthAnimated:NO]; - mapView.rotateEnabled = YES; - XCTAssertEqual(mapView.allowsRotating, YES); + [self.mapView resetNorthAnimated:NO]; + self.mapView.rotateEnabled = YES; + XCTAssertEqual(self.mapView.allowsRotating, YES); gesture.state = UIGestureRecognizerStateChanged; gesture.rotation = MGLRadiansFromDegrees(30); - [mapView handleRotateGesture:gesture]; - XCTAssertEqualWithAccuracy(mapView.direction, wrappedRotation, 0.001, @"Gestural rotation should work when rotation is enabled."); + [self.mapView handleRotateGesture:gesture]; + XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedRotation, 0.001, @"Gestural rotation should work when rotation is enabled."); } } -- (void)testRotateGesture { - mapView.zoomLevel = 15; +- (void)testRotationGesture { + self.mapView.zoomLevel = 15; UIRotationGestureRecognizer *gesture = [[UIRotationGestureRecognizer alloc] initWithTarget:nil action:nil]; gesture.state = UIGestureRecognizerStateBegan; gesture.rotation = 0; - [mapView handleRotateGesture:gesture]; - XCTAssertEqual(mapView.direction, gesture.rotation); + [self.mapView handleRotateGesture:gesture]; + XCTAssertEqual(self.mapView.direction, gesture.rotation); for (NSNumber *degrees in @[@-999, @-360, @-240, @-180, @-90, @-45, @0, @45, @90, @180, @240, @359, @999]) { gesture.state = UIGestureRecognizerStateChanged; gesture.rotation = MGLRadiansFromDegrees([degrees doubleValue]); - [mapView handleRotateGesture:gesture]; + [self.mapView handleRotateGesture:gesture]; CGFloat wrappedRotation = mbgl::util::wrap(-MGLDegreesFromRadians(gesture.rotation), 0., 360.); - XCTAssertEqualWithAccuracy(mapView.direction, wrappedRotation, 0.001, @"Map direction should match gesture rotation for input of %@°.", degrees); - } -} - -- (void)testCompassRotation { - mapView.zoomLevel = 15; - - for (NSNumber *degrees in @[@-999, @-359, @-240, @-180, @-90, @-45, @0, @45, @90, @180, @240, @360, @999]) { - mapView.direction = [degrees doubleValue]; - CGFloat wrappedDirection = mbgl::util::wrap(-mapView.direction, 0., 360.); - CGAffineTransform rotation = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(wrappedDirection)); - XCTAssertTrue(CGAffineTransformEqualToTransform(mapView.compassView.transform, rotation), - @"Compass transform direction %f° should equal wrapped transform direction %f° (~%.f°).", [self degreesFromAffineTransform:mapView.compassView.transform], [self degreesFromAffineTransform:rotation], wrappedDirection); + XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedRotation, 0.001, @"Map direction should match gesture rotation for input of %@°.", degrees); } } - (void)testResetPosition { - [mapView resetPosition]; - MGLMapCamera *defaultCamera = [MGLMapCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(0, 0) altitude:mapView.camera.altitude pitch:0 heading:0]; - XCTAssertTrue([mapView.camera isEqualToMapCamera:defaultCamera], @"Map camera %@ should be equal to default camera %@.", mapView.camera, defaultCamera); + [self.mapView resetPosition]; + MGLMapCamera *defaultCamera = [MGLMapCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(0, 0) altitude:self.mapView.camera.altitude pitch:0 heading:0]; + XCTAssertTrue([self.mapView.camera isEqualToMapCamera:defaultCamera], @"Map camera %@ should be equal to default camera %@.", self.mapView.camera, defaultCamera); } - (CGFloat)degreesFromAffineTransform:(CGAffineTransform)transform { |