From c7dbcf4ab6d5e60fb148cdbf306506be47e26f82 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Tue, 17 Sep 2019 09:57:05 -0400 Subject: [ios] Fixed test name (since validAccessToken has been removed in another PR). Added some more asserts. --- .../MGLMapSnapshotterSwiftTests.swift | 18 +++++++++++ .../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); -- cgit v1.2.1