diff options
Diffstat (limited to 'platform/ios/test')
18 files changed, 0 insertions, 2131 deletions
diff --git a/platform/ios/test/Info.plist b/platform/ios/test/Info.plist deleted file mode 100644 index ba72822e87..0000000000 --- a/platform/ios/test/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleDevelopmentRegion</key> - <string>en</string> - <key>CFBundleExecutable</key> - <string>$(EXECUTABLE_NAME)</string> - <key>CFBundleIdentifier</key> - <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundleName</key> - <string>$(PRODUCT_NAME)</string> - <key>CFBundlePackageType</key> - <string>BNDL</string> - <key>CFBundleShortVersionString</key> - <string>1.0</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>1</string> -</dict> -</plist> diff --git a/platform/ios/test/MGLAccountManagerTests.m b/platform/ios/test/MGLAccountManagerTests.m deleted file mode 100644 index fd59de2fd5..0000000000 --- a/platform/ios/test/MGLAccountManagerTests.m +++ /dev/null @@ -1,25 +0,0 @@ -#import <XCTest/XCTest.h> -#import <Mapbox/Mapbox.h> - -@interface MBXAccounts: NSObject -@property (class, nonatomic, readonly) NSString *skuToken; -@end - -@implementation MBXAccounts - -+ (NSString *)skuToken { - return @"foo"; -} - -@end - -@interface MGLAccountManagerTests : XCTestCase -@end - -@implementation MGLAccountManagerTests - -- (void)testSKU { - XCTAssertTrue([[MGLAccountManager valueForKeyPath:@"skuToken"] isEqualToString:@"foo"]); -} - -@end diff --git a/platform/ios/test/MGLAnnotationViewIntegrationTests.swift b/platform/ios/test/MGLAnnotationViewIntegrationTests.swift deleted file mode 100644 index 82a57a4009..0000000000 --- a/platform/ios/test/MGLAnnotationViewIntegrationTests.swift +++ /dev/null @@ -1,23 +0,0 @@ -import XCTest -import Mapbox - -class CustomAnnotationView: MGLAnnotationView { - - override init(reuseIdentifier: String?) { - super.init(reuseIdentifier: reuseIdentifier) - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - -} - -class MGLAnnotationViewIntegrationTests: XCTestCase { - - func testCreatingCustomAnnotationView() { - let customAnnotationView = CustomAnnotationView(reuseIdentifier: "resuse-id") - XCTAssertNotNil(customAnnotationView) - } - -} diff --git a/platform/ios/test/MGLAnnotationViewTests.m b/platform/ios/test/MGLAnnotationViewTests.m deleted file mode 100644 index bb85ea8c8a..0000000000 --- a/platform/ios/test/MGLAnnotationViewTests.m +++ /dev/null @@ -1,273 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> -#import "MGLTestUtility.h" - -static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer"; - - -@interface MGLMapView (Tests) -@property (nonatomic) MGLCameraChangeReason cameraChangeReasonBitmask; -@end - - - -@interface MGLCustomAnnotationView : MGLAnnotationView - -@end - -@implementation MGLCustomAnnotationView - -- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier { - return [super initWithReuseIdentifier:@"reuse-id"]; -} - -@end - -@interface MGLAnnotationView (Test) - -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic, readwrite) MGLAnnotationViewDragState dragState; -- (void)setDragState:(MGLAnnotationViewDragState)dragState; - -@end - -@interface MGLMapView (Test) -@property (nonatomic) UIView<MGLCalloutView> *calloutViewForSelectedAnnotation; -@end - -@interface MGLTestAnnotation : NSObject <MGLAnnotation> -@property (nonatomic, assign) CLLocationCoordinate2D coordinate; -@end - -@implementation MGLTestAnnotation -@end - -@interface MGLTestCalloutView: UIView<MGLCalloutView> -@property (nonatomic) BOOL didCallDismissCalloutAnimated; -@property (nonatomic, strong) id <MGLAnnotation> representedObject; -@property (nonatomic, strong) UIView *leftAccessoryView; -@property (nonatomic, strong) UIView *rightAccessoryView; -@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate; -@end - -@implementation MGLTestCalloutView - -- (void)dismissCalloutAnimated:(BOOL)animated -{ - _didCallDismissCalloutAnimated = YES; -} - -- (void)presentCalloutFromRect:(CGRect)rect inView:(nonnull UIView *)view constrainedToRect:(CGRect)constrainedRect animated:(BOOL)animated {} - -@end - -@interface MGLAnnotationViewTests : XCTestCase <MGLMapViewDelegate> -@property (nonatomic) XCTestExpectation *expectation; -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic, weak) MGLAnnotationView *annotationView; -@property (nonatomic) NSInteger annotationSelectedCount; -@property (nonatomic) void (^prepareAnnotationView)(MGLAnnotationView*); -@end - -@implementation MGLAnnotationViewTests - -- (void)setUp -{ - [super setUp]; - _mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)]; - _mapView.delegate = self; -} - -- (void)testAnnotationView -{ - _expectation = [self expectationWithDescription:@"annotation property"]; - - MGLTestAnnotation *annotation = [[MGLTestAnnotation alloc] init]; - [_mapView addAnnotation:annotation]; - - [self waitForExpectationsWithTimeout:5 handler:nil]; - - XCTAssert(_mapView.annotations.count == 1, @"number of annotations should be 1"); - XCTAssertNotNil(_annotationView.annotation, @"annotation property should not be nil"); - XCTAssertNotNil(_annotationView.mapView, @"mapView property should not be nil"); - - MGLTestCalloutView *testCalloutView = [[MGLTestCalloutView alloc] init]; - _mapView.calloutViewForSelectedAnnotation = testCalloutView; - _annotationView.dragState = MGLAnnotationViewDragStateStarting; - XCTAssertTrue(testCalloutView.didCallDismissCalloutAnimated, @"callout view was not dismissed"); - - [_mapView removeAnnotation:_annotationView.annotation]; - - XCTAssert(_mapView.annotations.count == 0, @"number of annotations should be 0"); - XCTAssertNil(_annotationView.annotation, @"annotation property should be nil"); -} - -- (void)testCustomAnnotationView -{ - MGLCustomAnnotationView *customAnnotationView = [[MGLCustomAnnotationView alloc] initWithReuseIdentifier:@"reuse-id"]; - XCTAssertNotNil(customAnnotationView); -} - -- (void)testSelectingOffscreenAnnotation -{ - // Partial test for https://github.com/mapbox/mapbox-gl-native/issues/9790 - - // This isn't quite the same as in updateAnnotationViews, but should be sufficient for this test. - MGLCoordinateBounds coordinateBounds = [_mapView convertRect:_mapView.bounds toCoordinateBoundsFromView:_mapView]; - - // -90 latitude is invalid. TBD. - BOOL anyOffscreen = NO; - NSInteger selectionCount = 0; - - for (NSInteger latitude = -89; latitude <= 90; latitude += 10) - { - for (NSInteger longitude = -180; longitude <= 180; longitude += 10) - { - MGLTestAnnotation *annotation = [[MGLTestAnnotation alloc] init]; - - annotation.coordinate = CLLocationCoordinate2DMake(latitude, longitude); - [_mapView addAnnotation:annotation]; - - if (!(MGLCoordinateInCoordinateBounds(annotation.coordinate, coordinateBounds))) - anyOffscreen = YES; - - XCTAssertNil(_mapView.selectedAnnotations.firstObject, @"There should be no selected annotation"); - - // First selection - [_mapView selectAnnotation:annotation animated:NO completionHandler:nil]; - selectionCount++; - - XCTAssert(_mapView.selectedAnnotations.count == 1, @"There should only be 1 selected annotation"); - XCTAssertEqualObjects(_mapView.selectedAnnotations.firstObject, annotation, @"The annotation should be selected"); - - // Deselect - [_mapView deselectAnnotation:annotation animated:NO]; - XCTAssert(_mapView.selectedAnnotations.count == 0, @"There should be no selected annotations"); - - // Second selection - _mapView.selectedAnnotations = @[annotation]; - selectionCount++; - - XCTAssert(_mapView.selectedAnnotations.count == 1, @"There should be 1 selected annotation"); - XCTAssertEqualObjects(_mapView.selectedAnnotations.firstObject, annotation, @"The annotation should be selected"); - - // Deselect - [_mapView deselectAnnotation:annotation animated:NO]; - XCTAssert(_mapView.selectedAnnotations.count == 0, @"There should be no selected annotations"); - } - } - - XCTAssert(anyOffscreen, @"At least one of these annotations should be offscreen"); - XCTAssertEqual(selectionCount, self.annotationSelectedCount, @"-mapView:didSelectAnnotation: should be called for each selection"); -} - -- (void)testSelectingOnscreenAnnotationThatHasNotBeenAdded { - // See https://github.com/mapbox/mapbox-gl-native/issues/11476 - - // This bug occurs under the following conditions: - // - // - There are content insets (e.g. navigation bar) for the compare against - // CGRectZero (now CGRectNull) - // - annotationView.enabled == NO - Currently this can happen if you use - // `-initWithFrame:` rather than one of the provided initializers - // - - self.prepareAnnotationView = ^(MGLAnnotationView *view) { - view.enabled = NO; - }; - - self.mapView.contentInset = UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0); - - MGLCameraChangeReason reasonBefore = self.mapView.cameraChangeReasonBitmask; - XCTAssert(reasonBefore == MGLCameraChangeReasonNone, @"Camera should not have moved at start of test"); - - // Create annotation - MGLPointFeature *point = [[MGLPointFeature alloc] init]; - point.title = NSStringFromSelector(_cmd); - point.coordinate = CLLocationCoordinate2DMake(0.0, 0.0); - - MGLCoordinateBounds coordinateBounds = [self.mapView convertRect:self.mapView.bounds toCoordinateBoundsFromView:self.mapView]; - XCTAssert(MGLCoordinateInCoordinateBounds(point.coordinate, coordinateBounds), @"The test point should be within the visible map view"); - - // Select on screen annotation (DO NOT ADD FIRST). - [self.mapView selectAnnotation:point animated:YES completionHandler:nil]; - - // Expect - the camera NOT to move. - MGLCameraChangeReason reasonAfter = self.mapView.cameraChangeReasonBitmask; - XCTAssert(reasonAfter == MGLCameraChangeReasonNone, @"Camera should not have moved"); -} - -- (void)checkDefaultPropertiesForAnnotationView:(MGLAnnotationView*)view { - XCTAssertNil(view.annotation); - XCTAssertNil(view.reuseIdentifier); - XCTAssertEqual(view.centerOffset.dx, 0.0); - XCTAssertEqual(view.centerOffset.dy, 0.0); - XCTAssertFalse(view.scalesWithViewingDistance); - XCTAssertFalse(view.rotatesToMatchCamera); - XCTAssertFalse(view.isSelected); - XCTAssert(view.isEnabled); - XCTAssertFalse(view.isDraggable); - XCTAssertEqual(view.dragState, MGLAnnotationViewDragStateNone); -} - -- (void)testAnnotationViewInitWithFramePENDING { - MGL_CHECK_IF_PENDING_TEST_SHOULD_RUN(); - CGRect frame = CGRectMake(10.0, 10.0, 100.0, 100.0); - MGLAnnotationView *view = [[MGLAnnotationView alloc] initWithFrame:frame]; - [self checkDefaultPropertiesForAnnotationView:view]; -} - -- (void)testAnnotationViewInitWithReuseIdentifier { - MGLAnnotationView *view = [[MGLAnnotationView alloc] initWithReuseIdentifier:nil]; - [self checkDefaultPropertiesForAnnotationView:view]; -} - -- (void)testSelectingADisabledAnnotationViewPENDING { - MGL_CHECK_IF_PENDING_TEST_SHOULD_RUN(); - self.prepareAnnotationView = ^(MGLAnnotationView *view) { - view.enabled = NO; - }; - - // Create annotation - MGLPointFeature *point = [[MGLPointFeature alloc] init]; - point.title = NSStringFromSelector(_cmd); - point.coordinate = CLLocationCoordinate2DMake(0.0, 0.0); - - XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations"); - - [self.mapView selectAnnotation:point animated:NO completionHandler:nil]; - - XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations"); -} - -#pragma mark - MGLMapViewDelegate - - -- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation -{ - MGLAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:MGLTestAnnotationReuseIdentifer]; - - if (!annotationView) - { - annotationView = [[MGLAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MGLTestAnnotationReuseIdentifer]; - } - - if (self.prepareAnnotationView) { - self.prepareAnnotationView(annotationView); - } - - _annotationView = annotationView; - - return annotationView; -} - -- (void)mapView:(MGLMapView *)mapView didAddAnnotationViews:(NSArray<MGLAnnotationView *> *)annotationViews -{ - [_expectation fulfill]; -} - -- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation -{ - self.annotationSelectedCount++; -} - -@end diff --git a/platform/ios/test/MGLMapAccessibilityElementTests.m b/platform/ios/test/MGLMapAccessibilityElementTests.m deleted file mode 100644 index 916461e708..0000000000 --- a/platform/ios/test/MGLMapAccessibilityElementTests.m +++ /dev/null @@ -1,87 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> - -#import "../../ios/src/MGLMapAccessibilityElement.h" - -@interface MGLMapAccessibilityElementTests : XCTestCase -@end - -@implementation MGLMapAccessibilityElementTests - -- (void)testFeatureLabels { - MGLPointFeature *feature = [[MGLPointFeature alloc] init]; - feature.attributes = @{ - @"name": @"Local", - @"name_en": @"English", - @"name_es": @"Spanish", - @"name_fr": @"French", - @"name_tlh": @"Klingon", - }; - MGLFeatureAccessibilityElement *element = [[MGLFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; - XCTAssertEqualObjects(element.accessibilityLabel, @"English", @"Accessibility label should be localized."); - - feature.attributes = @{ - @"name": @"Цинциннати", - @"name_en": @"Цинциннати", - }; - element = [[MGLFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; - XCTAssertEqualObjects(element.accessibilityLabel, @"Cincinnati", @"Accessibility label should be romanized."); -} - -- (void)testPlaceFeatureValues { - MGLPointFeature *feature = [[MGLPointFeature alloc] init]; - feature.attributes = @{ - @"type": @"village_green", - }; - MGLPlaceFeatureAccessibilityElement *element = [[MGLPlaceFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; - XCTAssertEqualObjects(element.accessibilityValue, @"village green"); - - feature = [[MGLPointFeature alloc] init]; - feature.attributes = @{ - @"maki": @"cat", - }; - element = [[MGLPlaceFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; - XCTAssertEqualObjects(element.accessibilityValue, @"cat"); - - feature = [[MGLPointFeature alloc] init]; - feature.attributes = @{ - @"elevation_ft": @31337, - @"elevation_m": @1337, - }; - element = [[MGLPlaceFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; - XCTAssertEqualObjects(element.accessibilityValue, @"31,337 feet"); -} - -- (void)testRoadFeatureValues { - CLLocationCoordinate2D coordinates[] = { - CLLocationCoordinate2DMake(0, 0), - CLLocationCoordinate2DMake(0, 1), - CLLocationCoordinate2DMake(1, 2), - CLLocationCoordinate2DMake(2, 2), - }; - MGLPolylineFeature *roadFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates count:sizeof(coordinates) / sizeof(coordinates[0])]; - roadFeature.attributes = @{ - @"ref": @"42", - @"oneway": @"true", - }; - MGLRoadFeatureAccessibilityElement *element = [[MGLRoadFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:roadFeature]; - XCTAssertEqualObjects(element.accessibilityValue, @"Route 42, One way, southwest to northeast"); - - CLLocationCoordinate2D opposingCoordinates[] = { - CLLocationCoordinate2DMake(2, 1), - CLLocationCoordinate2DMake(1, 0), - }; - MGLPolylineFeature *opposingRoadFeature = [MGLPolylineFeature polylineWithCoordinates:opposingCoordinates count:sizeof(opposingCoordinates) / sizeof(opposingCoordinates[0])]; - opposingRoadFeature.attributes = @{ - @"ref": @"42", - @"oneway": @"true", - }; - MGLMultiPolylineFeature *dividedRoadFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[roadFeature, opposingRoadFeature]]; - dividedRoadFeature.attributes = @{ - @"ref": @"42", - }; - element = [[MGLRoadFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:dividedRoadFeature]; - XCTAssertEqualObjects(element.accessibilityValue, @"Route 42, Divided road, southwest to northeast"); -} - -@end diff --git a/platform/ios/test/MGLMapViewCompassViewTests.mm b/platform/ios/test/MGLMapViewCompassViewTests.mm deleted file mode 100644 index aaec4b0bf7..0000000000 --- a/platform/ios/test/MGLMapViewCompassViewTests.mm +++ /dev/null @@ -1,98 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> - -#import <mbgl/math/wrap.hpp> - -@interface MGLMapView (MGLCompassButtonTests) -- (void)resetNorthAnimated:(BOOL)animated; -@end - -@interface MGLCompassButtonTests : XCTestCase -@property (nonatomic) MGLMapView *mapView; -@end - -@implementation MGLCompassButtonTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; -} - -- (void)tearDown { - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - - [super tearDown]; -} - -- (void)testCompassButton { - XCTAssertNotNil(self.mapView.compassView); - XCTAssertTrue([self.mapView.compassView isKindOfClass:[MGLCompassButton class]]); - XCTAssertTrue(self.mapView.compassView.userInteractionEnabled); - 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); -} - -- (void)testVisibilityAdaptive { - XCTAssertEqual(self.mapView.compassView.compassVisibility, MGLOrnamentVisibilityAdaptive, @"Adaptive should be the default visibility setting."); - XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should not initially be visible."); - - self.mapView.zoomLevel = 15.f; - [self.mapView setDirection:45.f animated:false]; - XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); - XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should become visible when direction changes."); - - [self.mapView resetNorthAnimated:NO]; - XCTAssertEqual(self.mapView.direction, 0); - XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should hide itself when direction is north."); -} - -- (void)testVisibilityHidden { - self.mapView.compassView.compassVisibility = MGLOrnamentVisibilityHidden; - XCTAssertEqual(self.mapView.compassView.compassVisibility, MGLOrnamentVisibilityHidden); - XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should not initially be visible."); - - self.mapView.zoomLevel = 15.f; - [self.mapView setDirection:45.f animated:false]; - XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); - XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should stay hidden when direction changes."); -} - -- (void)testVisibilityVisible { - self.mapView.compassView.compassVisibility = MGLOrnamentVisibilityVisible; - XCTAssertEqual(self.mapView.compassView.compassVisibility, MGLOrnamentVisibilityVisible); - XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should initially be visible."); - - self.mapView.zoomLevel = 15.f; - [self.mapView setDirection:45.f animated:false]; - XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); - XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should continue to be visible when direction changes."); - - [self.mapView resetNorthAnimated:NO]; - XCTAssertEqual(self.mapView.direction, 0); - 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/MGLMapViewContentInsetTests.m b/platform/ios/test/MGLMapViewContentInsetTests.m deleted file mode 100644 index 185baf4a05..0000000000 --- a/platform/ios/test/MGLMapViewContentInsetTests.m +++ /dev/null @@ -1,177 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> - -@interface MGLMapViewContentInsetTests : XCTestCase <MGLMapViewDelegate> - -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic) UIWindow *window; -@property (nonatomic) UIViewController *viewController; -@property (nonatomic) XCTestExpectation *styleLoadingExpectation; -@property (assign) CGRect screenBounds; - -@end - -@implementation MGLMapViewContentInsetTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.screenBounds = UIScreen.mainScreen.bounds; - self.mapView = [[MGLMapView alloc] initWithFrame:self.screenBounds styleURL:styleURL]; - self.mapView.zoomLevel = 16; - self.mapView.delegate = self; - - self.viewController = [[UIViewController alloc] init]; - self.viewController.view = [[UIView alloc] initWithFrame:self.screenBounds]; - [self.viewController.view addSubview:self.mapView]; - self.window = [[UIWindow alloc] initWithFrame:self.screenBounds]; - [self.window addSubview:self.viewController.view]; - [self.window makeKeyAndVisible]; - - if (!self.mapView.style) { - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self waitForExpectationsWithTimeout:10 handler:nil]; - } -} - -- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { - XCTAssertNotNil(mapView.style); - XCTAssertEqual(mapView.style, style); - - [_styleLoadingExpectation fulfill]; -} - -- (void)tearDown { - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - [super tearDown]; -} - -- (void)testContentInsetCenter { - CLLocationCoordinate2D center = CLLocationCoordinate2DMake(1.0, 5.0); - self.mapView.centerCoordinate = center; - XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.latitude, center.latitude, 0.01); - XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.longitude, center.longitude, 0.01); - - CGPoint centerPoint = [self.mapView convertCoordinate:center toPointToView:self.mapView]; - - XCTAssertEqualWithAccuracy(centerPoint.x, self.screenBounds.size.width/2, 0.01); - XCTAssertEqualWithAccuracy(centerPoint.y, self.screenBounds.size.height/2, 0.01); - - // shifting contentInset should keep the same centerCoordinate but shift the screen - // center point accordingly - UIEdgeInsets contentInset = UIEdgeInsetsMake(50.0, 10.0, 10.0, 30.0); - self.mapView.contentInset = contentInset; - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.latitude, center.latitude, 0.01); - XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.longitude, center.longitude, 0.01); - CGPoint shiftedPoint = [self.mapView convertCoordinate:center toPointToView:self.mapView]; - CGPoint expectedShiftedPoint = CGPointMake((self.screenBounds.size.width/2) + ((contentInset.left - contentInset.right) / 2 ), - (self.screenBounds.size.height/2) + ((contentInset.top - contentInset.bottom) / 2)); - XCTAssertEqualWithAccuracy(shiftedPoint.x, expectedShiftedPoint.x, 0.01); - XCTAssertEqualWithAccuracy(shiftedPoint.y, expectedShiftedPoint.y, 0.01); - - -} - -- (void)testContentInsetOrnaments { - CGFloat margin = 8; - self.mapView.contentInset = UIEdgeInsetsZero; - UIView *scaleBar = self.mapView.scaleBar; - CGPoint expectedScaleBarOrigin = CGPointMake(margin, margin); - XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin)); - - UIView *compassView = self.mapView.compassView; - CGFloat x = self.screenBounds.size.width - compassView.bounds.size.width - margin; - CGPoint expectedCompassOrigin = CGPointMake(x, margin); - XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin)); - - UIView *logoView = self.mapView.logoView; - CGFloat y = self.screenBounds.size.height - logoView.bounds.size.height - margin; - CGPoint expectedLogoOrigin = CGPointMake(margin, y); - XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin)); - - UIView *attributionView = self.mapView.attributionButton; - x = self.screenBounds.size.width - attributionView.bounds.size.width - margin; - y = self.screenBounds.size.height - attributionView.bounds.size.height - margin; - CGPoint expectedAttributionOrigin = CGPointMake(x, y); - XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin)); - - UIEdgeInsets insets = UIEdgeInsetsMake(15, 10, 20, 5); - self.viewController.automaticallyAdjustsScrollViewInsets = NO; - self.mapView.contentInset = insets; - - [self.mapView setNeedsLayout]; - [self.mapView layoutIfNeeded]; - - expectedScaleBarOrigin = CGPointMake(insets.left + self.mapView.scaleBarMargins.x, insets.top + self.mapView.scaleBarMargins.y); - XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin)); - - x = self.screenBounds.size.width - compassView.bounds.size.width - insets.right - self.mapView.compassViewMargins.x; - expectedCompassOrigin = CGPointMake(x, insets.top + self.mapView.compassViewMargins.y); - XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin)); - - y = self.screenBounds.size.height - logoView.bounds.size.height - insets.bottom - self.mapView.logoViewMargins.y; - expectedLogoOrigin = CGPointMake(insets.left + self.mapView.logoViewMargins.x, y); - XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin)); - - x = self.screenBounds.size.width - attributionView.bounds.size.width - insets.right - self.mapView.attributionButtonMargins.x; - y = self.screenBounds.size.height - attributionView.bounds.size.height - insets.bottom - self.mapView.attributionButtonMargins.y; - expectedAttributionOrigin = CGPointMake(x, y); - XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin)); - - // tests that passing negative values result in a 0 inset value - insets = UIEdgeInsetsMake(-100, -100, -100, -100); - self.mapView.contentInset = insets; - - [self.mapView setNeedsLayout]; - [self.mapView layoutIfNeeded]; - - expectedScaleBarOrigin = CGPointMake(margin, margin); - XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin)); - - x = self.screenBounds.size.width - compassView.bounds.size.width - margin; - expectedCompassOrigin = CGPointMake(x, margin); - XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin)); - - y = self.screenBounds.size.height - logoView.bounds.size.height - margin; - expectedLogoOrigin = CGPointMake(margin, y); - XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin)); - - x = self.screenBounds.size.width - attributionView.bounds.size.width - margin; - y = self.screenBounds.size.height - attributionView.bounds.size.height - margin; - expectedAttributionOrigin = CGPointMake(x, y); - XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin)); - - self.mapView.automaticallyAdjustsContentInset = YES; - insets = UIEdgeInsetsMake(100, 100, 100, 100); - self.mapView.contentInset = insets; - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, insets)); - - [self.mapView setNeedsLayout]; - [self.mapView layoutIfNeeded]; - - // when automaticallyAdjustsContentInset = YES the content insets should be overwriten - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, insets)); - - expectedScaleBarOrigin = CGPointMake(margin, margin); - XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin)); - - x = self.screenBounds.size.width - compassView.bounds.size.width - margin; - expectedCompassOrigin = CGPointMake(x, margin); - XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin)); - - y = self.screenBounds.size.height - logoView.bounds.size.height - margin; - expectedLogoOrigin = CGPointMake(margin, y); - XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin)); - - x = self.screenBounds.size.width - attributionView.bounds.size.width - margin; - y = self.screenBounds.size.height - attributionView.bounds.size.height - margin; - expectedAttributionOrigin = CGPointMake(x, y); - XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin)); - -} - -@end diff --git a/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift b/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift deleted file mode 100644 index 172538c65b..0000000000 --- a/platform/ios/test/MGLMapViewDelegateIntegrationTests.swift +++ /dev/null @@ -1,103 +0,0 @@ -import XCTest -import Mapbox - -class MGLMapViewDelegateIntegrationTests: XCTestCase { - - func testCoverage() { - MGLSDKTestHelpers.checkTestsContainAllMethods(testClass: MGLMapViewDelegateIntegrationTests.self, in: MGLMapViewDelegate.self) - } - -} - -extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate { - - func mapViewRegionIsChanging(_ mapView: MGLMapView) {} - - func mapViewRegionIsChanging(_ mapView: MGLMapView, reason: MGLCameraChangeReason) {} - - func mapView(_ mapView: MGLMapView, regionIsChangingWith reason: MGLCameraChangeReason) {} - - func mapView(_ mapView: MGLMapView, didChange mode: MGLUserTrackingMode, animated: Bool) {} - - func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {} - - func mapViewDidStopLocatingUser(_ mapView: MGLMapView) {} - - func mapViewWillStartLoadingMap(_ mapView: MGLMapView) {} - - func mapViewWillStartLocatingUser(_ mapView: MGLMapView) {} - - func mapViewWillStartRenderingMap(_ mapView: MGLMapView) {} - - func mapViewWillStartRenderingFrame(_ mapView: MGLMapView) {} - - func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {} - - func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {} - - func mapView(_ mapView: MGLMapView, didDeselect annotation: MGLAnnotation) {} - - func mapView(_ mapView: MGLMapView, didSingleTapAt coordinate: CLLocationCoordinate2D) {} - - func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {} - - func mapView(_ mapView: MGLMapView, regionDidChangeWith reason: MGLCameraChangeReason, animated: Bool) {} - - func mapView(_ mapView: MGLMapView, regionWillChangeAnimated animated: Bool) {} - - func mapView(_ mapView: MGLMapView, regionWillChangeWith reason: MGLCameraChangeReason, animated: Bool) {} - - func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {} - - func mapView(_ mapView: MGLMapView, didUpdate userLocation: MGLUserLocation?) {} - - func mapViewDidFinishRenderingMap(_ mapView: MGLMapView, fullyRendered: Bool) {} - - func mapViewDidBecomeIdle(_ mapView: MGLMapView) {} - - func mapView(_ mapView: MGLMapView, didFailToLocateUserWithError error: Error) {} - - func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) {} - - func mapViewDidFinishRenderingFrame(_ mapView: MGLMapView, fullyRendered: Bool) {} - - func mapView(_ mapView: MGLMapView, shapeAnnotationIsEnabled annotation: MGLShape) -> Bool { return false } - - func mapView(_ mapView: MGLMapView, didAdd annotationViews: [MGLAnnotationView]) {} - - func mapView(_ mapView: MGLMapView, didSelect annotationView: MGLAnnotationView) {} - - func mapView(_ mapView: MGLMapView, didDeselect annotationView: MGLAnnotationView) {} - - func mapView(_ mapView: MGLMapView, alphaForShapeAnnotation annotation: MGLShape) -> CGFloat { return 0 } - - func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { return nil } - - func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? { return nil } - - func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { return false } - - func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> MGLCalloutView? { return nil } - - func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor { return .black } - - func mapView(_ mapView: MGLMapView, fillColorForPolygonAnnotation annotation: MGLPolygon) -> UIColor { return .black } - - func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { return nil } - - func mapView(_ mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { return 0 } - - func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { return nil } - - func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {} - - func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> Bool { return false } - - func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera, reason: MGLCameraChangeReason) -> Bool { return false } - - func mapViewUserLocationAnchorPoint(_ mapView: MGLMapView) -> CGPoint { return CGPoint(x: 100, y: 100) } - - func mapView(_ mapView: MGLMapView, didFailToLoadImage imageName: String) -> UIImage? { return nil } - - func mapView(_ mapView: MGLMapView, shouldRemoveStyleImage imageName: String) -> Bool { return false } -} diff --git a/platform/ios/test/MGLMapViewDirectionTests.mm b/platform/ios/test/MGLMapViewDirectionTests.mm deleted file mode 100644 index 81e169432b..0000000000 --- a/platform/ios/test/MGLMapViewDirectionTests.mm +++ /dev/null @@ -1,126 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> -#import "MGLMockGestureRecognizers.h" - -#import <mbgl/math/wrap.hpp> - -@interface MGLMapView (MGLMapViewDirectionTests) -- (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate; -- (void)resetNorthAnimated:(BOOL)animated; -@end - - -@interface MGLMapViewDirectionTests : XCTestCase -@property (nonatomic) MGLMapView *mapView; -@end - -@implementation MGLMapViewDirectionTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 64, 64) styleURL:styleURL]; -} - -- (void)tearDown { - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - [super tearDown]; -} - -- (void)testDirection { - self.mapView.zoomLevel = 0; - self.mapView.direction = 30; - XCTAssertEqual(self.mapView.direction, 0, @"Rotation is not allowed at world-scale zoom levels."); - - self.mapView.zoomLevel = 15; - CLLocationCoordinate2D originalCenterCoordinate = self.mapView.centerCoordinate; - - 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.); - self.mapView.direction = inputDegrees; - XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedDegrees, 0.001); - - XCTAssertEqual(originalCenterCoordinate.latitude, self.mapView.centerCoordinate.latitude, "@Map center coordinate latitude should remain constant when direction is set to %@°.", degrees); - XCTAssertEqual(originalCenterCoordinate.longitude, self.mapView.centerCoordinate.longitude, @"Map center coordinate longitude should remain constant when direction is set to %@°.", degrees); - } - - [self.mapView resetNorthAnimated:NO]; - XCTAssertEqual(self.mapView.direction, 0, @"Reset-to-north should set direction to 0°."); - XCTAssertEqual(originalCenterCoordinate.latitude, self.mapView.centerCoordinate.latitude, "@Map center coordinate latitude should remain constant when direction is reset."); - XCTAssertEqual(originalCenterCoordinate.longitude, self.mapView.centerCoordinate.longitude, @"Map center coordinate latitude should remain constant when direction is reset."); -} - -- (void)testRotateEnabled { - self.mapView.zoomLevel = 10; - - UIRotationGestureRecognizerMock *gesture = [[UIRotationGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - gesture.rotation = MGLRadiansFromDegrees(30); - CGFloat wrappedRotation = mbgl::util::wrap(-MGLDegreesFromRadians(gesture.rotation), 0., 360.); - - // Disabled - { - self.mapView.rotateEnabled = NO; - XCTAssertEqual(self.mapView.allowsRotating, NO); - - [self.mapView handleRotateGesture:gesture]; - XCTAssertNotEqual(self.mapView.direction, wrappedRotation, @"Gestural rotation should not work when rotation is disabled."); - - self.mapView.direction = 45.f; - XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001, @"Programmatic rotation is allowed when rotateEnabled = NO."); - } - - // Enabled - { - [self.mapView resetNorthAnimated:NO]; - self.mapView.rotateEnabled = YES; - XCTAssertEqual(self.mapView.allowsRotating, YES); - - gesture.state = UIGestureRecognizerStateChanged; - gesture.rotation = MGLRadiansFromDegrees(30); - [self.mapView handleRotateGesture:gesture]; - XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedRotation, 0.001, @"Gestural rotation should work when rotation is enabled."); - } -} - -- (void)testRotationGesture { - self.mapView.zoomLevel = 15; - CLLocationCoordinate2D originalCenterCoordinate = self.mapView.centerCoordinate; - - UIRotationGestureRecognizerMock *gesture = [[UIRotationGestureRecognizerMock alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - gesture.rotation = 0; - [self.mapView addGestureRecognizer:gesture]; - [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]); - [self.mapView handleRotateGesture:gesture]; - CGFloat wrappedRotation = mbgl::util::wrap(-MGLDegreesFromRadians(gesture.rotation), 0., 360.); - XCTAssertEqualWithAccuracy(self.mapView.direction, wrappedRotation, 0.001, @"Map direction should match gesture rotation for input of %@°.", degrees); - - // Given a hypothetical rotation around the exact center of the map, the center coordinate should remain the same. - // See above where we override -[UIRotationGestureRecognizer locationInView:] to always return the center of the target view. - XCTAssertEqualWithAccuracy(originalCenterCoordinate.latitude, self.mapView.centerCoordinate.latitude, 0.0000001, "@Map center coordinate latitude should remain constant during rotation of %@°.", degrees); - XCTAssertEqualWithAccuracy(originalCenterCoordinate.longitude, self.mapView.centerCoordinate.longitude, 0.0000001, @"Map center coordinate longitude should remain constant during rotation of %@°.", degrees); - } -} - -- (void)testResetPosition { - [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 { - CGFloat angle = atan2f(transform.b, transform.a); - return MGLDegreesFromRadians(angle); -} - -@end diff --git a/platform/ios/test/MGLMapViewGestureRecognizerTests.mm b/platform/ios/test/MGLMapViewGestureRecognizerTests.mm deleted file mode 100644 index 58fbf2d03b..0000000000 --- a/platform/ios/test/MGLMapViewGestureRecognizerTests.mm +++ /dev/null @@ -1,280 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> - -#import "../../darwin/src/MGLGeometry_Private.h" -#import "MGLMockGestureRecognizers.h" - -#include <mbgl/map/map.hpp> -#include <mbgl/map/camera.hpp> - -@interface MGLMapView (MGLMapViewGestureRecognizerTests) - -- (mbgl::Map &)mbglMap; - -- (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch; -- (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate; -- (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap; -- (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap; -- (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom; -- (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag; - -@end - -@interface MGLMapViewGestureRecognizerTests : XCTestCase <MGLMapViewDelegate> - -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic) UIWindow *window; -@property (nonatomic) UIViewController *viewController; -@property (nonatomic) XCTestExpectation *styleLoadingExpectation; -@property (nonatomic) XCTestExpectation *twoFingerExpectation; -@property (nonatomic) XCTestExpectation *quickZoomExpectation; -@property (nonatomic) XCTestExpectation *doubleTapExpectation; -@property (nonatomic) XCTestExpectation *twoFingerDragExpectation; -@property (assign) CGRect screenBounds; - -@end - -@implementation MGLMapViewGestureRecognizerTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.screenBounds = UIScreen.mainScreen.bounds; - self.mapView = [[MGLMapView alloc] initWithFrame:self.screenBounds styleURL:styleURL]; - self.mapView.zoomLevel = 16; - self.mapView.delegate = self; - - self.viewController = [[UIViewController alloc] init]; - self.viewController.view = [[UIView alloc] initWithFrame:self.screenBounds]; - [self.viewController.view addSubview:self.mapView]; - self.window = [[UIWindow alloc] initWithFrame:self.screenBounds]; - [self.window addSubview:self.viewController.view]; - [self.window makeKeyAndVisible]; - - if (!self.mapView.style) { - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self waitForExpectationsWithTimeout:10 handler:nil]; - } -} - -- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { - XCTAssertNotNil(mapView.style); - XCTAssertEqual(mapView.style, style); - - [_styleLoadingExpectation fulfill]; -} - -- (void)testHandlePinchGestureContentInset { - UIEdgeInsets contentInset = UIEdgeInsetsZero; - self.mapView.contentInset = contentInset; - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); - auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - contentInset = UIEdgeInsetsMake(20, 20, 20, 20); - [self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertNotEqual(padding, cameraPadding); - - UIPinchGestureRecognizerMock *pinchGesture = [[UIPinchGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - pinchGesture.state = UIGestureRecognizerStateBegan; - pinchGesture.scale = 1.0; - [self.mapView handlePinchGesture:pinchGesture]; - XCTAssertNotEqual(padding, cameraPadding); - - pinchGesture.state = UIGestureRecognizerStateChanged; - [self.mapView handlePinchGesture:pinchGesture]; - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - - pinchGesture.state = UIGestureRecognizerStateEnded; - [self.mapView handlePinchGesture:pinchGesture]; - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - -} - -- (void)testHandleRotateGestureContentInset { - UIEdgeInsets contentInset = UIEdgeInsetsZero; - self.mapView.contentInset = contentInset; - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); - auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - contentInset = UIEdgeInsetsMake(20, 20, 20, 20); - [self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertNotEqual(padding, cameraPadding); - - UIRotationGestureRecognizerMock *rotateGesture = [[UIRotationGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - rotateGesture.state = UIGestureRecognizerStateBegan; - rotateGesture.rotation = 1; - [self.mapView handleRotateGesture:rotateGesture]; - XCTAssertNotEqual(padding, cameraPadding); - - rotateGesture.state = UIGestureRecognizerStateChanged; - [self.mapView handleRotateGesture:rotateGesture]; - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - - rotateGesture.state = UIGestureRecognizerStateEnded; - [self.mapView handleRotateGesture:rotateGesture]; - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - -} - -- (void)testHandleDoubleTapGestureContentInset { - UIEdgeInsets contentInset = UIEdgeInsetsMake(1, 1, 1, 1); - self.mapView.contentInset = contentInset; - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); - auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - contentInset = UIEdgeInsetsMake(20, 20, 20, 20); - [self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertNotEqual(padding, cameraPadding); - - UITapGestureRecognizerMock *doubleTapGesture = [[UITapGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - doubleTapGesture.mockTappedView = self.mapView; - doubleTapGesture.mockTappedPoint = CGPointMake(1.0, 1.0); - - [self.mapView handleDoubleTapGesture:doubleTapGesture]; - _doubleTapExpectation = [self expectationWithDescription:@"Double tap gesture animation."]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self->_doubleTapExpectation fulfill]; - }); - [self waitForExpectationsWithTimeout:10 handler:nil]; - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - -} - -- (void)testHandleTwoFingerTapGesture { - UIEdgeInsets contentInset = UIEdgeInsetsZero; - self.mapView.contentInset = contentInset; - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); - auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - contentInset = UIEdgeInsetsMake(20, 20, 20, 20); - [self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertNotEqual(padding, cameraPadding); - - UITapGestureRecognizerMock *twoFingerTap = [[UITapGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - twoFingerTap.mockTappedView = self.mapView; - twoFingerTap.mockTappedPoint = CGPointMake(1.0, 1.0); - - [self.mapView handleTwoFingerTapGesture:twoFingerTap]; - _twoFingerExpectation = [self expectationWithDescription:@"Two Finger tap gesture animation."]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self->_twoFingerExpectation fulfill]; - }); - [self waitForExpectationsWithTimeout:10 handler:nil]; - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); -} - -- (void)testHandleQuickZoomGesture { - UIEdgeInsets contentInset = UIEdgeInsetsZero; - self.mapView.contentInset = contentInset; - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); - auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - contentInset = UIEdgeInsetsMake(20, 20, 20, 20); - [self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertNotEqual(padding, cameraPadding); - - UILongPressGestureRecognizerMock *quickZoom = [[UILongPressGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - quickZoom.state = UIGestureRecognizerStateBegan; - [self.mapView handleQuickZoomGesture:quickZoom]; - XCTAssertNotEqual(padding, cameraPadding); - - quickZoom.state = UIGestureRecognizerStateChanged; - quickZoom.mockTappedPoint = CGPointMake(self.mapView.frame.size.width / 2, self.mapView.frame.size.height / 2); - [self.mapView handleQuickZoomGesture:quickZoom]; - _quickZoomExpectation = [self expectationWithDescription:@"Quick zoom gesture animation."]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self->_quickZoomExpectation fulfill]; - }); - [self waitForExpectationsWithTimeout:10 handler:nil]; - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - - quickZoom.state = UIGestureRecognizerStateEnded; - [self.mapView handleQuickZoomGesture:quickZoom]; - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); -} - -- (void)testHandleTwoFingerDragGesture { - UIEdgeInsets contentInset = UIEdgeInsetsZero; - self.mapView.contentInset = contentInset; - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); - auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); - XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - contentInset = UIEdgeInsetsMake(20, 20, 20, 20); - [self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; - XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertNotEqual(padding, cameraPadding); - - UIPanGestureRecognizerMock *twoFingerDrag = [[UIPanGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - twoFingerDrag.state = UIGestureRecognizerStateBegan; - twoFingerDrag.firstFingerPoint = CGPointMake(self.mapView.frame.size.width / 3, self.mapView.frame.size.height/2); - twoFingerDrag.secondFingerPoint = CGPointMake((self.mapView.frame.size.width / 2), self.mapView.frame.size.height/2); - twoFingerDrag.numberOfTouches = 2; - [self.mapView handleTwoFingerDragGesture:twoFingerDrag]; - XCTAssertNotEqual(padding, cameraPadding); - - twoFingerDrag.state = UIGestureRecognizerStateChanged; - twoFingerDrag.firstFingerPoint = CGPointMake(self.mapView.frame.size.width / 3, (self.mapView.frame.size.height/2)-10); - twoFingerDrag.secondFingerPoint = CGPointMake((self.mapView.frame.size.width / 2), (self.mapView.frame.size.height/2)-10); - [self.mapView handleTwoFingerDragGesture:twoFingerDrag]; - _twoFingerDragExpectation = [self expectationWithDescription:@"Quick zoom gesture animation."]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self->_twoFingerDragExpectation fulfill]; - }); - [self waitForExpectationsWithTimeout:10 handler:nil]; - - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); - - twoFingerDrag.state = UIGestureRecognizerStateEnded; - [self.mapView handleTwoFingerDragGesture:twoFingerDrag]; - cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; - XCTAssertEqual(padding, cameraPadding, @"When a gesture recognizer is performed contentInsets and camera padding should match."); -} - -@end diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m deleted file mode 100644 index 2a9579818a..0000000000 --- a/platform/ios/test/MGLMapViewLayoutTests.m +++ /dev/null @@ -1,317 +0,0 @@ -#import <XCTest/XCTest.h> -#import "MGLMapView.h" -#import "MGLMapViewDelegate.h" -#import "MGLAccountManager.h" - -#import "MGLScaleBar.h" - -@interface MGLOrnamentTestData : NSObject - -@property (nonatomic) MGLOrnamentPosition position; -@property (nonatomic) CGPoint offset; -@property (nonatomic) CGPoint expectedOrigin; - -@end - -@implementation MGLOrnamentTestData - -+ (instancetype)createWithPosition:(MGLOrnamentPosition)position offset:(CGPoint)offset expectedOrigin:(CGPoint)expectedOrigin { - MGLOrnamentTestData *data = [[MGLOrnamentTestData alloc] init]; - data.position = position; - data.offset = offset; - data.expectedOrigin = expectedOrigin; - return data; -} - -@end - -@interface MGLScaleBar (Tests) -@property (nonatomic, readonly) NSArray<UIView *> *labelViews; -@property (nonatomic, readonly) NSArray<UIView *> *bars; -@property (nonatomic, readonly) UIView *containerView; -@property (nonatomic, readonly) CGSize size; -@property (nonatomic) NSNumber *testingRightToLeftOverride; -@end - - -@interface MGLMapViewLayoutTests : XCTestCase<MGLMapViewDelegate> - -@property (nonatomic) UIView *superView; -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic) XCTestExpectation *styleLoadingExpectation; - -@end - -@implementation MGLMapViewLayoutTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - - self.superView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; - - self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; - self.mapView.delegate = self; - - [self.superView addSubview:self.mapView]; - - UIView *mapView = self.mapView; - NSDictionary *bindings = NSDictionaryOfVariableBindings(mapView); - NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[mapView]-0-|" options:0 metrics:nil views:bindings]; - NSArray *horizonatalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[mapView]-0-|" options:0 metrics:nil views:bindings]; - - [self.superView addConstraints:[verticalConstraints arrayByAddingObjectsFromArray:horizonatalConstraints]]; - - self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self waitForExpectationsWithTimeout:10 handler:nil]; - - self.mapView.showsScale = YES; - - //set zoom and heading so that scale bar and compass will be shown - [self.mapView setZoomLevel:10.0 animated:NO]; - [self.mapView.camera setHeading:12.0]; - - //invoke layout - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; -} - -- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { - XCTAssertNotNil(mapView.style); - XCTAssertEqual(mapView.style, style); - - [self.styleLoadingExpectation fulfill]; -} - -- (void)tearDown { - self.styleLoadingExpectation = nil; - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - - [super tearDown]; -} - -- (void)testOrnamentPlacement { - - CGFloat margin = 8.0; - CGFloat bottomSafeAreaInset = 0.0; - double accuracy = 0.01; - - if (@available(iOS 11.0, *)) { - bottomSafeAreaInset = self.mapView.safeAreaInsets.bottom; - } - - //compass - UIImageView *compassView = self.mapView.compassView; - - CGFloat expectedCompassOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(compassView.frame); - CGFloat expectedCompassOriginY = margin; - - XCTAssertEqualWithAccuracy(CGRectGetMinX(compassView.frame), expectedCompassOriginX, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(compassView.frame), expectedCompassOriginY, accuracy); - - //scale bar - UIView *scaleBar = self.mapView.scaleBar; - - XCTAssertEqualWithAccuracy(CGRectGetMinX(scaleBar.frame), margin, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(scaleBar.frame), margin, accuracy); - - //attribution button - UIButton *attributionButton = self.mapView.attributionButton; - - CGFloat expectedButtonOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(attributionButton.frame); - CGFloat expectedButtonOriginY = CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(attributionButton.frame); - - XCTAssertEqualWithAccuracy(CGRectGetMinX(attributionButton.frame), expectedButtonOriginX, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(attributionButton.frame), expectedButtonOriginY, accuracy); - - //mapbox logo - UIImageView *logoView = self.mapView.logoView; - - CGFloat expectedLogoOriginX = margin; - CGFloat expectedLogoOriginY = CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(logoView.frame); - - XCTAssertEqualWithAccuracy(CGRectGetMinX(logoView.frame), expectedLogoOriginX, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(logoView.frame), expectedLogoOriginY, accuracy); -} - -- (NSArray *)makeTestDataListWithView:(UIView *)view margin:(CGFloat)margin { - CGFloat bottomSafeAreaInset = 0.0; - if (@available(iOS 11.0, *)) { - bottomSafeAreaInset = self.mapView.safeAreaInsets.bottom; - } - - return @[ - [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionTopLeft - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(margin, margin)], - [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionTopRight - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), margin)], - [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionBottomLeft - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(margin, CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))], - [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionBottomRight - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), - CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))] - ]; -} - -- (void)testCompassPlacement { - double accuracy = 0.01; - CGFloat margin = 4.0; - - UIView *compassView = self.mapView.compassView; - NSArray *testDataList = [self makeTestDataListWithView:compassView margin:margin]; - - for (MGLOrnamentTestData *testData in testDataList) { - self.mapView.compassViewPosition = testData.position; - self.mapView.compassViewMargins = testData.offset; - - //invoke layout - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; - - XCTAssertEqualWithAccuracy(CGRectGetMinX(compassView.frame), testData.expectedOrigin.x, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(compassView.frame), testData.expectedOrigin.y, accuracy); - } -} - -- (void)testScalebarPlacement { - double accuracy = 0.01; - CGFloat margin = 4.0; - - UIView *scaleBar = self.mapView.scaleBar; - XCTAssertFalse(CGSizeEqualToSize(scaleBar.bounds.size, CGSizeZero)); - - NSArray *testDataList = [self makeTestDataListWithView:scaleBar margin:margin]; - - for (MGLOrnamentTestData *testData in testDataList) { - self.mapView.scaleBarPosition = testData.position; - self.mapView.scaleBarMargins = testData.offset; - - //invoke layout - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; - - XCTAssertEqualWithAccuracy(CGRectGetMinX(scaleBar.frame), testData.expectedOrigin.x, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(scaleBar.frame), testData.expectedOrigin.y, accuracy); - } -} - -// This test checks the frames of the scalebar's subviews, based on the positions -// as above, but also with forced Right-to-Left reading, and modifying zoom levels. -- (void)testScalebarSubviewPlacement { - double accuracy = 0.01; - CGFloat margin = 20.0; - - MGLScaleBar *scaleBar = (MGLScaleBar*)self.mapView.scaleBar; - XCTAssertFalse(CGSizeEqualToSize(scaleBar.bounds.size, CGSizeZero)); - - for (NSInteger rtl = 0; rtl <= 1; rtl++) { - scaleBar.testingRightToLeftOverride = @((BOOL)rtl); - - NSString *positions[] = { - @"MGLOrnamentPositionTopLeft", - @"MGLOrnamentPositionTopRight", - @"MGLOrnamentPositionBottomLeft", - @"MGLOrnamentPositionBottomRight" - }; - - for (CGFloat zoomLevel = 0; zoomLevel < 20; zoomLevel++) - { - self.mapView.zoomLevel = zoomLevel; - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; - - // Following method assumes scaleBar has an up-to-date frame, based - // on the current zoom level. Modifying the position and margins - // should not affect the overall size of the scalebar. - - NSArray *testDataList = [self makeTestDataListWithView:scaleBar margin:margin]; - - CGSize initialSize = scaleBar.intrinsicContentSize; - XCTAssert(CGSizeEqualToSize(initialSize, scaleBar.bounds.size)); - - for (MGLOrnamentTestData *testData in testDataList) { - self.mapView.scaleBarPosition = testData.position; - self.mapView.scaleBarMargins = testData.offset; - - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; - - XCTAssert(CGSizeEqualToSize(initialSize, scaleBar.bounds.size)); - - NSString *activityName = [NSString stringWithFormat: - @"Scalebar subview tests: RTL=%@, Zoom=%ld, POS=%@, Visible=%@", - (rtl == 0 ? @"NO" : @"YES"), - (long)zoomLevel, - positions[testData.position], - scaleBar.alpha > 0.0 ? @"YES" : @"NO"]; - - [XCTContext runActivityNamed:activityName - block:^(id<XCTActivity> activity) { - - // Check the subviews - XCTAssertEqualWithAccuracy(CGRectGetMinX(scaleBar.frame), testData.expectedOrigin.x, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(scaleBar.frame), testData.expectedOrigin.y, accuracy); - - XCTAssertTrue(CGRectContainsRect(scaleBar.bounds, scaleBar.containerView.frame)); - for (UIView *bar in scaleBar.bars) { - XCTAssertTrue(CGRectContainsRect(scaleBar.containerView.bounds, bar.frame)); - } - for (UIView *label in scaleBar.labelViews) { - if (!label.isHidden) { - XCTAssertTrue(CGRectContainsRect(scaleBar.bounds, label.frame)); - } - } - }]; - } - } - } -} - -- (void)testAttributionButtonPlacement { - double accuracy = 0.01; - CGFloat margin = 4.0; - - UIView *attributionButton = self.mapView.attributionButton; - NSArray *testDataList = [self makeTestDataListWithView:attributionButton margin:margin]; - - for (MGLOrnamentTestData *testData in testDataList) { - self.mapView.attributionButtonPosition = testData.position; - self.mapView.attributionButtonMargins = testData.offset; - - //invoke layout - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; - - XCTAssertEqualWithAccuracy(CGRectGetMinX(attributionButton.frame), testData.expectedOrigin.x, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(attributionButton.frame), testData.expectedOrigin.y, accuracy); - } -} - -- (void)testLogoPlacement { - double accuracy = 0.01; - CGFloat margin = 4.0; - - UIView *logoView = self.mapView.logoView; - NSArray *testDataList = [self makeTestDataListWithView:logoView margin:margin]; - - for (MGLOrnamentTestData *testData in testDataList) { - self.mapView.logoViewPosition = testData.position; - self.mapView.logoViewMargins = testData.offset; - - //invoke layout - [self.superView setNeedsLayout]; - [self.superView layoutIfNeeded]; - - XCTAssertEqualWithAccuracy(CGRectGetMinX(logoView.frame), testData.expectedOrigin.x, accuracy); - XCTAssertEqualWithAccuracy(CGRectGetMinY(logoView.frame), testData.expectedOrigin.y, accuracy); - } -} - -@end diff --git a/platform/ios/test/MGLMapViewPitchTests.m b/platform/ios/test/MGLMapViewPitchTests.m deleted file mode 100644 index fa657eb994..0000000000 --- a/platform/ios/test/MGLMapViewPitchTests.m +++ /dev/null @@ -1,190 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> - -@interface MockUIPanGestureRecognizer : UIPanGestureRecognizer -@property(nonatomic, readwrite) UIGestureRecognizerState state; -@property NSUInteger mbx_numberOfFingersForGesture; -@property CGPoint mbx_middlePoint; -@property CGPoint mbx_westPoint; -@property CGPoint mbx_eastPoint; -@end - -@implementation MockUIPanGestureRecognizer - -@synthesize state; - -- (instancetype)initWithTarget:(id)target action:(SEL)action { - if (self = [super initWithTarget:target action:action]) { - self.mbx_numberOfFingersForGesture = 2; - self.mbx_westPoint = CGPointMake(100, 0); - self.mbx_eastPoint = CGPointMake(200, 0); - } - return self; -} -- (NSUInteger)numberOfTouches { return self.mbx_numberOfFingersForGesture; } -- (CGPoint)translationInView:(UIView *)view { return self.mbx_middlePoint; } -- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view { - if (touchIndex == 0) { - return self.mbx_westPoint; - } - return self.mbx_eastPoint; -} -- (void)setTiltGestureYTranslationForPitchDegrees:(CGFloat)degrees { - // The tilt gesture takes the number of screen points the fingers have moved and then divides them by a "slowdown" factor, which happens to be set to 2.0 in -[MGLMapView handleTwoFingerDragGesture:]. - CGFloat mbx_tiltGestureYTranslation = -(degrees * 2.0); - self.mbx_westPoint = CGPointMake(self.mbx_westPoint.x, mbx_tiltGestureYTranslation); - self.mbx_eastPoint = CGPointMake(self.mbx_eastPoint.x, mbx_tiltGestureYTranslation); - self.mbx_middlePoint = CGPointMake(self.mbx_middlePoint.x, mbx_tiltGestureYTranslation); -} -@end - -// Forward declare relevant private methods -@interface MGLMapView (MGLMapViewPitchTests) -- (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)rotate; -- (MGLMapCamera *)cameraByTiltingToPitch:(CGFloat)pitch; -@end - -@interface MGLMapViewPitchTests : XCTestCase -@property (nonatomic) MGLMapView *mapView; -@end - -@implementation MGLMapViewPitchTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 400, 400) styleURL:styleURL]; -} - -- (void)tearDown { - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - [super tearDown]; -} - -- (void)testPitchEnabled { - self.mapView.pitchEnabled = NO; - self.mapView.camera = [self.mapView cameraByTiltingToPitch:30]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 30, 0.001, @"Tilt should not be set when pitchEnabled = NO."); - - self.mapView.pitchEnabled = YES; - self.mapView.camera = [self.mapView cameraByTiltingToPitch:30]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 30, 0.001, @"Tilt should be set when pitchEnabled = YES."); -} - -- (void)testPitchInValidRange { - for (NSNumber *degrees in @[@0, @5, @20, @40, @60]) { - CGFloat inputDegrees = [degrees floatValue]; - self.mapView.camera = [self.mapView cameraByTiltingToPitch:inputDegrees]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, inputDegrees, 0.001, @"Tilt should be able to be set within range 0-60°."); - } -} - -- (void)testNegativePitchClamping { - for (NSNumber *degrees in @[@CGFLOAT_MIN, @-999, @-60, @-30, @-0]) { - CGFloat inputDegrees = [degrees floatValue]; - self.mapView.camera = [self.mapView cameraByTiltingToPitch:inputDegrees]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 0, 0.001, @"Minimum tilt should be clamped to 0°."); - } -} - -- (void)testPositivePitchClamping { - for (NSNumber *degrees in @[@61, @90, @999, @CGFLOAT_MAX]) { - CGFloat inputDegrees = [degrees floatValue]; - self.mapView.camera = [self.mapView cameraByTiltingToPitch:inputDegrees]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 60, 0.001, @"Maximum tilt should be clamped to 60°."); - } -} - -- (void)testPitchAtVariousZoomLevels { - for (NSNumber *zoomLevel in @[@0, @5, @10, @15, @18, @21, @CGFLOAT_MAX]) { - self.mapView.camera = [self.mapView cameraByTiltingToPitch:0]; - self.mapView.zoomLevel = 0; - - CGFloat inputZoomLevel = [zoomLevel floatValue]; - self.mapView.zoomLevel = inputZoomLevel; - self.mapView.camera = [self.mapView cameraByTiltingToPitch:30]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 30, 0.001, @"Tilting should be allowed at z%.f.", inputZoomLevel); - } -} - -- (void)testTiltGesture { - MockUIPanGestureRecognizer *gesture = [[MockUIPanGestureRecognizer alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqual(self.mapView.camera.pitch, 0, @"Pitch should initially be set to 0°."); - - // Use a tilt gesture to tilt the map within its acceptable range (0-60°). - for (NSNumber *degrees in @[@0, @5, @20, @40, @60]) { - self.mapView.camera = [self.mapView cameraByTiltingToPitch:0]; - gesture.state = UIGestureRecognizerStateChanged; - - CGFloat inputDegrees = [degrees floatValue]; - [gesture setTiltGestureYTranslationForPitchDegrees:inputDegrees]; - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, inputDegrees, 0.001, @"Pitch should be set to %.f°.", inputDegrees); - } -} - -- (void)testHorizontalTiltGesture { - MockUIPanGestureRecognizer *gesture = [[MockUIPanGestureRecognizer alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqual(self.mapView.camera.pitch, 0, @"Pitch should initially be set to 0°."); - - // Tilt gestures should not be triggered on horizontal dragging. - for (NSInteger deltaX = 0; deltaX < 5; deltaX++) { - gesture.mbx_westPoint = CGPointMake(100 - deltaX, 100); - gesture.mbx_eastPoint = CGPointMake(100 - deltaX, 50); - gesture.mbx_middlePoint = CGPointMake((gesture.mbx_westPoint.x + gesture.mbx_westPoint.x)/2, (gesture.mbx_westPoint.y + gesture.mbx_westPoint.y)/2); - - gesture.state = UIGestureRecognizerStateChanged; - - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqual(self.mapView.camera.pitch, 0, @"Horizontal dragging should not tilt the map."); - } -} - -- (void)testTiltGestureFromInitialTilt { - CGFloat initialTilt = 20; - CGFloat additionalTilt = 30; - - // Set the map camera to a pitched state, perhaps from a previous gesture or camera movement. - self.mapView.camera = [self.mapView cameraByTiltingToPitch:initialTilt]; - XCTAssertEqual(self.mapView.camera.pitch, initialTilt, @"Tilt should initially be set to %.f°.", initialTilt); - - // Initialize a tilt gesture. - MockUIPanGestureRecognizer *gesture = [[MockUIPanGestureRecognizer alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - [self.mapView handleTwoFingerDragGesture:gesture]; - - // Use the gesture to tilt the map even more. - gesture.state = UIGestureRecognizerStateChanged; - [gesture setTiltGestureYTranslationForPitchDegrees:additionalTilt]; - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, initialTilt + additionalTilt, 0.001, @"Tilt should be set to %.f°.", initialTilt + additionalTilt); -} - -- (void)testTiltGestureNumberOfFingersRequired { - // Initialize a tilt gesture with two fingers. - MockUIPanGestureRecognizer *gesture = [[MockUIPanGestureRecognizer alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - gesture.mbx_numberOfFingersForGesture = 2; - - // Use the gesture to tilt to 30°. - [gesture setTiltGestureYTranslationForPitchDegrees:30]; - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 30, 0.001, @"Tilt gesture should work with two fingers down."); - - // Change the gesture's number of fingers to one and try to update the pitch. - gesture.mbx_numberOfFingersForGesture = 1; - gesture.state = UIGestureRecognizerStateChanged; - [gesture setTiltGestureYTranslationForPitchDegrees:0]; - [self.mapView handleTwoFingerDragGesture:gesture]; - XCTAssertEqual(gesture.state, UIGestureRecognizerStateEnded, @"Gesture should end when the number of fingers is less than two."); - XCTAssertEqualWithAccuracy(self.mapView.camera.pitch, 30, 0.001, @"Pitch should remain unchanged if gesture has ended."); -} - -@end diff --git a/platform/ios/test/MGLMapViewScaleBarTests.m b/platform/ios/test/MGLMapViewScaleBarTests.m deleted file mode 100644 index b4f81ef62b..0000000000 --- a/platform/ios/test/MGLMapViewScaleBarTests.m +++ /dev/null @@ -1,70 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> - -@interface MGLMapViewScaleBarTests : XCTestCase - -@property (nonatomic) MGLMapView *mapView; - -@end - -@implementation MGLMapViewScaleBarTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; -} - -- (void)tearDown { - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - - [super tearDown]; -} - -- (void)testShowsScale { - UIView *scaleBar = self.mapView.scaleBar; - - // Scale bar should not be enabled by default. - XCTAssertFalse(self.mapView.showsScale); - XCTAssertTrue(scaleBar.hidden); - - self.mapView.showsScale = YES; - - XCTAssertFalse(scaleBar.hidden); - - // Scale bar should not be visible at default zoom (~z0), but it should be ready. - // Size is not a measure of readiness here though. - XCTAssertTrue(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); - XCTAssertEqual(scaleBar.alpha, 0); - - self.mapView.zoomLevel = 15; - [self.mapView layoutIfNeeded]; - XCTAssertGreaterThan(scaleBar.alpha, 0); - XCTAssertFalse(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); -} - -- (void)testDirectlySettingScaleBarViewHiddenProperty { - UIView *scaleBar = self.mapView.scaleBar; - - scaleBar.hidden = NO; - XCTAssertFalse(scaleBar.hidden); - - // Directly setting `.hidden` after the map has finished initializing will not update the scale bar. - XCTAssertTrue(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); - - // ... but triggering any camera event will update it. - self.mapView.zoomLevel = 1; - [self.mapView layoutIfNeeded]; - - XCTAssertTrue(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); - XCTAssertEqual(scaleBar.alpha, 0); - - self.mapView.zoomLevel = 15; - [self.mapView layoutIfNeeded]; - - XCTAssertGreaterThan(scaleBar.alpha, 0); - XCTAssertFalse(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); -}@end diff --git a/platform/ios/test/MGLMapViewZoomTests.mm b/platform/ios/test/MGLMapViewZoomTests.mm deleted file mode 100644 index 360af72d02..0000000000 --- a/platform/ios/test/MGLMapViewZoomTests.mm +++ /dev/null @@ -1,192 +0,0 @@ -#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; -- (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate; -@end - -@interface MGLMapViewZoomTests : XCTestCase -@property (nonatomic) MGLMapView *mapView; -@end - -@implementation MGLMapViewZoomTests - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; -} - -- (void)tearDown { - self.mapView = nil; - [MGLAccountManager setAccessToken:nil]; - [super tearDown]; -} - -- (void)testZoom { - CLLocationCoordinate2D originalCenterCoordinate = self.mapView.centerCoordinate; - - for (NSNumber *zoom in @[@1, @5, @10, @15, @22]) { - self.mapView.zoomLevel = [zoom doubleValue]; - XCTAssertEqual(self.mapView.zoomLevel, [zoom doubleValue], @"Map zoom should match z%@.", zoom); - - XCTAssertEqualWithAccuracy(originalCenterCoordinate.latitude, self.mapView.centerCoordinate.latitude, 0.0000001, "@Map center coordinate latitude should remain constant during zoom to z%@.", zoom); - XCTAssertEqualWithAccuracy(originalCenterCoordinate.longitude, self.mapView.centerCoordinate.longitude, 0.0000001, @"Map center coordinate longitude should remain constant during zoom to z%@.", zoom); - } -} - -- (void)testZoomEnabled { - UIPinchGestureRecognizerMock *gesture = [[UIPinchGestureRecognizerMock alloc] initWithTarget:nil action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - gesture.scale = 10.f; - [self.mapView handlePinchGesture:gesture]; - gesture.state = UIGestureRecognizerStateChanged; - - // Disabled - { - self.mapView.zoomEnabled = NO; - XCTAssertEqual(self.mapView.allowsZooming, NO); - - [self.mapView handlePinchGesture:gesture]; - XCTAssertNotEqual(self.mapView.zoomLevel, log2(gesture.scale), @"Gestural zoom should not work when zoom is disabled."); - - self.mapView.zoomLevel = 15.f; - XCTAssertEqualWithAccuracy(self.mapView.zoomLevel, 15, 0.001, @"Programmatic zoom is allowed when zoomEnabled = NO."); - } - - // Enabled - { - // No need to reset the map zoom or gesture scale, since gesture scale hasn't been applied yet and the map zoom will be overriden when the gesture is handled. - self.mapView.zoomEnabled = YES; - XCTAssertEqual(self.mapView.allowsZooming, YES); - - [self.mapView handlePinchGesture:gesture]; - XCTAssertEqualWithAccuracy(self.mapView.zoomLevel, log2(gesture.scale), 0.001, @"Gestural zoom should work when zoom is enabled."); - } -} - -- (void)testPinchGesture { - CLLocationCoordinate2D originalCenterCoordinate = self.mapView.centerCoordinate; - - UIPinchGestureRecognizerMock *gesture = [[UIPinchGestureRecognizerMock alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - gesture.scale = 0; - gesture.locationInViewOverride = self.mapView.center; - [self.mapView handlePinchGesture:gesture]; - XCTAssertEqual(self.mapView.zoomLevel, 0); - - for (NSNumber *zoom in @[@1, @5, @10, @15, @22]) { - gesture.state = UIGestureRecognizerStateChanged; - gesture.scale = MGLScaleFromZoomLevel([zoom doubleValue]); - [self.mapView handlePinchGesture:gesture]; - XCTAssertEqual(self.mapView.zoomLevel, [zoom doubleValue], @"Map zoom should match gesture to z%@.", zoom); - - // Given a hypothetical zoom into the exact center of the map, the center coordinate should remain the same. - XCTAssertEqualWithAccuracy(originalCenterCoordinate.latitude, self.mapView.centerCoordinate.latitude, 0.0000001, "@Map center coordinate latitude should remain constant during zoom to z%@.", zoom); - XCTAssertEqualWithAccuracy(originalCenterCoordinate.longitude, self.mapView.centerCoordinate.longitude, 0.0000001, @"Map center coordinate longitude should remain constant during zoom to z%@.", zoom); - } -} - -// Regression test for: https://github.com/mapbox/mapbox-gl-native/issues/14977 -- (void)testPinchGestureOffCenter { - self.mapView.zoomLevel = 15; - - // Set up pinch gesture at z15 with an origin of 0,0. - UIPinchGestureRecognizerMock *gesture = [[UIPinchGestureRecognizerMock alloc] initWithTarget:self.mapView action:nil]; - gesture.state = UIGestureRecognizerStateBegan; - gesture.scale = 0; - gesture.locationInViewOverride = CGPointMake(0, 0); - [self.mapView handlePinchGesture:gesture]; - XCTAssertEqual(self.mapView.zoomLevel, 15); - - // Set a map rotation so that we can later check if un-rotating happens around the correct center point. - self.mapView.direction = 45; - - // Zoom to z18 at the off-center origin. - gesture.state = UIGestureRecognizerStateChanged; - gesture.scale = MGLScaleFromZoomLevel(3); - [self.mapView handlePinchGesture:gesture]; - XCTAssertEqual(self.mapView.zoomLevel, 18, @"Map zoom should match original zoom plus gesture zoom."); - - // Check that the center coordinate remains the same when direction is reset to north. - CLLocationCoordinate2D centerCoordinateBeforeReset = self.mapView.centerCoordinate; - CLLocationCoordinate2D manuallyDerivedCenterCoordinate = [self.mapView convertPoint:self.mapView.center toCoordinateFromView:nil]; - XCTAssertEqualWithAccuracy(centerCoordinateBeforeReset.latitude, manuallyDerivedCenterCoordinate.latitude, 0.0000001, "@Map center latitude should be equal to manually derived latitude."); - XCTAssertEqualWithAccuracy(centerCoordinateBeforeReset.longitude, manuallyDerivedCenterCoordinate.longitude, 0.0000001, @"Map center longitude should be equal to manually derived longitude."); - - self.mapView.direction = 0; - XCTAssertEqualWithAccuracy(centerCoordinateBeforeReset.latitude, self.mapView.centerCoordinate.latitude, 0.0000001, "@Map center coordinate latitude should remain constant after resetting to north."); - 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); -} - -__unused NS_INLINE double MGLZoomLevelFromScale(CGFloat scale) { - return log2(scale); -} - -@end diff --git a/platform/ios/test/MGLMockGestureRecognizers.h b/platform/ios/test/MGLMockGestureRecognizers.h deleted file mode 100644 index 29889e39f4..0000000000 --- a/platform/ios/test/MGLMockGestureRecognizers.h +++ /dev/null @@ -1,29 +0,0 @@ - -#import <UIKit/UIKit.h> - -@interface UIPinchGestureRecognizerMock : UIPinchGestureRecognizer -@property (nonatomic, readwrite) CGFloat velocity; -@property (nonatomic) CGPoint locationInViewOverride; -@property(nonatomic, readwrite) UIGestureRecognizerState state; -@end - -@interface UIRotationGestureRecognizerMock : UIRotationGestureRecognizer -@property(nonatomic, readwrite) UIGestureRecognizerState state; -@end - -@interface UITapGestureRecognizerMock : UITapGestureRecognizer -@property (strong, nonatomic) UIView *mockTappedView; -@property (assign) CGPoint mockTappedPoint; -@end - -@interface UILongPressGestureRecognizerMock : UILongPressGestureRecognizer -@property(nonatomic, readwrite) UIGestureRecognizerState state; -@property (assign) CGPoint mockTappedPoint; -@end - -@interface UIPanGestureRecognizerMock : UIPanGestureRecognizer -@property(nonatomic, readwrite) UIGestureRecognizerState state; -@property (assign) CGPoint firstFingerPoint; -@property (assign) CGPoint secondFingerPoint; -@property(nonatomic, readwrite) NSUInteger numberOfTouches; -@end diff --git a/platform/ios/test/MGLMockGestureRecognizers.m b/platform/ios/test/MGLMockGestureRecognizers.m deleted file mode 100644 index c818805174..0000000000 --- a/platform/ios/test/MGLMockGestureRecognizers.m +++ /dev/null @@ -1,55 +0,0 @@ - -#import "MGLMockGestureRecognizers.h" -#import "objc/runtime.h" - -@implementation UIPinchGestureRecognizerMock -@synthesize velocity; -@synthesize state; -- (CGPoint)locationInView:(nullable UIView *)view { return self.locationInViewOverride; } -@end - -@implementation UIRotationGestureRecognizerMock -- (CGPoint)locationInView:(nullable UIView*)view { return view.center; } -@synthesize state; -@end - -@implementation UITapGestureRecognizerMock - -+ (void)load { - method_exchangeImplementations(class_getInstanceMethod(self, @selector(state)), - class_getInstanceMethod(self, @selector(mockState))); -} - -- (UIGestureRecognizerState)mockState { - return UIGestureRecognizerStateRecognized; -} - -- (UIView *)view { - return self.mockTappedView; -} - -- (CGPoint)locationInView:(UIView *)view { - return self.mockTappedPoint; -} - -@end - -@implementation UILongPressGestureRecognizerMock -@synthesize state; - -- (CGPoint)locationInView:(UIView *)view { - return self.mockTappedPoint; -} -@end - -@implementation UIPanGestureRecognizerMock -@synthesize state; -@synthesize numberOfTouches; - -- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view { - if (touchIndex) { - return self.secondFingerPoint; - } - return self.firstFingerPoint; -} -@end diff --git a/platform/ios/test/MGLNSOrthographyAdditionsTests.m b/platform/ios/test/MGLNSOrthographyAdditionsTests.m deleted file mode 100644 index f30553e8f6..0000000000 --- a/platform/ios/test/MGLNSOrthographyAdditionsTests.m +++ /dev/null @@ -1,19 +0,0 @@ -#import <XCTest/XCTest.h> - -#import "NSOrthography+MGLAdditions.h" -#import "MGLVectorTileSource_Private.h" - -@interface MGLNSOrthographyAdditionsTests : XCTestCase - -@end - -@implementation MGLNSOrthographyAdditionsTests - -- (void)testStreetsLanguages { - for (NSString *language in [MGLVectorTileSource mapboxStreetsLanguages]) { - NSString *dominantScript = [NSOrthography mgl_dominantScriptForMapboxStreetsLanguage:language]; - XCTAssertNotEqualObjects(dominantScript, @"Zyyy", @"Mapbox Streets languages should have dominant script"); - } -} - -@end diff --git a/platform/ios/test/MGLNetworkConfigurationTests.m b/platform/ios/test/MGLNetworkConfigurationTests.m deleted file mode 100644 index bfb63f57af..0000000000 --- a/platform/ios/test/MGLNetworkConfigurationTests.m +++ /dev/null @@ -1,43 +0,0 @@ -#import <Mapbox/Mapbox.h> -#import <XCTest/XCTest.h> -#import "MGLNetworkConfiguration_Private.h" - -@interface MGLNetworkConfigurationTests : XCTestCase -@end - -@implementation MGLNetworkConfigurationTests - -// Regression test for https://github.com/mapbox/mapbox-gl-native/issues/14982 -- (void)testAccessingEventsFromMultipleThreads { - MGLNetworkConfiguration *configuration = [[MGLNetworkConfiguration alloc] init]; - - // Concurrent - dispatch_queue_t queue = dispatch_queue_create("com.mapbox.testAccessingEventsFromMultipleThreads", DISPATCH_QUEUE_CONCURRENT); - - NSUInteger numberOfConcurrentBlocks = 20; - - XCTestExpectation *expectation = [self expectationWithDescription:@"wait-for-threads"]; - expectation.expectedFulfillmentCount = numberOfConcurrentBlocks; - - for (NSUInteger i = 0; i < numberOfConcurrentBlocks; i++) { - - NSString *event = [NSString stringWithFormat:@"test://event-%ld", i]; - NSString *resourceType = @"test"; - - dispatch_async(queue, ^{ - [configuration startDownloadEvent:event type:resourceType]; - - NSURL *url = [NSURL URLWithString:event]; - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:url MIMEType:nil expectedContentLength:0 textEncodingName:nil]; - - [configuration stopDownloadEventForResponse:response]; - - dispatch_async(dispatch_get_main_queue(), ^{ - [expectation fulfill]; - }); - }); - } - - [self waitForExpectations:@[expectation] timeout:10.0]; -} -@end |