summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-05-02 11:55:58 -0400
committerJulian Rex <julian.rex@mapbox.com>2018-05-02 11:55:58 -0400
commit3257d91763d72e559d27d08c657318571aab97f4 (patch)
tree1bc3585ac60b188cddbf568971188bd864d6a905
parent5a147f6335314defeed26c570ebcfe217e2af5d9 (diff)
downloadqtlocation-mapboxgl-upstream/jrex-11801-snapshotter.tar.gz
Added snapshotter testupstream/jrex-11801-snapshotter
-rw-r--r--platform/ios/Integration Tests/MGLMapViewIntegrationTest.h9
-rw-r--r--platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m78
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj12
3 files changed, 98 insertions, 1 deletions
diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
index ab5d2cc46f..e4a1e82878 100644
--- a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
+++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
@@ -1,9 +1,16 @@
#import <XCTest/XCTest.h>
#import <Mapbox/Mapbox.h>
-#define TestFailWithSelf(myself, ...) \
+#define MGLTestFailWithSelf(myself, ...) \
_XCTPrimitiveFail(myself, __VA_ARGS__)
+#define MGLTestAssertNil(myself, expression, ...) \
+ _XCTPrimitiveAssertNil(myself, expression, @#expression, __VA_ARGS__)
+
+#define MGLTestAssertNotNil(myself, expression, ...) \
+ _XCTPrimitiveAssertNotNil(myself, expression, @#expression, __VA_ARGS__)
+
+
@interface MGLMapViewIntegrationTest : XCTestCase <MGLMapViewDelegate>
@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) MGLStyle *style;
diff --git a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m
new file mode 100644
index 0000000000..8a395c4e36
--- /dev/null
+++ b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m
@@ -0,0 +1,78 @@
+#import "MGLMapViewIntegrationTest.h"
+
+@interface MGLMapSnapshotterTest : MGLMapViewIntegrationTest
+
+@end
+
+@implementation MGLMapSnapshotterTest
+
+- (MGLMapSnapshotter*)startSnapshotterWithCoordinates:(CLLocationCoordinate2D)coordinates completion:(MGLMapSnapshotCompletionHandler)completion {
+ // Create snapshot options
+ MGLMapCamera* mapCamera = [[MGLMapCamera alloc] init];
+ mapCamera.pitch = 20;
+ mapCamera.centerCoordinate = coordinates;
+ MGLMapSnapshotOptions* options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:[MGLStyle satelliteStreetsStyleURL]
+ camera:mapCamera
+ size:self.mapView.bounds.size];
+ options.zoomLevel = 10;
+
+ // Create and start the snapshotter
+ MGLMapSnapshotter* snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options];
+ [snapshotter startWithCompletionHandler:completion];
+
+ return snapshotter;
+}
+
+- (void)testMultipleSnapshotters {
+
+ NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"];
+ if (!accessToken) {
+ printf("warning: MAPBOX_ACCESS_TOKEN env var is required for this test - skipping.\n");
+ return;
+ }
+
+ [MGLAccountManager setAccessToken:accessToken];
+
+ NSUInteger numSnapshots = 20;
+ NSMutableArray *expectations = [NSMutableArray arrayWithCapacity:numSnapshots];
+ NSMutableSet *snapshots = [NSMutableSet setWithCapacity:numSnapshots];
+
+ __weak __typeof(self) weakself = self;
+ __block CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(30.0, 30.0);
+ for (NSInteger run = 0; run < numSnapshots; run++) {
+ NSString *expectationTitle = [NSString stringWithFormat:@"Snapshot %ld", run];
+ XCTestExpectation *expectation = [self expectationWithDescription:expectationTitle];
+ [expectations addObject:expectation];
+
+ MGLMapSnapshotter *snapshotter = [self startSnapshotterWithCoordinates:coordinates
+ completion:^(MGLMapSnapshot * _Nullable snapshot, NSError * _Nullable error) {
+
+ __typeof(self) strongself = weakself;
+ MGLTestAssertNotNil(strongself, strongself);
+
+ MGLTestAssertNotNil(strongself, snapshot);
+ MGLTestAssertNotNil(strongself, snapshot.image);
+ MGLTestAssertNil(strongself, error, @"Snapshot should not error with: %@", error);
+
+ // Change this back to XCTAttachmentLifetimeDeleteOnSuccess when we're sure this
+ // test is passing.
+ XCTAttachment *attachment = [XCTAttachment attachmentWithImage:snapshot.image];
+ attachment.lifetime = XCTAttachmentLifetimeKeepAlways;
+ [strongself addAttachment:attachment];
+
+ [snapshots addObject:snapshot];
+ [expectation fulfill];
+ }];
+
+ XCTAssertNotNil(snapshotter);
+
+ coordinates.latitude += 1.0;
+ coordinates.longitude += 1.0;
+ }
+
+ [self waitForExpectations:expectations timeout:60.0];
+
+ XCTAssert(snapshots.count == expectations.count);
+}
+
+@end
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 80335b8bf0..01bf420e14 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -362,6 +362,7 @@
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 */; };
+ CA1B4A512099FB2200EDD491 /* MGLMapSnapshotterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CA1B4A502099FB2200EDD491 /* MGLMapSnapshotterTest.m */; };
CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.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, ); }; };
@@ -992,6 +993,7 @@
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>"; };
+ CA1B4A502099FB2200EDD491 /* MGLMapSnapshotterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapSnapshotterTest.m; sourceTree = "<group>"; };
CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLStyleLayerIntegrationTests.m; 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>"; };
@@ -1340,6 +1342,7 @@
16376B081FFD9DAF0000563E /* Integration Tests */ = {
isa = PBXGroup;
children = (
+ CA1B4A4F2099FA2800EDD491 /* Snapshotter Tests */,
16376B091FFD9DAF0000563E /* MBGLIntegrationTests.m */,
16376B0B1FFD9DAF0000563E /* Info.plist */,
CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */,
@@ -1689,6 +1692,14 @@
name = Fixtures;
sourceTree = "<group>";
};
+ CA1B4A4F2099FA2800EDD491 /* Snapshotter Tests */ = {
+ isa = PBXGroup;
+ children = (
+ CA1B4A502099FB2200EDD491 /* MGLMapSnapshotterTest.m */,
+ );
+ path = "Snapshotter Tests";
+ sourceTree = "<group>";
+ };
DA1DC9411CB6C1C2006E619F = {
isa = PBXGroup;
children = (
@@ -2793,6 +2804,7 @@
CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */,
16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */,
CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */,
+ CA1B4A512099FB2200EDD491 /* MGLMapSnapshotterTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};