summaryrefslogtreecommitdiff
path: root/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift')
-rw-r--r--platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift62
1 files changed, 62 insertions, 0 deletions
diff --git a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift
new file mode 100644
index 0000000000..bbdfce7531
--- /dev/null
+++ b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterSwiftTests.swift
@@ -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)
+ }
+}