This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Call snapshotter completion block with error if deallocated pri…
…or to snapshot completion
- Loading branch information
Julian Rex
committed
Jul 10, 2018
1 parent
ec8ac3c
commit 5e3478e
Showing
7 changed files
with
256 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import XCTest | ||
|
||
class MGLMapSnapshotterSwiftTests: MGLMapViewIntegrationTest { | ||
|
||
// Create snapshot options | ||
private class func snapshotterOptions(size: CGSize) -> MGLMapSnapshotOptions { | ||
let camera = MGLMapCamera() | ||
|
||
let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL, camera: camera, size: size) | ||
|
||
let sw = CLLocationCoordinate2D(latitude: 52.3, longitude: 13.0) | ||
let ne = CLLocationCoordinate2D(latitude: 52.5, longitude: 13.2) | ||
options.coordinateBounds = MGLCoordinateBounds(sw:sw, ne:ne) | ||
|
||
return options | ||
} | ||
|
||
func testCapturingSnapshotterInSnapshotCompletion() { | ||
// See the Obj-C testDeallocatingSnapshotterDuringSnapshot | ||
// This Swift test, is essentially the same except for capturing the snapshotter | ||
guard validAccessToken() != nil else { | ||
return | ||
} | ||
|
||
let timeout: TimeInterval = 5.0 | ||
let expectation = self.expectation(description: "snapshot") | ||
|
||
let options = MGLMapSnapshotterSwiftTests.snapshotterOptions(size: mapView.bounds.size) | ||
|
||
let backgroundQueue = DispatchQueue.main | ||
|
||
backgroundQueue.async { | ||
let dg = DispatchGroup() | ||
dg.enter() | ||
|
||
DispatchQueue.main.async { | ||
|
||
let snapshotter = MGLMapSnapshotter(options: options) | ||
|
||
snapshotter.start(completionHandler: { (snapshot, error) in | ||
|
||
// // Without capturing snapshotter: | ||
// XCTAssertNil(snapshot) | ||
// XCTAssertNotNil(error) | ||
|
||
// Capture snapshotter | ||
dump(snapshotter) | ||
XCTAssertNotNil(snapshot) | ||
XCTAssertNil(error) | ||
|
||
dg.leave() | ||
}) | ||
} | ||
|
||
dg.notify(queue: .main) { | ||
expectation.fulfill() | ||
} | ||
} | ||
|
||
wait(for: [expectation], timeout: timeout) | ||
} | ||
} |
Oops, something went wrong.