summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-09-17 09:57:05 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-09-17 09:57:05 -0400
commitc7dbcf4ab6d5e60fb148cdbf306506be47e26f82 (patch)
treec22649cde596e0ea98df46e32432186d51e193cb
parent4f910734149b59e3babb5a4c22cc398f13ca4364 (diff)
downloadqtlocation-mapboxgl-upstream/jrex/snapshot-overlay-test-tweak.tar.gz
[ios] Fixed test name (since validAccessToken has been removed in another PR). Added some more asserts.upstream/jrex/snapshot-overlay-test-tweak
-rw-r--r--platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift18
-rw-r--r--platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m37
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);