diff options
Diffstat (limited to 'platform/ios/test')
-rw-r--r-- | platform/ios/test/MGLMapViewDirectionTests.mm | 7 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewZoomTests.mm (renamed from platform/ios/test/MGLMapViewZoomTests.m) | 68 | ||||
-rw-r--r-- | platform/ios/test/MGLMockGestureRecognizers.h | 10 | ||||
-rw-r--r-- | platform/ios/test/MGLMockGestureRecognizers.m | 11 |
4 files changed, 82 insertions, 14 deletions
diff --git a/platform/ios/test/MGLMapViewDirectionTests.mm b/platform/ios/test/MGLMapViewDirectionTests.mm index 8a724a06bc..81e169432b 100644 --- a/platform/ios/test/MGLMapViewDirectionTests.mm +++ b/platform/ios/test/MGLMapViewDirectionTests.mm @@ -1,5 +1,6 @@ #import <Mapbox/Mapbox.h> #import <XCTest/XCTest.h> +#import "MGLMockGestureRecognizers.h" #import <mbgl/math/wrap.hpp> @@ -8,12 +9,6 @@ - (void)resetNorthAnimated:(BOOL)animated; @end -@interface UIRotationGestureRecognizerMock : UIRotationGestureRecognizer -@end - -@implementation UIRotationGestureRecognizerMock -- (CGPoint)locationInView:(nullable UIView*)view { return view.center; } -@end @interface MGLMapViewDirectionTests : XCTestCase @property (nonatomic) MGLMapView *mapView; diff --git a/platform/ios/test/MGLMapViewZoomTests.m b/platform/ios/test/MGLMapViewZoomTests.mm index bd617857fd..360af72d02 100644 --- a/platform/ios/test/MGLMapViewZoomTests.m +++ b/platform/ios/test/MGLMapViewZoomTests.mm @@ -1,16 +1,14 @@ #import <Mapbox/Mapbox.h> #import <XCTest/XCTest.h> +#import "MGLMockGestureRecognizers.h" + +#import <mbgl/math/wrap.hpp> @interface MGLMapView (MGLMapViewZoomTests) +@property (nonatomic) BOOL isZooming; +@property (nonatomic) CGFloat rotationThresholdWhileZooming; - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch; -@end - -@interface UIPinchGestureRecognizerMock : UIPinchGestureRecognizer -@property (nonatomic) CGPoint locationInViewOverride; -@end - -@implementation UIPinchGestureRecognizerMock -- (CGPoint)locationInView:(nullable UIView *)view { return self.locationInViewOverride; } +- (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate; @end @interface MGLMapViewZoomTests : XCTestCase @@ -129,6 +127,60 @@ XCTAssertEqualWithAccuracy(centerCoordinateBeforeReset.longitude, self.mapView.centerCoordinate.longitude, 0.0000001, @"Map center coordinate longitude should remain constant after resetting to north."); } +- (void)testPinchAndZoom { + + [[NSUserDefaults standardUserDefaults] setObject:@3 forKey:@"MGLRotationThresholdWhileZooming"]; + self.mapView.rotationThresholdWhileZooming = 3; + self.mapView.zoomLevel = 15; + UIPinchGestureRecognizerMock *pinch = [[UIPinchGestureRecognizerMock alloc] initWithTarget:self.mapView action:nil]; + [self.mapView addGestureRecognizer:pinch]; + pinch.state = UIGestureRecognizerStateBegan; + pinch.velocity = 5.0; + pinch.locationInViewOverride = CGPointMake(0, 0); + [self.mapView handlePinchGesture:pinch]; + + XCTAssertTrue(self.mapView.isZooming); + + UIRotationGestureRecognizerMock *rotate = [[UIRotationGestureRecognizerMock alloc] initWithTarget:self.mapView action:nil]; + rotate.state = UIGestureRecognizerStateBegan; + rotate.rotation = MGLRadiansFromDegrees(1); + [self.mapView addGestureRecognizer:rotate]; + [self.mapView handleRotateGesture:rotate]; + + // Both the rotation and direction should be zero since the rotation threshold hasn't been met. + XCTAssertEqual(rotate.rotation, 0); + XCTAssertEqual(self.mapView.direction, 0); + + // The direction should be `0`. The default rotation threshold is `3`. + XCTAssertEqual(self.mapView.direction, 0); + rotate.state = UIGestureRecognizerStateChanged; + rotate.rotation = MGLRadiansFromDegrees(2); + [self.mapView handleRotateGesture:rotate]; + + // The direction should be `0`. The default rotation threshold is `3`. + XCTAssertEqual(self.mapView.direction, 0); + + for (NSNumber *degrees in @[@-90, @-10, @10, @10, @30, @90, @180, @240, @460, @500, @590, @800]) { + rotate.state = UIGestureRecognizerStateChanged; + rotate.rotation = MGLRadiansFromDegrees([degrees doubleValue]); + [self.mapView handleRotateGesture:rotate]; + + CGFloat wrappedRotation = mbgl::util::wrap(-MGLDegreesFromRadians(rotate.rotation), 0., 360.); + + + // Check that the direction property now matches the gesture's rotation. + XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedRotation, 0.001, @"Map direction should match gesture rotation for input of %@°.", degrees); + } + + rotate.state = UIGestureRecognizerStateEnded; + pinch.state = UIGestureRecognizerStateEnded; + + [self.mapView handleRotateGesture:rotate]; + [self.mapView handlePinchGesture:pinch]; + + XCTAssertFalse(self.mapView.isZooming); +} + NS_INLINE CGFloat MGLScaleFromZoomLevel(double zoom) { return pow(2, zoom); } diff --git a/platform/ios/test/MGLMockGestureRecognizers.h b/platform/ios/test/MGLMockGestureRecognizers.h new file mode 100644 index 0000000000..aa5fbec494 --- /dev/null +++ b/platform/ios/test/MGLMockGestureRecognizers.h @@ -0,0 +1,10 @@ + +#import <UIKit/UIKit.h> + +@interface UIPinchGestureRecognizerMock : UIPinchGestureRecognizer +@property (nonatomic, readwrite) CGFloat velocity; +@property (nonatomic) CGPoint locationInViewOverride; +@end + +@interface UIRotationGestureRecognizerMock : UIRotationGestureRecognizer +@end diff --git a/platform/ios/test/MGLMockGestureRecognizers.m b/platform/ios/test/MGLMockGestureRecognizers.m new file mode 100644 index 0000000000..89df6750a9 --- /dev/null +++ b/platform/ios/test/MGLMockGestureRecognizers.m @@ -0,0 +1,11 @@ + +#import "MGLMockGestureRecognizers.h" + +@implementation UIPinchGestureRecognizerMock +@synthesize velocity; +- (CGPoint)locationInView:(nullable UIView *)view { return self.locationInViewOverride; } +@end + +@implementation UIRotationGestureRecognizerMock +- (CGPoint)locationInView:(nullable UIView*)view { return view.center; } +@end |