summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@gmail.com>2018-04-10 14:56:38 -0400
committerGitHub <noreply@github.com>2018-04-10 14:56:38 -0400
commit80474b24f2cbb2a59022b964ed326d6efd20bbe7 (patch)
treea1f2d34a9fbd6e9a0fc3e58efdc16208a37d7ee8
parent4191c4bbcba5af5bf0e9ffb70bd2eaf25a83f166 (diff)
downloadqtlocation-mapboxgl-80474b24f2cbb2a59022b964ed326d6efd20bbe7.tar.gz
[ios] Refactor integrations tests
-rw-r--r--platform/ios/Integration Tests/MBGLIntegrationTests.m76
-rw-r--r--platform/ios/Integration Tests/MGLMapViewIntegrationTest.h20
-rw-r--r--platform/ios/Integration Tests/MGLMapViewIntegrationTest.m79
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj6
4 files changed, 113 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
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 53944bb14d..d2b6679b81 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -361,6 +361,7 @@
AC518E00201BB55A00EBC820 /* MGLTelemetryConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */; };
AC518E03201BB56000EBC820 /* MGLTelemetryConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */; };
AC518E04201BB56100EBC820 /* MGLTelemetryConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */; };
+ CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */; };
CA55CD41202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; };
CA55CD42202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; };
CAA69DA4206DCD0E007279CD /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA4A26961CB6E795000B7809 /* Mapbox.framework */; };
@@ -990,6 +991,8 @@
96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationHeadingIndicator.h; sourceTree = "<group>"; };
AC518DFD201BB55A00EBC820 /* MGLTelemetryConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLTelemetryConfig.h; sourceTree = "<group>"; };
AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLTelemetryConfig.m; sourceTree = "<group>"; };
+ CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewIntegrationTest.m; sourceTree = "<group>"; };
+ CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLMapViewIntegrationTest.h; sourceTree = "<group>"; };
CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCameraChangeReason.h; sourceTree = "<group>"; };
DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; };
DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; };
@@ -1335,6 +1338,8 @@
children = (
16376B091FFD9DAF0000563E /* MBGLIntegrationTests.m */,
16376B0B1FFD9DAF0000563E /* Info.plist */,
+ CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */,
+ CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */,
);
path = "Integration Tests";
sourceTree = "<group>";
@@ -2783,6 +2788,7 @@
buildActionMask = 2147483647;
files = (
16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */,
+ CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};