From d8cef7850293bb801778c82d2d196cdeb22862f5 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Mon, 28 Nov 2016 18:15:50 +0200 Subject: [ios, macos] handle duplicate source error --- platform/darwin/src/MGLStyle.mm | 6 +++++- platform/ios/ios.xcodeproj/project.pbxproj | 4 ++++ platform/ios/test/MGLSourceTests.m | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 platform/ios/test/MGLSourceTests.m diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 20c1917065..6da3cae3df 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -223,7 +223,11 @@ static NSURL *MGLStyleURL_emerald; source]; } - [source addToMapView:self.mapView]; + try { + [source addToMapView:self.mapView]; + } catch (std::runtime_error & err) { + [NSException raise:@"Could not add source" format:@"%s", err.what()]; + } } - (void)removeSource:(MGLSource *)source diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index ea6bc03227..e8e246907a 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -161,6 +161,7 @@ 7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; }; 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; + 92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */; }; DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */; }; @@ -584,6 +585,7 @@ 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; }; 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; + 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceTests.m; sourceTree = ""; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA17BE2F1CC4BAC300402C41 /* MGLMapView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Private.h; sourceTree = ""; }; DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -890,6 +892,7 @@ children = ( 3575798F1D513EF1000B822E /* Layers */, 35B8E08B1D6C8B5100E768D2 /* MGLFilterTests.mm */, + 92BE56761DEDD44500A4F2B6 /* MGLSourceTests.m */, DA2207BE1DC0805F0002F84D /* MGLStyleValueTests.swift */, 40CFA64E1D78754A008103BD /* Sources */, DA2207BD1DC0805F0002F84D /* test-Bridging-Header.h */, @@ -1899,6 +1902,7 @@ 357579831D502AE6000B822E /* MGLRasterStyleLayerTests.m in Sources */, 353D23961D0B0DFE002BE09D /* MGLAnnotationViewTests.m in Sources */, 35E208A71D24210F00EC9A46 /* MGLNSDataAdditionsTests.m in Sources */, + 92BE56771DEDD44500A4F2B6 /* MGLSourceTests.m in Sources */, DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/platform/ios/test/MGLSourceTests.m b/platform/ios/test/MGLSourceTests.m new file mode 100644 index 0000000000..90ec4e3a0b --- /dev/null +++ b/platform/ios/test/MGLSourceTests.m @@ -0,0 +1,24 @@ +#import "MGLMapViewTests.h" + +@interface MGLSourceTests : MGLMapViewTests + +@end + +@implementation MGLSourceTests + +- (void)testDuplicateSources { + MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; + MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; + + [self.mapView.style addSource: source1]; + + @try { + [self.mapView.style addSource: source2]; + XCTFail(@"Should not have reached this point"); + } + @catch (NSException *e) { + XCTAssertNotNil(e, @"Should have thrown an exception"); + } +} + +@end -- cgit v1.2.1