summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2016-12-02 13:47:48 -0800
committerJesse Bounds <jesse@rebounds.net>2016-12-02 14:21:05 -0800
commit179e9c610fcc771f0c94db09cda720aabc28b752 (patch)
treecd2fa5c039c0402cc440d3d00072b588cda2d206 /platform/darwin
parent1db0a96927d53bc0216d48cf5add1254ae6cab89 (diff)
downloadqtlocation-mapboxgl-179e9c610fcc771f0c94db09cda720aabc28b752.tar.gz
[ios, macos] Consolidate tests of MGLStyle addSource in MGLStyleTests
This replaces the integration test of `addSource` when duplicate identifiers are used in `MGLSourceTests` with a more direct unit test in the style class's unit test file `MGLStyleTests`. Although tests of the case where the same instance are actually integration tests where the source instance itself throws, it is easier to test all of this functionality in one place using the public facing MGLStyle API.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLStyle.mm2
-rw-r--r--platform/darwin/test/MGLStyleTests.mm60
2 files changed, 38 insertions, 24 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index a722c993a7..56dc4ad8f7 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -187,7 +187,7 @@ static NSURL *MGLStyleURL_emerald;
try {
[source addToMapView:self.mapView];
} catch (std::runtime_error & err) {
- [NSException raise:@"Could not add source" format:@"%s", err.what()];
+ [NSException raise:@"MGLRedundantSourceIdentiferException" format:@"%s", err.what()];
}
}
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 6a6a4a827f..4c0c163b38 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -20,10 +20,21 @@
#import <objc/runtime.h>
@interface MGLStyleTests : XCTestCase
+
+@property (nonatomic) MGLMapView *mapView;
+@property (nonatomic) MGLStyle *style;
+
@end
@implementation MGLStyleTests
+- (void)setUp {
+ [super setUp];
+
+ self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
+ self.style = [[MGLStyle alloc] initWithMapView:self.mapView];
+}
+
- (void)testUnversionedStyleURLs {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -105,50 +116,53 @@
}
- (void)testAddingSourcesTwice {
- MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
- MGLStyle *style = [[MGLStyle alloc] initWithMapView:mapView];
-
MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil];
- [style addSource:geoJSONSource];
- XCTAssertThrowsSpecificNamed([style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException");
+ [self.style addSource:geoJSONSource];
+ XCTAssertThrowsSpecificNamed([self.style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException");
MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" URL:[NSURL new] tileSize:42];
- [style addSource:rasterSource];
- XCTAssertThrowsSpecificNamed([style addSource:rasterSource], NSException, @"MGLRedundantSourceException");
+ [self.style addSource:rasterSource];
+ XCTAssertThrowsSpecificNamed([self.style addSource:rasterSource], NSException, @"MGLRedundantSourceException");
MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vectorSource" URL:[NSURL new]];
- [style addSource:vectorSource];
- XCTAssertThrowsSpecificNamed([style addSource:vectorSource], NSException, @"MGLRedundantSourceException");
+ [self.style addSource:vectorSource];
+ XCTAssertThrowsSpecificNamed([self.style addSource:vectorSource], NSException, @"MGLRedundantSourceException");
+}
+
+- (void)testAddingSourcesWithDuplicateIdentifiers {
+ 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.style addSource: source1];
+ XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentiferException");
}
- (void)testAddingLayersTwice {
- MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
- MGLStyle *style = [[MGLStyle alloc] initWithMapView:mapView];
MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil];
MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"backgroundLayer"];
- [style addLayer:backgroundLayer];
- XCTAssertThrowsSpecificNamed([style addLayer:backgroundLayer], NSException, @"MGLRedundantLayerException");
+ [self.style addLayer:backgroundLayer];
+ XCTAssertThrowsSpecificNamed([self.style addLayer:backgroundLayer], NSException, @"MGLRedundantLayerException");
MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circleLayer" source:source];
- [style addLayer:circleLayer];
- XCTAssertThrowsSpecificNamed([style addLayer:circleLayer], NSException, @"MGLRedundantLayerException");
+ [self.style addLayer:circleLayer];
+ XCTAssertThrowsSpecificNamed([self.style addLayer:circleLayer], NSException, @"MGLRedundantLayerException");
MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:source];
- [style addLayer:fillLayer];
- XCTAssertThrowsSpecificNamed([style addLayer:fillLayer], NSException, @"MGLRedundantLayerException");
+ [self.style addLayer:fillLayer];
+ XCTAssertThrowsSpecificNamed([self.style addLayer:fillLayer], NSException, @"MGLRedundantLayerException");
MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"lineLayer" source:source];
- [style addLayer:lineLayer];
- XCTAssertThrowsSpecificNamed([style addLayer:lineLayer], NSException, @"MGLRedundantLayerException");
+ [self.style addLayer:lineLayer];
+ XCTAssertThrowsSpecificNamed([self.style addLayer:lineLayer], NSException, @"MGLRedundantLayerException");
MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"rasterLayer" source:source];
- [style addLayer:rasterLayer];
- XCTAssertThrowsSpecificNamed([style addLayer:rasterLayer], NSException, @"MGLRedundantLayerException");
+ [self.style addLayer:rasterLayer];
+ XCTAssertThrowsSpecificNamed([self.style addLayer:rasterLayer], NSException, @"MGLRedundantLayerException");
MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbolLayer" source:source];
- [style addLayer:symbolLayer];
- XCTAssertThrowsSpecificNamed([style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException");
+ [self.style addLayer:symbolLayer];
+ XCTAssertThrowsSpecificNamed([self.style addLayer:symbolLayer], NSException, @"MGLRedundantLayerException");
}
- (NSString *)stringWithContentsOfStyleHeader {