From 7e8fe8e787cf43f08d28c3b809a26753387f96b1 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Tue, 24 Apr 2018 11:50:16 -0400 Subject: Refactored integration test. Consolidated unit tests. --- platform/darwin/test/MGLExpressionTests.mm | 19 +------ .../ios/Integration Tests/MGLEmptyStopsTests.m | 61 ---------------------- .../MGLStyleLayerIntegrationTests.m | 61 ++++++++++++++++++++++ platform/ios/ios.xcodeproj/project.pbxproj | 8 +-- 4 files changed, 67 insertions(+), 82 deletions(-) delete mode 100644 platform/ios/Integration Tests/MGLEmptyStopsTests.m create mode 100644 platform/ios/Integration Tests/MGLStyleLayerIntegrationTests.m diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 61d389f9f9..9c75dedaa3 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -710,30 +710,15 @@ using namespace std::string_literals; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } -} - -- (void)testInterpolationExpressionObjectWithEmptyStopsDictionary { { NSDictionary *stops = @{}; NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(x, 'cubic-bezier', { 0.42, 0, 0.58, 1 }, %@)", stops]; - @try { - (void)expression.mgl_jsonExpressionObject; - XCTFail(); - } - @catch (NSException *e){ - XCTAssert(e.name == NSInvalidArgumentException); - } + XCTAssertThrowsSpecificNamed(expression.mgl_jsonExpressionObject, NSException, NSInvalidArgumentException); } { NSDictionary *stops = @{}; NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, 11, %@)", stops]; - @try { - (void)expression.mgl_jsonExpressionObject; - XCTFail(); - } - @catch (NSException *e){ - XCTAssert(e.name == NSInvalidArgumentException); - } + XCTAssertThrowsSpecificNamed(expression.mgl_jsonExpressionObject, NSException, NSInvalidArgumentException); } } diff --git a/platform/ios/Integration Tests/MGLEmptyStopsTests.m b/platform/ios/Integration Tests/MGLEmptyStopsTests.m deleted file mode 100644 index 80a46aea6e..0000000000 --- a/platform/ios/Integration Tests/MGLEmptyStopsTests.m +++ /dev/null @@ -1,61 +0,0 @@ -#import "MGLMapViewIntegrationTest.h" - -@interface MGLEmptyStopsTests : MGLMapViewIntegrationTest - -@end - -@implementation MGLEmptyStopsTests - - -- (void)testEmptyStops { - // From https://www.mapbox.com/ios-sdk/examples/dds-circle-layer/ - self.mapView.centerCoordinate = CLLocationCoordinate2DMake(38.897,-77.039); - self.mapView.zoomLevel = 10.5; - - // "mapbox://examples.2uf7qges" is a map ID referencing a tileset. For more - // more information, see mapbox.com/help/define-map-id/ - MGLSource *source = [[MGLVectorTileSource alloc] initWithIdentifier:@"trees" configurationURL:[NSURL URLWithString:@"mapbox://examples.2uf7qges"]]; - - [self.mapView.style addSource:source]; - - MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier: @"tree-style" source:source]; - - // The source name from the source's TileJSON metadata: mapbox.com/api-documentation/#retrieve-tilejson-metadata - layer.sourceLayerIdentifier = @"yoshino-trees-a0puw5"; - - { - NSExpression *interpExpression = [NSExpression mgl_expressionForInterpolatingExpression:NSExpression.zoomLevelVariableExpression - withCurveType:MGLExpressionInterpolationModeLinear - parameters:nil - stops:[NSExpression expressionForConstantValue:@{}]]; - - @try { - layer.circleColor = interpExpression; - XCTFail(); - } - @catch (NSException *exception) { - XCTAssertNotNil(exception); - XCTAssert(exception.name == NSInvalidArgumentException); - } - } - - { - NSExpression *steppingExpression = [NSExpression mgl_expressionForSteppingExpression:NSExpression.zoomLevelVariableExpression - fromExpression:[NSExpression expressionForConstantValue:[UIColor greenColor]] - stops:[NSExpression expressionForConstantValue:@{}]]; - - @try { - layer.circleColor = steppingExpression; - XCTFail(); - } - @catch (NSException *exception) { - XCTAssertNotNil(exception); - XCTAssert(exception.name == NSInvalidArgumentException); - } - } - - [self.mapView.style addLayer:layer]; - [self waitForMapViewToBeRenderedWithTimeout:5.0]; -} - -@end diff --git a/platform/ios/Integration Tests/MGLStyleLayerIntegrationTests.m b/platform/ios/Integration Tests/MGLStyleLayerIntegrationTests.m new file mode 100644 index 0000000000..015a58d2d2 --- /dev/null +++ b/platform/ios/Integration Tests/MGLStyleLayerIntegrationTests.m @@ -0,0 +1,61 @@ +#import "MGLMapViewIntegrationTest.h" + +@interface MGLStyleLayerIntegrationTests : MGLMapViewIntegrationTest +@end + +@implementation MGLStyleLayerIntegrationTests + +- (MGLCircleStyleLayer*)setupCircleStyleLayer { + // Adapted from https://www.mapbox.com/ios-sdk/examples/dds-circle-layer/ + + // "mapbox://examples.2uf7qges" is a map ID referencing a tileset. For more + // more information, see mapbox.com/help/define-map-id/ + MGLSource *source = [[MGLVectorTileSource alloc] initWithIdentifier:@"trees" configurationURL:[NSURL URLWithString:@"mapbox://examples.2uf7qges"]]; + [self.mapView.style addSource:source]; + + MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier: @"tree-style" source:source]; + + // The source name from the source's TileJSON metadata: mapbox.com/api-documentation/#retrieve-tilejson-metadata + layer.sourceLayerIdentifier = @"yoshino-trees-a0puw5"; + + return layer; +} + +- (void)testForInterpolatingExpressionRenderCrashWithEmptyStops { + // Tests: https://github.com/mapbox/mapbox-gl-native/issues/9539 + // Adapted from https://www.mapbox.com/ios-sdk/examples/dds-circle-layer/ + self.mapView.centerCoordinate = CLLocationCoordinate2DMake(38.897,-77.039); + self.mapView.zoomLevel = 10.5; + + MGLCircleStyleLayer *layer = [self setupCircleStyleLayer]; + + NSExpression *interpExpression = [NSExpression mgl_expressionForInterpolatingExpression:NSExpression.zoomLevelVariableExpression + withCurveType:MGLExpressionInterpolationModeLinear + parameters:nil + stops:[NSExpression expressionForConstantValue:@{}]]; + + XCTAssertThrowsSpecificNamed((layer.circleColor = interpExpression), NSException, NSInvalidArgumentException); + + [self.mapView.style addLayer:layer]; + [self waitForMapViewToBeRenderedWithTimeout:1.0]; +} + +- (void)testForSteppingExpressionRenderCrashWithEmptyStops { + // Tests: https://github.com/mapbox/mapbox-gl-native/issues/9539 + // Adapted from https://www.mapbox.com/ios-sdk/examples/dds-circle-layer/ + self.mapView.centerCoordinate = CLLocationCoordinate2DMake(38.897,-77.039); + self.mapView.zoomLevel = 10.5; + + MGLCircleStyleLayer *layer = [self setupCircleStyleLayer]; + + NSExpression *steppingExpression = [NSExpression mgl_expressionForSteppingExpression:NSExpression.zoomLevelVariableExpression + fromExpression:[NSExpression expressionForConstantValue:[UIColor greenColor]] + stops:[NSExpression expressionForConstantValue:@{}]]; + + XCTAssertThrowsSpecificNamed((layer.circleColor = steppingExpression), NSException, NSInvalidArgumentException); + + [self.mapView.style addLayer:layer]; + [self waitForMapViewToBeRenderedWithTimeout:1.0]; +} + +@end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 90e3f1a725..6892760f59 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -362,7 +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 */; }; - CA4EB8C720863487006AB465 /* MGLEmptyStopsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4EB8C620863487006AB465 /* MGLEmptyStopsTests.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, ); }; }; CAA69DA4206DCD0E007279CD /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA4A26961CB6E795000B7809 /* Mapbox.framework */; }; @@ -994,7 +994,7 @@ AC518DFE201BB55A00EBC820 /* MGLTelemetryConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLTelemetryConfig.m; sourceTree = ""; }; CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewIntegrationTest.m; sourceTree = ""; }; CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLMapViewIntegrationTest.h; sourceTree = ""; }; - CA4EB8C620863487006AB465 /* MGLEmptyStopsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLEmptyStopsTests.m; sourceTree = ""; }; + CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLStyleLayerIntegrationTests.m; sourceTree = ""; }; CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCameraChangeReason.h; sourceTree = ""; }; DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; @@ -1347,7 +1347,7 @@ 16376B0B1FFD9DAF0000563E /* Info.plist */, CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */, CA0C27952076CA50001CE5B7 /* MGLMapViewIntegrationTest.h */, - CA4EB8C620863487006AB465 /* MGLEmptyStopsTests.m */, + CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */, ); path = "Integration Tests"; sourceTree = ""; @@ -2796,7 +2796,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CA4EB8C720863487006AB465 /* MGLEmptyStopsTests.m in Sources */, + CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */, 16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */, CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */, ); -- cgit v1.2.1