From 62ea1f21858c69f6921c775ba7a3de201f0514d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 26 Jan 2017 18:52:44 +0100 Subject: [core] remove trailing whitespace, add trailing newlines, add space after // --- platform/darwin/test/MGLStyleTests.mm | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 176217619d..ed86a252fa 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -25,7 +25,7 @@ - (void)setUp { [super setUp]; - + [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) styleURL:styleURL]; @@ -39,14 +39,14 @@ - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { XCTAssertNotNil(mapView.style); XCTAssertEqual(mapView.style, style); - + [_styleLoadingExpectation fulfill]; } - (void)tearDown { _styleLoadingExpectation = nil; self.mapView = nil; - + [super tearDown]; } @@ -81,7 +81,7 @@ XCTAssertEqualObjects([MGLStyle satelliteStyleURLWithVersion:99].absoluteString, @"mapbox://styles/mapbox/satellite-v99"); XCTAssertEqualObjects([MGLStyle satelliteStreetsStyleURLWithVersion:MGLStyleDefaultVersion].absoluteString, @(mbgl::util::default_styles::satelliteStreets.url)); XCTAssertEqualObjects([MGLStyle satelliteStreetsStyleURLWithVersion:99].absoluteString, @"mapbox://styles/mapbox/satellite-streets-v99"); - + static_assert(6 == mbgl::util::default_styles::numOrderedStyles, "MGLStyleTests isn’t testing all the styles in mbgl::util::default_styles."); } @@ -109,17 +109,17 @@ XCTAssertEqual(mbgl::util::default_styles::numOrderedStyles, numVersionedMethods, @"There are %lu default styles but MGLStyleTests only provides versioned style URL methods for %u of them.", mbgl::util::default_styles::numOrderedStyles, numVersionedMethods); - + // Test that all the versioned style methods are in the public header. NSString *styleHeader = self.stringWithContentsOfStyleHeader; - + NSError *versionedMethodError; NSString *versionedMethodExpressionString = @(R"RE(^\+\s*\(NSURL\s*\*\s*\)\s*\w+StyleURLWithVersion\s*:\s*\(\s*NSInteger\s*\)\s*version\s*;)RE"); NSRegularExpression *versionedMethodExpression = [NSRegularExpression regularExpressionWithPattern:versionedMethodExpressionString options:NSRegularExpressionAnchorsMatchLines error:&versionedMethodError]; XCTAssertNil(versionedMethodError, @"Error compiling regular expression to search for versioned methods."); NSUInteger numVersionedMethodDeclarations = [versionedMethodExpression numberOfMatchesInString:styleHeader options:0 range:NSMakeRange(0, styleHeader.length)]; XCTAssertEqual(numVersionedMethodDeclarations, numVersionedMethods); - + // Test that “current version is” statements are present and current for all versioned style methods. NSError *versionError; NSString *versionExpressionString = @(R"RE(current version is `(\d+)`)RE"); @@ -219,15 +219,15 @@ } - (void)testAddingLayersWithDuplicateIdentifiers { - //Just some source + // Just some source MGLVectorSource *source = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" configurationURL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]]; [self.style addSource: source]; - - //Add initial layer + + // Add initial layer MGLFillStyleLayer *initial = [[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source]; [self.style addLayer:initial]; - - //Try to add the duplicate + + // Try to add the duplicate XCTAssertThrowsSpecificNamed([self.style addLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source]], NSException, @"MGLRedundantLayerIdentifierException"); XCTAssertThrowsSpecificNamed([self.style insertLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source] belowLayer:initial],NSException, @"MGLRedundantLayerIdentifierException"); XCTAssertThrowsSpecificNamed([self.style insertLayer:[[MGLFillStyleLayer alloc] initWithIdentifier:@"my-layer" source:source] aboveLayer:initial], NSException, @"MGLRedundantLayerIdentifierException"); @@ -259,10 +259,10 @@ MGLImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:imageName]; #endif XCTAssertNotNil(image); - + [self.style setImage:image forName:imageName]; MGLImage *styleImage = [self.style imageForName:imageName]; - + XCTAssertNotNil(styleImage); XCTAssertEqual(image.size.width, styleImage.size.width); XCTAssertEqual(image.size.height, styleImage.size.height); @@ -273,28 +273,28 @@ NSURL *url = [NSURL fileURLWithPath:filePath]; MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; [self.style addSource:source]; - + MGLCircleStyleLayer *layer1 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer1" source:source]; [self.style addLayer:layer1]; - + MGLCircleStyleLayer *layer3 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer3" source:source]; [self.style addLayer:layer3]; - + MGLCircleStyleLayer *layer2 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer2" source:source]; [self.style insertLayer:layer2 aboveLayer:layer1]; - + MGLCircleStyleLayer *layer4 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer4" source:source]; [self.style insertLayer:layer4 aboveLayer:layer3]; - + MGLCircleStyleLayer *layer0 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer0" source:source]; [self.style insertLayer:layer0 belowLayer:layer1]; - + NSArray *layers = [self.style layers]; NSUInteger startIndex = 0; if ([layers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) { startIndex++; } - + XCTAssertEqualObjects(layers[startIndex++].identifier, layer0.identifier); XCTAssertEqualObjects(layers[startIndex++].identifier, layer1.identifier); XCTAssertEqualObjects(layers[startIndex++].identifier, layer2.identifier); -- cgit v1.2.1 From 360e5bf631229e2aec71780a515a42e32d4c28e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 7 Feb 2017 18:26:49 -0800 Subject: [ios, macos] Fixed runtime styling deprecation warnings --- platform/darwin/test/MGLStyleTests.mm | 3 +++ 1 file changed, 3 insertions(+) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index ed86a252fa..c50330d488 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -246,7 +246,10 @@ } - (void)testClasses { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" XCTAssertEqual(self.style.styleClasses.count, 0); +#pragma clang diagnostic pop } - (void)testImages { -- cgit v1.2.1 From e860fa6f0a71805dafd03a1ac02980369b799f9e Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 14 Feb 2017 13:09:49 -0800 Subject: [ios, macos] Recreate pending and raw layer ref when layer is removed --- platform/darwin/test/MGLStyleTests.mm | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index c50330d488..7939db576e 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -235,6 +235,44 @@ XCTAssertThrowsSpecificNamed([self.style insertLayer:[[MGLOpenGLStyleLayer alloc] initWithIdentifier:@"my-layer"] atIndex:0], NSException, @"MGLRedundantLayerIdentifierException"); } + +- (void)testRemovingLayerBeforeAddingSameLayer { + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil]; + + // Attempting to find a layer with identifier will trigger an exception if the source associated with the layer is not added + [self.style addSource:source]; + + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:source]; + [self.style removeLayer:fillLayer]; + [self.style addLayer:fillLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:fillLayer.identifier]); + + MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"raster-layer" source:source]; + [self.style removeLayer:rasterLayer]; + [self.style addLayer:rasterLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:rasterLayer.identifier]); + + MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbol-layer" source:source]; + [self.style removeLayer:symbolLayer]; + [self.style addLayer:symbolLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:symbolLayer.identifier]); + + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"line-layer" source:source]; + [self.style removeLayer:lineLayer]; + [self.style addLayer:lineLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:lineLayer.identifier]); + + MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circle-layer" source:source]; + [self.style removeLayer:circleLayer]; + [self.style addLayer:circleLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:circleLayer.identifier]); + + MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"circle-layer"]; + [self.style removeLayer:backgroundLayer]; + [self.style addLayer:backgroundLayer]; + XCTAssertNotNil([self.style layerWithIdentifier:backgroundLayer.identifier]); +} + - (NSString *)stringWithContentsOfStyleHeader { NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL URLByAppendingPathComponent:@"Headers" isDirectory:YES] -- cgit v1.2.1 From c0718a863d0a915641857bc9cd4ff51cd508f222 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Mon, 20 Feb 2017 15:06:46 -0800 Subject: [core, ios, macos] Return null when removing nonexistent source --- platform/darwin/test/MGLStyleTests.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 7939db576e..86cf11d4aa 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -174,6 +174,23 @@ XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentifierException"); } +- (void)testRemovingSourcesBeforeAddingThem { + MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"raster-source" tileURLTemplates:@[] options:nil]; + [self.style removeSource:rasterSource]; + [self.style addSource:rasterSource]; + XCTAssertNotNil([self.style sourceWithIdentifier:rasterSource.identifier]); + + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source" shape:nil options:nil]; + [self.style removeSource:shapeSource]; + [self.style addSource:shapeSource]; + XCTAssertNotNil([self.style sourceWithIdentifier:shapeSource.identifier]); + + MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vector-source" tileURLTemplates:@[] options:nil]; + [self.style removeSource:vectorSource]; + [self.style addSource:vectorSource]; + XCTAssertNotNil([self.style sourceWithIdentifier:vectorSource.identifier]); +} + - (void)testLayers { NSArray *initialLayers = self.style.layers; if ([initialLayers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) { -- cgit v1.2.1 From 59820fb63d9970c1e2cda9cf950b819b79b1e7f7 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Mon, 20 Feb 2017 16:39:23 -0800 Subject: [ios, macos] Simplify implementation of layer removal from map view This reverts a previous change that recreated the pending and raw layer pointers if an identifier match caused a layer to be removed but the removed layer was of a different type than the layer triggering the removal This refactors the pointer replacement to use a simpler solution that returns early if the layer does not have a raw pointer loaded in the mbgl map instance. --- platform/darwin/test/MGLStyleTests.mm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 86cf11d4aa..4f6f5f0dba 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -284,12 +284,27 @@ [self.style addLayer:circleLayer]; XCTAssertNotNil([self.style layerWithIdentifier:circleLayer.identifier]); - MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"circle-layer"]; + MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"background-layer"]; [self.style removeLayer:backgroundLayer]; [self.style addLayer:backgroundLayer]; XCTAssertNotNil([self.style layerWithIdentifier:backgroundLayer.identifier]); } +- (void)testAddingLayerOfTypeABeforeRemovingLayerOfTypeBWithSameIdentifier { + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil]; + [self.style addSource:source]; + + // Add a fill layer with an identifer + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source]; + [self.style addLayer:fillLayer]; + + // Remove a line layer (before adding it) with the same identifier as the fill layer previously added + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source]; + [self.style removeLayer:lineLayer]; + + XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]); +} + - (NSString *)stringWithContentsOfStyleHeader { NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL URLByAppendingPathComponent:@"Headers" isDirectory:YES] -- cgit v1.2.1 From 7d9018093a61d327fa7ca1312845d2a00d928380 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Tue, 21 Feb 2017 10:30:21 -0800 Subject: [ios, macos] Make source removal consistent with layer removal This refactors the source removal methods to make them consistent with the way layers are removed. This makes removal of nonexistent sources and removal of sources of a different type but same identifier as a previously added source a no-ops. As with layers, the check at the top of the method to ensure that the raw pointer is the same as the one in mbgl for the same identifier string should make it impossible to attempt to remove a source of a different type than the one in mbgl for the same identifier. However, for consistency with the layer implementation, the reinterpret_cast has been replaced with a dynamic_cast and check for nullptr. --- platform/darwin/test/MGLStyleTests.mm | 42 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 4f6f5f0dba..36772e556d 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -191,6 +191,41 @@ XCTAssertNotNil([self.style sourceWithIdentifier:vectorSource.identifier]); } +- (void)testAddingSourceOfTypeABeforeSourceOfTypeBWithSameIdentifier { + // Add a raster source + MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"some-identifier" tileURLTemplates:@[] options:nil]; + [self.style addSource:rasterSource]; + + // Attempt to remove a shape source with the same identifier as the raster source + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"some-identifier" shape:nil options:nil]; + [self.style removeSource:shapeSource]; + // The raster source should still be added + XCTAssertTrue([[self.style sourceWithIdentifier:rasterSource.identifier] isMemberOfClass:[MGLRasterSource class]]); + + // Remove the raster source + [self.style removeSource:rasterSource]; + + // Add the shape source + [self.style addSource:shapeSource]; + + // Attempt to remove a vector source with the same identifer as the shape source + MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"some-identifier" tileURLTemplates:@[] options:nil]; + [self.style removeSource:vectorSource]; + // The shape source should still be added + XCTAssertTrue([[self.style sourceWithIdentifier:shapeSource.identifier] isMemberOfClass:[MGLShapeSource class]]); + + // Remove the shape source + [self.style removeSource:shapeSource]; + + // Add the vector source + [self.style addSource:vectorSource]; + + // Attempt to remove the previously created raster source that has the same identifer as the shape source + [self.style removeSource:rasterSource]; + // The vector source should still be added + XCTAssertTrue([[self.style sourceWithIdentifier:shapeSource.identifier] isMemberOfClass:[MGLVectorSource class]]); +} + - (void)testLayers { NSArray *initialLayers = self.style.layers; if ([initialLayers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) { @@ -252,7 +287,6 @@ XCTAssertThrowsSpecificNamed([self.style insertLayer:[[MGLOpenGLStyleLayer alloc] initWithIdentifier:@"my-layer"] atIndex:0], NSException, @"MGLRedundantLayerIdentifierException"); } - - (void)testRemovingLayerBeforeAddingSameLayer { MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil]; @@ -291,14 +325,14 @@ } - (void)testAddingLayerOfTypeABeforeRemovingLayerOfTypeBWithSameIdentifier { - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil]; [self.style addSource:source]; - // Add a fill layer with an identifer + // Add a fill layer MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source]; [self.style addLayer:fillLayer]; - // Remove a line layer (before adding it) with the same identifier as the fill layer previously added + // Attempt to remove a line layer with the same identifier as the fill layer MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source]; [self.style removeLayer:lineLayer]; -- cgit v1.2.1