diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2019-08-28 17:39:29 -0700 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2019-10-03 10:27:10 -0700 |
commit | 09e089952b3a290c23ff0e2c602b75801709515e (patch) | |
tree | cc99d6d7b7177d3f494cab34924544cc2da81cb7 | |
parent | daf8e1289c3c8b437c97e1ec4250b521fa6edc52 (diff) | |
download | qtlocation-mapboxgl-09e089952b3a290c23ff0e2c602b75801709515e.tar.gz |
[ios] Add mapView content inset tests.
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewContentInsetTests.m | 126 |
2 files changed, 130 insertions, 0 deletions
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 20001c26a8..447fb5976f 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ 170C437D2029D97900863DF0 /* MGLHeatmapStyleLayerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 170C43792028D49800863DF0 /* MGLHeatmapStyleLayerTests.mm */; }; 1753ED421E53CE6F00A9FD90 /* MGLConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1753ED411E53CE6F00A9FD90 /* MGLConversion.h */; }; 1753ED431E53CE6F00A9FD90 /* MGLConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1753ED411E53CE6F00A9FD90 /* MGLConversion.h */; }; + 1F0196AA23174B0700F5C819 /* MGLMapViewContentInsetTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F0196A923174B0700F5C819 /* MGLMapViewContentInsetTests.m */; }; 1F06668A1EC64F8E001C16D7 /* MGLLight.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F0666881EC64F8E001C16D7 /* MGLLight.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1F06668D1EC64F8E001C16D7 /* MGLLight.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F0666891EC64F8E001C16D7 /* MGLLight.mm */; }; 1F26B6C120E189C9007BCC21 /* MBXCustomLocationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F26B6C020E189C9007BCC21 /* MBXCustomLocationViewController.m */; }; @@ -897,6 +898,7 @@ 170C43782028D49800863DF0 /* MGLHeatmapColorTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLHeatmapColorTests.mm; path = ../../darwin/test/MGLHeatmapColorTests.mm; sourceTree = "<group>"; }; 170C43792028D49800863DF0 /* MGLHeatmapStyleLayerTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLHeatmapStyleLayerTests.mm; path = ../../darwin/test/MGLHeatmapStyleLayerTests.mm; sourceTree = "<group>"; }; 1753ED411E53CE6F00A9FD90 /* MGLConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLConversion.h; sourceTree = "<group>"; }; + 1F0196A923174B0700F5C819 /* MGLMapViewContentInsetTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewContentInsetTests.m; sourceTree = "<group>"; }; 1F0666881EC64F8E001C16D7 /* MGLLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight.h; sourceTree = "<group>"; }; 1F0666891EC64F8E001C16D7 /* MGLLight.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLLight.mm; sourceTree = "<group>"; }; 1F26B6BF20E189C9007BCC21 /* MBXCustomLocationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBXCustomLocationViewController.h; sourceTree = "<group>"; }; @@ -2081,6 +2083,7 @@ DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */, DA695425215B1E75002041A4 /* MGLMapCameraTests.m */, 96E6145522CC135200109F14 /* MGLMapViewCompassViewTests.mm */, + 1F0196A923174B0700F5C819 /* MGLMapViewContentInsetTests.m */, 96ED34DD22374C0900E9FCA9 /* MGLMapViewDirectionTests.mm */, 16376B481FFEED010000563E /* MGLMapViewLayoutTests.m */, 96381C0122C6F3950053497D /* MGLMapViewPitchTests.m */, @@ -3316,6 +3319,7 @@ 920A3E5D1E6F995200C16EFC /* MGLSourceQueryTests.m in Sources */, DA5DB12A1FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m in Sources */, 96ED34DE22374C0900E9FCA9 /* MGLMapViewDirectionTests.mm in Sources */, + 1F0196AA23174B0700F5C819 /* MGLMapViewContentInsetTests.m in Sources */, FAE1CDCB1E9D79CB00C40B5B /* MGLFillExtrusionStyleLayerTests.mm in Sources */, DA35A2AA1CCA058D00E826B2 /* MGLCoordinateFormatterTests.m in Sources */, 357579831D502AE6000B822E /* MGLRasterStyleLayerTests.mm in Sources */, diff --git a/platform/ios/test/MGLMapViewContentInsetTests.m b/platform/ios/test/MGLMapViewContentInsetTests.m new file mode 100644 index 0000000000..aa6f57cc0a --- /dev/null +++ b/platform/ios/test/MGLMapViewContentInsetTests.m @@ -0,0 +1,126 @@ +#import <Mapbox/Mapbox.h> +#import <XCTest/XCTest.h> + +@interface MGLMapViewContentInsetTests : XCTestCase <MGLMapViewDelegate> + +@property (nonatomic) MGLMapView *mapView; +@property (nonatomic) UIWindow *window; +@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; + + + UIView *view = [[UIView alloc] initWithFrame:self.screenBounds]; + [view addSubview:self.mapView]; + self.window = [[UIWindow alloc] initWithFrame:self.screenBounds]; + [self.window addSubview: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.mapView.automaticallyAdjustContentInset = YES; + 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)); + +} + +@end |