diff options
Diffstat (limited to 'platform/darwin/test')
-rw-r--r-- | platform/darwin/test/MGLGeoJSONSourceTests.mm | 82 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleTests.mm | 4 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleValueTests.swift | 4 |
3 files changed, 51 insertions, 39 deletions
diff --git a/platform/darwin/test/MGLGeoJSONSourceTests.mm b/platform/darwin/test/MGLGeoJSONSourceTests.mm index be8bb143ce..1b6da95a69 100644 --- a/platform/darwin/test/MGLGeoJSONSourceTests.mm +++ b/platform/darwin/test/MGLGeoJSONSourceTests.mm @@ -35,27 +35,40 @@ XCTAssertThrows([[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options]); } -- (void)testMGLGeoJSONSourceWithData { +- (void)testNilShape { + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"id" shape:nil options:nil]; + XCTAssertNil(source.shape); +} + +- (void)testMGLGeoJSONSourceWithDataMultipleFeatures { NSString *geoJSON = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}"; NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding]; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" geoJSONData:data options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPolylineFeature class]]); + MGLShapeCollection *collection = source.shape; + XCTAssertNotNil(collection); + XCTAssertEqual(collection.shapes.count, 1); + XCTAssertTrue([collection.shapes.firstObject isMemberOfClass:[MGLPolylineFeature class]]); +} + +- (void)testMGLGeoJSONSourceWithSingleFeature { + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geojson" + geoJSONData:[@"{\"type\": \"Point\", \"coordinates\": [0, 0]}" dataUsingEncoding:NSUTF8StringEncoding] + options:nil]; + XCTAssertNotNil(source.shape); + XCTAssert([source.shape isKindOfClass:[MGLPointFeature class]]); } - (void)testMGLGeoJSONSourceWithPolylineFeatures { CLLocationCoordinate2D coordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)}; MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates count:2]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[polylineFeature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:polylineFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPolylineFeature class]]); + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPolylineFeature class]]); } - (void)testMGLGeoJSONSourceWithPolygonFeatures { @@ -88,11 +101,11 @@ @"array-of-array-attribute": arrayOfArrays, @"array-of-dictionary-attribute": arrayOfDictionaries}; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[polygonFeature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:polygonFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - MGLPolygonFeature *expectedPolygonFeature = (MGLPolygonFeature *)source.features.firstObject; + XCTAssertNotNil(source.shape); + MGLPolygonFeature *expectedPolygonFeature = (MGLPolygonFeature *)source.shape; + XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier); XCTAssertTrue([expectedPolygonFeature isMemberOfClass:[MGLPolygonFeature class]]); XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier); XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"name"], stringAttribute); @@ -123,12 +136,10 @@ MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[polygonFeature] options:nil]; - + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:polygonFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPolygonFeature class]]); + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPolygonFeature class]]); } - (void)testMGLGeoJSONSourceWithMultiPolylineFeatures { @@ -138,11 +149,10 @@ MGLPolylineFeature *secondPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:secondCoordinates count:2]; MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[firstPolylineFeature, secondPolylineFeature]]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[multiPolylineFeature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:multiPolylineFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLMultiPolylineFeature class]]); + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLMultiPolylineFeature class]]); } - (void)testMGLGeoJSONSourceWithMultiPolygonFeatures { @@ -167,23 +177,20 @@ MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[firstPolygon, secondPolygon]]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[multiPolygonFeature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:multiPolygonFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLMultiPolygonFeature class]]); - + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLMultiPolygonFeature class]]); } - (void)testMGLGeoJSONSourceWithPointFeature { MGLPointFeature *pointFeature = [MGLPointFeature new]; pointFeature.coordinate = CLLocationCoordinate2DMake(100.2, 0.2); - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" features:@[pointFeature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" shape:pointFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPointFeature class]]); + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPointFeature class]]); } - (void)testMGLGeoJSONSourceWithPointCollectionFeature { @@ -194,11 +201,10 @@ CLLocationCoordinate2DMake(100.0, 1.0), CLLocationCoordinate2DMake(100.0, 0.0)}; MGLPointCollectionFeature *pointCollectionFeature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:5]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" features:@[pointCollectionFeature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" shape:pointCollectionFeature options:nil]; - XCTAssertNotNil(source.features); - XCTAssertEqual(source.features.count, 1); - XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPointCollectionFeature class]]); + XCTAssertNotNil(source.shape); + XCTAssertTrue([source.shape isMemberOfClass:[MGLPointCollectionFeature class]]); } - (void)testMGLGeoJSONSourceWithShapeCollectionFeatures { @@ -236,7 +242,13 @@ MGLShapeCollectionFeature *shapeCollectionFeature_1 = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[polygonFeature, polylineFeature, multiPolygonFeature, multiPolylineFeature, pointCollectionFeature, pointFeature, shapeCollectionFeature]]; - XCTAssertThrowsSpecificNamed([[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[shapeCollectionFeature_1] options:nil], NSException, @"Method unavailable"); + + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" shape:shapeCollectionFeature_1 options:nil]; + + MGLShapeCollectionFeature *shape = source.shape; + + XCTAssertNotNil(shape); + XCTAssert(shape.shapes.count == 7, @"Shape collection should contain 7 shapes"); } @end diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 8f0d2502fb..bc1e6078f0 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -121,7 +121,7 @@ } - (void)testAddingSourcesTwice { - MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil]; + MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" shape:nil options:nil]; [self.style addSource:geoJSONSource]; XCTAssertThrowsSpecificNamed([self.style addSource:geoJSONSource], NSException, @"MGLRedundantSourceException"); @@ -143,7 +143,7 @@ } - (void)testAddingLayersTwice { - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" features:@[] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"geoJSONSource" shape:nil options:nil]; MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"backgroundLayer"]; [self.style addLayer:backgroundLayer]; diff --git a/platform/darwin/test/MGLStyleValueTests.swift b/platform/darwin/test/MGLStyleValueTests.swift index f7bf343852..aa9b003236 100644 --- a/platform/darwin/test/MGLStyleValueTests.swift +++ b/platform/darwin/test/MGLStyleValueTests.swift @@ -3,7 +3,7 @@ import Mapbox class MGLStyleValueTests: XCTestCase { func testConstantValues() { - let geoJSONSource = MGLGeoJSONSource(identifier: "test", features: [], options: nil) + let geoJSONSource = MGLGeoJSONSource(identifier: "test", shape: nil, options: nil) let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: geoJSONSource) // Boolean @@ -20,7 +20,7 @@ class MGLStyleValueTests: XCTestCase { } func testFunctions() { - let geoJSONSource = MGLGeoJSONSource(identifier: "test", features: [], options: nil) + let geoJSONSource = MGLGeoJSONSource(identifier: "test", shape: nil, options: nil) let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: geoJSONSource) // Boolean |