This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julian Rex
committed
May 18, 2018
1 parent
1aa5c67
commit 2057327
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// MBShapeSourceTests.m | ||
// integration | ||
// | ||
// Created by Julian Rex on 4/5/18. | ||
// Copyright © 2018 Mapbox. All rights reserved. | ||
// | ||
|
||
#import "MGLMapViewIntegrationTest.h" | ||
|
||
@interface MBShapeSourceTests : MGLMapViewIntegrationTest | ||
@end | ||
|
||
@implementation MBShapeSourceTests | ||
|
||
- (void)testRepeatedlyChangingShapeSourceToNil { | ||
|
||
NSMutableArray *features = [[NSMutableArray alloc] init]; | ||
|
||
for (NSUInteger i = 0; i <= 180; i+=5) { | ||
CLLocationCoordinate2D coord[4] = { | ||
CLLocationCoordinate2DMake(round(0), round(i)), | ||
CLLocationCoordinate2DMake(round(20), round(i)), | ||
CLLocationCoordinate2DMake(round(0), round(i / 2 )), | ||
CLLocationCoordinate2DMake(round(20), round(i / 2))}; | ||
|
||
MGLPolygonFeature *feature = [MGLPolygonFeature polygonWithCoordinates:coord count:4]; | ||
[features addObject:feature]; | ||
} | ||
|
||
MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"source" features:features options:nil]; | ||
[self.style addSource:shapeSource]; | ||
|
||
MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layer" source:shapeSource]; | ||
layer.fillOpacity = [NSExpression expressionForConstantValue:@0.5]; | ||
[self.style addLayer:layer]; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"]; | ||
|
||
__weak typeof(self) weakself = self; | ||
__block NSInteger delegateCallCount; | ||
|
||
self.regionDidChange = ^(MGLMapView *mapView, BOOL animated) { | ||
|
||
MBShapeSourceTests *strongSelf = weakself; | ||
|
||
if (!strongSelf) | ||
return; | ||
|
||
delegateCallCount++; | ||
|
||
// Setting the shapeSource.shape = nil, was causing an infinite loop, so here | ||
// we check for a runaway call. 10 here is arbitrary. We could argue that this | ||
// should check that the call count is only 1, however in this case we particularly | ||
// want to check for the infinite loop. | ||
// See https://github.com/mapbox/mapbox-gl-native/issues/11180 | ||
|
||
if (delegateCallCount > 10) { | ||
XCTFail(); | ||
} | ||
else { | ||
shapeSource.shape = nil; | ||
} | ||
|
||
[NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil]; | ||
[expectation performSelector:@selector(fulfill) withObject:nil afterDelay:5.0]; | ||
}; | ||
|
||
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(10.0, 10.0)]; | ||
[self waitForExpectations:@[expectation] timeout:30.0]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters