diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-03-16 23:19:10 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2018-05-17 17:16:19 -0400 |
commit | 954c4a64d1e751077e7f3fc86720674d753810db (patch) | |
tree | 1fdfce2fa9580555d14350ad4f60a54dbd2dd64f | |
parent | 1aa5c67837a19d5f8ba8f7336f183da83e68441c (diff) | |
download | qtlocation-mapboxgl-954c4a64d1e751077e7f3fc86720674d753810db.tar.gz |
[ios] Added (failing) test for latlon (-90, 0) that raises an exception when addAnnotation is called.
-rw-r--r-- | platform/ios/test/MGLAnnotationViewTests.m | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/platform/ios/test/MGLAnnotationViewTests.m b/platform/ios/test/MGLAnnotationViewTests.m index a2cc4227ed..43bcf826c2 100644 --- a/platform/ios/test/MGLAnnotationViewTests.m +++ b/platform/ios/test/MGLAnnotationViewTests.m @@ -237,8 +237,62 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations"); } +- (void)testAddAnnotationWithBoundaryCoordinates +{ + typedef struct { + CLLocationDegrees lat; + CLLocationDegrees lon; + BOOL expectation; + } TestParam; + + TestParam params[] = { + // Lat Lon Valid + { -91.0, 0.0, NO}, + { -90.0, 0.0, YES}, // THIS ONE CURRENTLY FAILS + { 90.0, 0.0, YES}, + { 91.0, 0.0, NO}, + + { 0.0, -181.0, NO}, + { 0.0, -180.0, YES}, + { 0.0, 180.0, YES}, + { 0.0, 181.0, NO}, + }; + + for (int i = 0; i < sizeof(params)/sizeof(params[0]); i++) { + TestParam param = params[i]; + + // Essentially a deconstructed -[MGLMapView convertCoordinate:toPointToView] + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(param.lat, param.lon); + NSString *coordDesc = [NSString stringWithFormat:@"(%0.1f,%0.1f)", param.lat, param.lon]; + + XCTAssert(CLLocationCoordinate2DIsValid(coordinate) == param.expectation, @"Unexpected valid result for coordinate %@", coordDesc); + + CGPoint point = [_mapView convertCoordinate:coordinate toPointToView:_mapView]; + (void)point; + XCTAssert(isnan(point.x) != param.expectation, @"Unexpected point.x for coordinate %@", coordDesc); + XCTAssert(isnan(point.y) != param.expectation, @"Unexpected point.y for coordinate %@", coordDesc); + + if (param.expectation) { + // If we expect a valid coordinate, let's finally try to add an annotation + + // The above method is called by the following, which will trigger CALayer to raise an + // exception + MGLTestAnnotation *annotation = [[MGLTestAnnotation alloc] init]; + annotation.coordinate = coordinate; + + @try { + [_mapView addAnnotation:annotation]; + } + @catch (NSException *e) { + XCTFail("addAnnotation triggered exception: %@ for coordinate %@", e, coordDesc); + } + } + } +} + #pragma mark - MGLMapViewDelegate - + - (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation { MGLAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:MGLTestAnnotationReuseIdentifer]; |