diff options
author | Julian Rex <julian.rex@mapbox.com> | 2019-09-17 16:18:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-17 16:18:14 -0400 |
commit | fc7d2938dd7352055ed0562db5235c97e5a01745 (patch) | |
tree | 1e4e06d02c30176e1f2600e0691b4b35862049f5 | |
parent | 634c95c8d91a0833272557a76ec189780b20a284 (diff) | |
download | qtlocation-mapboxgl-fc7d2938dd7352055ed0562db5235c97e5a01745.tar.gz |
[ios] Fixed test name (since validAccessToken has been removed in another PR). Added some more asserts. (#15643)
-rw-r--r-- | platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift | 18 | ||||
-rw-r--r-- | platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m | 37 |
2 files changed, 42 insertions, 13 deletions
diff --git a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift index c3400b1fa2..d33a986beb 100644 --- a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift +++ b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift @@ -56,4 +56,22 @@ class MGLMapSnapshotterSwiftTests: MGLMapViewIntegrationTest { wait(for: [expectation], timeout: timeout) } + + func testSnapshotOverlaySwiftErgonomics🔒() { + let options = MGLMapSnapshotterSwiftTests.snapshotterOptions(size: mapView.bounds.size) + let snapshotter = MGLMapSnapshotter(options: options) + let expectation = self.expectation(description: "snapshot") + expectation.expectedFulfillmentCount = 2 + + snapshotter.start(overlayHandler: { (overlay) in + guard let _ = overlay.context.makeImage() else { + XCTFail() + return + } + expectation.fulfill() + }) { (_, _) in + expectation.fulfill() + } + wait(for: [expectation], timeout: 10) + } } diff --git a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m index 7707896203..19718165b3 100644 --- a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m +++ b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m @@ -393,11 +393,7 @@ MGLMapSnapshotter* snapshotterWithCoordinates(CLLocationCoordinate2D coordinates [self waitForExpectations:@[expectation] timeout:10.0]; } -- (void)testSnapshotWithOverlayHandlerFailure { - if (![self validAccessToken]) { - return; - } - +- (void)testSnapshotWithOverlayHandlerFailure🔒 { CGSize size = self.mapView.bounds.size; XCTestExpectation *expectation = [self expectationWithDescription:@"snapshot with overlay fails"]; @@ -408,23 +404,25 @@ MGLMapSnapshotter* snapshotterWithCoordinates(CLLocationCoordinate2D coordinates MGLMapSnapshotter *snapshotter = snapshotterWithCoordinates(coord, size); XCTAssertNotNil(snapshotter); - [snapshotter startWithOverlayHandler:^(MGLMapSnapshotOverlay * _Nullable snapshotOverlay) { + [snapshotter startWithOverlayHandler:^(MGLMapSnapshotOverlay *snapshotOverlay) { + XCTAssertNotNil(snapshotOverlay); + UIGraphicsEndImageContext(); [expectation fulfill]; } completionHandler:^(MGLMapSnapshot * _Nullable snapshot, NSError * _Nullable error) { XCTAssertNil(snapshot); XCTAssertNotNil(error); + XCTAssertEqualObjects(error.domain, MGLErrorDomain); + XCTAssertEqual(error.code, MGLErrorCodeSnapshotFailed); + XCTAssertEqualObjects(error.localizedDescription, @"Failed to generate composited snapshot."); + [expectation fulfill]; }]; [self waitForExpectations:@[expectation] timeout:10.0]; } -- (void)testSnapshotWithOverlayHandlerSuccess { - if (![self validAccessToken]) { - return; - } - +- (void)testSnapshotWithOverlayHandlerSuccess🔒 { CGSize size = self.mapView.bounds.size; CGRect snapshotRect = CGRectMake(0, 0, size.width, size.height); @@ -435,8 +433,21 @@ MGLMapSnapshotter* snapshotterWithCoordinates(CLLocationCoordinate2D coordinates MGLMapSnapshotter *snapshotter = snapshotterWithCoordinates(coord, size); XCTAssertNotNil(snapshotter); - - [snapshotter startWithOverlayHandler:^(MGLMapSnapshotOverlay * _Nullable snapshotOverlay) { + + CGFloat scale = snapshotter.options.scale; + + [snapshotter startWithOverlayHandler:^(MGLMapSnapshotOverlay *snapshotOverlay) { + XCTAssertNotNil(snapshotOverlay); + + CGFloat width = CGBitmapContextGetWidth(snapshotOverlay.context); + CGFloat height = CGBitmapContextGetHeight(snapshotOverlay.context); + + CGRect contextRect = CGContextConvertRectToDeviceSpace(snapshotOverlay.context, CGRectMake(0, 0, 1, 0)); + CGFloat scaleFromContext = contextRect.size.width; + XCTAssertEqual(scale, scaleFromContext); + XCTAssertEqual(width, size.width*scale); + XCTAssertEqual(height, size.height*scale); + CGContextSetFillColorWithColor(snapshotOverlay.context, [UIColor.greenColor CGColor]); CGContextSetAlpha(snapshotOverlay.context, 0.2); CGContextAddRect(snapshotOverlay.context, snapshotRect); |