diff options
author | Julian Rex <julian.rex@gmail.com> | 2018-04-10 14:56:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-10 14:56:38 -0400 |
commit | 80474b24f2cbb2a59022b964ed326d6efd20bbe7 (patch) | |
tree | a1f2d34a9fbd6e9a0fc3e58efdc16208a37d7ee8 /platform/ios/Integration Tests | |
parent | 4191c4bbcba5af5bf0e9ffb70bd2eaf25a83f166 (diff) | |
download | qtlocation-mapboxgl-80474b24f2cbb2a59022b964ed326d6efd20bbe7.tar.gz |
[ios] Refactor integrations tests
Diffstat (limited to 'platform/ios/Integration Tests')
3 files changed, 107 insertions, 68 deletions
diff --git a/platform/ios/Integration Tests/MBGLIntegrationTests.m b/platform/ios/Integration Tests/MBGLIntegrationTests.m index 7b82f41b57..4f42c5a13f 100644 --- a/platform/ios/Integration Tests/MBGLIntegrationTests.m +++ b/platform/ios/Integration Tests/MBGLIntegrationTests.m @@ -1,76 +1,16 @@ -#import <XCTest/XCTest.h> -#import <objc/message.h> -#import <Mapbox/Mapbox.h> - -@interface MBGLIntegrationTests : XCTestCase <MGLMapViewDelegate> - -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic) MGLStyle *style; +#import "MGLMapViewIntegrationTest.h" +@interface MBGLIntegrationTests : MGLMapViewIntegrationTest @end -@implementation MBGLIntegrationTests { - XCTestExpectation *_styleLoadingExpectation; - XCTestExpectation *_renderFinishedExpectation; -} - -#pragma mark - Setup/Teardown +@implementation MBGLIntegrationTests -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; - self.mapView.delegate = self; - if (!self.mapView.style) { - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self waitForExpectationsWithTimeout:1 handler:nil]; - } - - UIView *superView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; - [superView addSubview:self.mapView]; - UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; - [window addSubview:superView]; - [window makeKeyAndVisible]; -} - -- (void)tearDown { - _styleLoadingExpectation = nil; - self.mapView = nil; - self.style = nil; - - [super tearDown]; -} - -#pragma mark - MGLMapViewDelegate - -- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { - XCTAssertNotNil(mapView.style); - XCTAssertEqual(mapView.style, style); - - [_styleLoadingExpectation fulfill]; -} - -- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(__unused BOOL)fullyRendered { - [_renderFinishedExpectation fulfill]; - _renderFinishedExpectation = nil; -} - -#pragma mark - Utilities +#pragma mark - Tests - (void)waitForMapViewToBeRendered { - [self.mapView setNeedsDisplay]; - _renderFinishedExpectation = [self expectationWithDescription:@"Map view should be rendered"]; - [self waitForExpectations:@[_renderFinishedExpectation] timeout:1]; -} - -- (MGLStyle *)style { - return self.mapView.style; + [self waitForMapViewToBeRenderedWithTimeout:1]; } -#pragma mark - Tests - // This test does not strictly need to be in this test file/target. Including here for convenience. - (void)testOpenGLLayerDoesNotLeakWhenCreatedAndDestroyedWithoutAddingToStyle { MGLOpenGLStyleLayer *layer = [[MGLOpenGLStyleLayer alloc] initWithIdentifier:@"gl-layer"]; @@ -220,9 +160,9 @@ MGLStyleLayer *layer2 = [self.mapView.style layerWithIdentifier:@"gl-layer"]; NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; [self.mapView setStyleURL:styleURL]; - [self waitForExpectations:@[_styleLoadingExpectation] timeout:10]; + [self waitForExpectations:@[self.styleLoadingExpectation] timeout:10]; // At this point the C++ CustomLayer will have been destroyed, and the rawLayer pointer has been NULLed XCTAssert(weakLayer == layer2); @@ -245,7 +185,7 @@ XCTAssertNil(mapView2.style); - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; [self waitForExpectationsWithTimeout:1 handler:nil]; MGLOpenGLStyleLayer *layer = [[MGLOpenGLStyleLayer alloc] initWithIdentifier:@"gl-layer"]; diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h new file mode 100644 index 0000000000..ab5d2cc46f --- /dev/null +++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h @@ -0,0 +1,20 @@ +#import <XCTest/XCTest.h> +#import <Mapbox/Mapbox.h> + +#define TestFailWithSelf(myself, ...) \ + _XCTPrimitiveFail(myself, __VA_ARGS__) + +@interface MGLMapViewIntegrationTest : XCTestCase <MGLMapViewDelegate> +@property (nonatomic) MGLMapView *mapView; +@property (nonatomic) MGLStyle *style; +@property (nonatomic) XCTestExpectation *styleLoadingExpectation; +@property (nonatomic) XCTestExpectation *renderFinishedExpectation; +@property (nonatomic) void (^regionDidChange)(MGLMapView *mapView, BOOL animated); +@property (nonatomic) void (^regionIsChanging)(MGLMapView *mapView); + + + +// Utility methods +- (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout; +- (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout; +@end diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m new file mode 100644 index 0000000000..fc3229c83b --- /dev/null +++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m @@ -0,0 +1,79 @@ +#import "MGLMapViewIntegrationTest.h" + +@implementation MGLMapViewIntegrationTest + +- (void)setUp { + [super setUp]; + + [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; + NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + + self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; + self.mapView.delegate = self; + + UIView *superView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + [superView addSubview:self.mapView]; + UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; + [window addSubview:superView]; + [window makeKeyAndVisible]; + + if (!self.mapView.style) { + [self waitForMapViewToFinishLoadingStyleWithTimeout:1]; + } +} + +- (void)tearDown { + self.styleLoadingExpectation = nil; + self.renderFinishedExpectation = nil; + self.mapView = nil; + self.style = nil; + + [super tearDown]; +} + +#pragma mark - MGLMapViewDelegate + +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { + XCTAssertNotNil(mapView.style); + XCTAssertEqual(mapView.style, style); + + [self.styleLoadingExpectation fulfill]; +} + +- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(__unused BOOL)fullyRendered { + [self.renderFinishedExpectation fulfill]; + self.renderFinishedExpectation = nil; +} + +- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated { + if (self.regionDidChange) { + self.regionDidChange(mapView, animated); + } +} + +- (void)mapViewRegionIsChanging:(MGLMapView *)mapView { + if (self.regionIsChanging) { + self.regionIsChanging(mapView); + } +} + +#pragma mark - Utilities + +- (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout { + XCTAssertNil(self.styleLoadingExpectation); + self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self waitForExpectations:@[self.styleLoadingExpectation] timeout:timeout]; +} + +- (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout { + XCTAssertNil(self.renderFinishedExpectation); + [self.mapView setNeedsDisplay]; + self.renderFinishedExpectation = [self expectationWithDescription:@"Map view should be rendered"]; + [self waitForExpectations:@[self.renderFinishedExpectation] timeout:timeout]; +} + +- (MGLStyle *)style { + return self.mapView.style; +} + +@end |