summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLStyleTests.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-01-11 08:06:20 -0800
committerGitHub <noreply@github.com>2017-01-11 08:06:20 -0800
commit424c12499cab69b935779d306d7d47d19139116e (patch)
tree56c27e57288a5df08083ede6b54db7204b46a02c /platform/darwin/test/MGLStyleTests.mm
parent581fb3849da8ce97e557bb3633b886fcc369f6cb (diff)
downloadqtlocation-mapboxgl-424c12499cab69b935779d306d7d47d19139116e.tar.gz
[ios, macos] Make MGLMapView.style property nullable (#7664)
* [ios, macos] Made MGLMapView.style property nullable MGLMapView’s style property is now nullable (optional in Swift). The property is set to nil while the style loads and in the event that the style has failed to load. * [ios, macos] Switch to delegate method * [macos] Create MGLMapView programmatically for layer tests When MGLMapView is created via a nib, -initWithCoder: is called, causing styleURL to be set to nil, in turn causing the default Streets style to be loaded, fooling MGLStyleLayerTests into thinking one-line has been loaded. Instead, create MGLMapView programmatically, passing the intended style URL into the initializer, preventing Streets from being loaded.
Diffstat (limited to 'platform/darwin/test/MGLStyleTests.mm')
-rw-r--r--platform/darwin/test/MGLStyleTests.mm22
1 files changed, 16 insertions, 6 deletions
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index bcad7ab508..b771ff0af6 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -39,7 +39,13 @@
[super setUp];
[MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];
- self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
+ NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
+ self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) styleURL:styleURL];
+ XCTAssertNil(self.mapView.style);
+ [self keyValueObservingExpectationForObject:self.mapView keyPath:@"style" handler:^BOOL(MGLMapView * _Nonnull observedMapView, NSDictionary * _Nonnull change) {
+ return observedMapView.style != nil;
+ }];
+ [self waitForExpectationsWithTimeout:1 handler:nil];
}
- (void)tearDown {
@@ -250,12 +256,16 @@
[self.style insertLayer:layer0 belowLayer:layer1];
NSArray<MGLStyleLayer *> *layers = [self.style layers];
+ NSUInteger startIndex = 0;
+ if ([layers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) {
+ startIndex++;
+ }
- XCTAssert([[layers[0] identifier] isEqualToString:layer0.identifier]);
- XCTAssert([[layers[1] identifier] isEqualToString:layer1.identifier]);
- XCTAssert([[layers[2] identifier] isEqualToString:layer2.identifier]);
- XCTAssert([[layers[3] identifier] isEqualToString:layer3.identifier]);
- XCTAssert([[layers[4] identifier] isEqualToString:layer4.identifier]);
+ XCTAssertEqualObjects(layers[startIndex++].identifier, layer0.identifier);
+ XCTAssertEqualObjects(layers[startIndex++].identifier, layer1.identifier);
+ XCTAssertEqualObjects(layers[startIndex++].identifier, layer2.identifier);
+ XCTAssertEqualObjects(layers[startIndex++].identifier, layer3.identifier);
+ XCTAssertEqualObjects(layers[startIndex++].identifier, layer4.identifier);
}
@end