[ios] Fixed test name (since validAccessToken has been removed in another PR). Added some more asserts. (#15643)

This commit is contained in:
Julian Rex
2019-09-17 16:18:14 -04:00
committed by GitHub
parent 634c95c8d9
commit fc7d2938dd
2 changed files with 41 additions and 12 deletions

View File

@@ -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)
}
}

View File

@@ -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);
CGFloat scale = snapshotter.options.scale;
[snapshotter startWithOverlayHandler:^(MGLMapSnapshotOverlay *snapshotOverlay) {
XCTAssertNotNil(snapshotOverlay);
CGFloat width = CGBitmapContextGetWidth(snapshotOverlay.context);
CGFloat height = CGBitmapContextGetHeight(snapshotOverlay.context);
[snapshotter startWithOverlayHandler:^(MGLMapSnapshotOverlay * _Nullable snapshotOverlay) {
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);