From 43bcba4cbe2242d1c0aaefbdeed0906600589511 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Mon, 26 Feb 2018 11:11:27 -0500 Subject: [ios] Release only called if the layer is really being removed from the style. Update associated test that failed. --- platform/darwin/test/MGLStyleTests.mm | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'platform/darwin/test/MGLStyleTests.mm') diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 8f610e338c..5ab17dd62e 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -359,20 +359,41 @@ } - (void)testAddingLayerOfTypeABeforeRemovingLayerOfTypeBWithSameIdentifier { - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil]; - [self.style addSource:source]; - // Add a fill layer - MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source]; - [self.style addLayer:fillLayer]; + __weak MGLFillStyleLayer *weakFillLayer = nil; + __weak MGLLineStyleLayer *weakLineLayer = nil; - // 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]; + @autoreleasepool { + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil]; + [self.style addSource:source]; + + // Add a fill layer + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source]; + weakFillLayer = fillLayer; + + [self.style addLayer:fillLayer]; - XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]); + // Attempt to remove a line layer with the same identifier as the fill layer + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source]; + weakLineLayer = lineLayer; + [self.style removeLayer:lineLayer]; + + // The above remove should fail, and the fill layer should still be there. + XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]); + + // Finally remove the fill layer. + [self.style removeLayer:fillLayer]; + + fillLayer = nil; + lineLayer = nil; + } + + XCTAssertNil(weakFillLayer, @""); + XCTAssertNil(weakLineLayer, @""); } + - (NSString *)stringWithContentsOfStyleHeader { NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL URLByAppendingPathComponent:@"Headers" isDirectory:YES] -- cgit v1.2.1