diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-01-11 21:00:51 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-01-12 08:19:29 -0800 |
commit | 13243ba26b9e5206dea76a84d9a41fa5e1cd6383 (patch) | |
tree | 856b190686aff66b0338df22ae59789be6032439 /platform | |
parent | 4aecb18f54aa01b2c6c33c7240fc6e0c7d1c8cb5 (diff) | |
download | qtlocation-mapboxgl-13243ba26b9e5206dea76a84d9a41fa5e1cd6383.tar.gz |
[ios, macos] Made style-related tests more robust
Removed UIViewController from MGLStyleLayerTests on iOS, because we aren’t really testing integration at that level. Switched to delegate-based expectation fulfillment for both MGLStyleLayerTests and MGLStyleTests, conditionalized on whether the style has already loaded, to avoid race conditions that bleed into other tests.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/test/MGLStyleLayerTests.m | 20 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleTests.mm | 41 |
2 files changed, 25 insertions, 36 deletions
diff --git a/platform/darwin/test/MGLStyleLayerTests.m b/platform/darwin/test/MGLStyleLayerTests.m index 11ca54022f..0bf5072391 100644 --- a/platform/darwin/test/MGLStyleLayerTests.m +++ b/platform/darwin/test/MGLStyleLayerTests.m @@ -14,20 +14,12 @@ [super setUp]; [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; -#if TARGET_OS_IPHONE - UIApplication *app = [UIApplication sharedApplication]; - UIViewController *vc = [[UIViewController alloc] init]; - app.keyWindow.rootViewController = vc; - [vc view]; // Force load xib - _mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 256, 256) styleURL:styleURL]; - [vc.view addSubview:_mapView]; -#else - _mapView = [[MGLMapView alloc] initWithFrame:NSMakeRect(0, 0, 256, 256) styleURL:styleURL]; -#endif - _mapView.delegate = self; - XCTAssertNil(_mapView.style); - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self waitForExpectationsWithTimeout:1 handler:nil]; + self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 256, 256) styleURL:styleURL]; + self.mapView.delegate = self; + if (!self.mapView.style) { + _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + } } - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index b771ff0af6..82de27973b 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -1,18 +1,4 @@ -#import "MGLAccountManager.h" -#import "MGLMapView.h" -#import "MGLStyle_Private.h" -#import "MGLOpenGLStyleLayer.h" - -#import "MGLShapeSource.h" -#import "MGLRasterSource.h" -#import "MGLVectorSource.h" - -#import "MGLBackgroundStyleLayer.h" -#import "MGLCircleStyleLayer.h" -#import "MGLFillStyleLayer.h" -#import "MGLLineStyleLayer.h" -#import "MGLRasterStyleLayer.h" -#import "MGLSymbolStyleLayer.h" +#import <Mapbox/Mapbox.h> #import "NSBundle+MGLAdditions.h" @@ -26,14 +12,16 @@ #endif #import <objc/runtime.h> -@interface MGLStyleTests : XCTestCase +@interface MGLStyleTests : XCTestCase <MGLMapViewDelegate> @property (nonatomic) MGLMapView *mapView; @property (nonatomic) MGLStyle *style; @end -@implementation MGLStyleTests +@implementation MGLStyleTests { + XCTestExpectation *_styleLoadingExpectation; +} - (void)setUp { [super setUp]; @@ -41,14 +29,23 @@ [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; 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]; + self.mapView.delegate = self; + if (!self.mapView.style) { + _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + } +} + +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { + XCTAssertNotNil(mapView.style); + XCTAssertEqual(mapView.style, style); + XCTAssertNil(style.name); + + [_styleLoadingExpectation fulfill]; } - (void)tearDown { + _styleLoadingExpectation = nil; self.mapView = nil; [super tearDown]; |