summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2019-02-18 17:31:55 -0800
committerJason Wray <jason@mapbox.com>2019-02-18 17:46:41 -0800
commit58817c8607138dad411f6041685fb476c7708882 (patch)
tree6a404d76592ec295aa4f58852fcfd7c5ef34e52e
parent1fc7a9b82ea0c064c20247f0902b3854fff1942f (diff)
downloadqtlocation-mapboxgl-58817c8607138dad411f6041685fb476c7708882.tar.gz
[ios] Mock MGLOfflineStorage in MGLDocumentationExampleTests
Otherwise we kick-off long-running offline pack downloads that could interfere with other tests.
-rw-r--r--platform/darwin/src/MGLOfflinePack.h2
-rw-r--r--platform/darwin/test/MGLDocumentationExampleTests.swift20
2 files changed, 18 insertions, 4 deletions
diff --git a/platform/darwin/src/MGLOfflinePack.h b/platform/darwin/src/MGLOfflinePack.h
index 7b241e0248..c2983331f7 100644
--- a/platform/darwin/src/MGLOfflinePack.h
+++ b/platform/darwin/src/MGLOfflinePack.h
@@ -106,7 +106,7 @@ typedef struct __attribute__((objc_boxable)) MGLOfflinePackProgress {
### Example
```swift
- MGLOfflineStorage.shared.addPack(for: region, withContext: context!) { (pack, error) in
+ MGLOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in
guard error == nil else {
// If download fails, log the error to the console
print("Error: \(error?.localizedDescription ?? "unknown error")")
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift
index 9d1d848868..efd696d8c3 100644
--- a/platform/darwin/test/MGLDocumentationExampleTests.swift
+++ b/platform/darwin/test/MGLDocumentationExampleTests.swift
@@ -29,6 +29,14 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
var styleLoadingExpectation: XCTestExpectation!
static let styleURL = Bundle(for: MGLDocumentationExampleTests.self).url(forResource: "one-liner", withExtension: "json")!
+ // Mock MGLOfflineStorage singleton so that it doesn't start long-running tasks that could interfere with other tests.
+ fileprivate class MGLOfflineStorageMock {
+ static let shared = MGLOfflineStorageMock()
+ func addPack(for: MGLOfflineRegion, withContext: Data, completionHandler: MGLOfflinePackAdditionCompletionHandler? = nil) {
+ XCTAssert(MGLOfflineStorage.shared.responds(to: #selector(MGLOfflineStorage.shared.addPack(for:withContext:completionHandler:))))
+ }
+ }
+
override func setUp() {
super.setUp()
mapView = MGLMapView(frame: CGRect(x: 0, y: 0, width: 256, height: 256), styleURL: MGLDocumentationExampleTests.styleURL)
@@ -66,6 +74,8 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
}
}
+ typealias MGLOfflineStorage = MGLOfflineStorageMock
+
//#-example-code
let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592)
let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896)
@@ -85,6 +95,8 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
return MGLDocumentationExampleTests.styleURL
}
}
+
+ typealias MGLOfflineStorage = MGLOfflineStorageMock
//#-example-code
var coordinates = [
@@ -103,14 +115,16 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
}
func testMGLOfflinePack() {
+ typealias MGLOfflineStorage = MGLOfflineStorageMock
+
let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592)
let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896)
let bbox = MGLCoordinateBounds(sw: southwest, ne: northeast)
- let region = MGLTilePyramidOfflineRegion(styleURL: MGLStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14)
- let context = "Tile Pyramid Region".data(using: .utf8)
+ let region = MGLTilePyramidOfflineRegion(styleURL: MGLDocumentationExampleTests.styleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14)
+ let context = "Tile Pyramid Region".data(using: .utf8)!
//#-example-code
- MGLOfflineStorage.shared.addPack(for: region, withContext: context!) { (pack, error) in
+ MGLOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in
guard error == nil else {
// If download fails, log the error to the console
print("Error: \(error?.localizedDescription ?? "unknown error")")