summaryrefslogtreecommitdiff
path: root/platform/ios/test/MGLGeoJSONSourceTests.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/test/MGLGeoJSONSourceTests.mm')
-rw-r--r--platform/ios/test/MGLGeoJSONSourceTests.mm106
1 files changed, 76 insertions, 30 deletions
diff --git a/platform/ios/test/MGLGeoJSONSourceTests.mm b/platform/ios/test/MGLGeoJSONSourceTests.mm
index ce92ec24ab..40d8067985 100644
--- a/platform/ios/test/MGLGeoJSONSourceTests.mm
+++ b/platform/ios/test/MGLGeoJSONSourceTests.mm
@@ -1,12 +1,18 @@
#import <XCTest/XCTest.h>
#import <Mapbox/Mapbox.h>
+#import "MGLFeature_Private.h"
#import "MGLGeoJSONSource_Private.h"
#import "MGLSource_Private.h"
#include <mbgl/style/sources/geojson_source.hpp>
@interface MGLGeoJSONSourceTests : XCTestCase
+@end
+
+@interface MGLPolygonFeature (Test)
+
+@property (nonatomic, copy, readwrite) NS_DICTIONARY_OF(NSString *, id) *attributes;
@end
@@ -38,10 +44,10 @@
- (void)testMGLGeoJSONSourceWithData {
- NSString *data = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}";
+ NSString *geoJSON = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}";
- NSData *geoJSON = [data dataUsingEncoding:NSUTF8StringEncoding];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"test-id" geoJSONData:geoJSON options:nil];
+ NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" geoJSONData:data options:nil];
[source mbglSource];
@@ -54,7 +60,7 @@
CLLocationCoordinate2D coordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)};
MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates count:2];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[polylineFeature] options:nil];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[polylineFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
@@ -63,7 +69,6 @@
XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPolylineFeature class]]);
}
-
- (void)testMGLGeoJSONSourceWithPolygonFeatures {
CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(100.0, 0.0),
@@ -71,15 +76,45 @@
CLLocationCoordinate2DMake(101.0, 1.0),
CLLocationCoordinate2DMake(100.0, 1.0),
CLLocationCoordinate2DMake(100.0, 0.0)};
- MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[polygonFeature] options:nil];
+ MGLPolygonFeature<MGLFeaturePrivate> *polygonFeature = (MGLPolygonFeature<MGLFeaturePrivate> *)[MGLPolygonFeature polygonWithCoordinates:coordinates count:5];
+ polygonFeature.identifier = @"feature-id";
+ NSString *stringAttribute = @"string";
+ NSNumber *boolAttribute = [NSNumber numberWithBool:YES];
+ NSNumber *doubleAttribute = [NSNumber numberWithDouble:1.23];
+ NSDictionary *nestedDictionaryValue = @{@"nested-key-1": @"nested-string-value"};
+ NSArray *arrayValue = @[@"string-value", @2];
+ NSDictionary *dictionaryValue = @{@"key-1": @"string-value",
+ @"key-2": @1,
+ @"key-3": nestedDictionaryValue,
+ @"key-4": arrayValue};
+ NSArray *arrayOfArrays = @[@[@1, @"string-value", @[@"jagged"]]];
+ NSArray *arrayOfDictionaries = @[@{@"key": @"value"}];
+
+ polygonFeature.attributes = @{@"name": stringAttribute,
+ @"bool": boolAttribute,
+ @"double": doubleAttribute,
+ @"dictionary-attribute": dictionaryValue,
+ @"array-attribute": arrayValue,
+ @"array-of-array-attribute": arrayOfArrays,
+ @"array-of-dictionary-attribute": arrayOfDictionaries};
+
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[polygonFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
XCTAssertNotNil(source.features);
XCTAssertEqual(source.features.count, 1);
- XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPolygonFeature class]]);
+ MGLPolygonFeature *expectedPolygonFeature = (MGLPolygonFeature *)source.features.firstObject;
+ XCTAssertTrue([expectedPolygonFeature isMemberOfClass:[MGLPolygonFeature class]]);
+ XCTAssertEqualObjects(expectedPolygonFeature.identifier, polygonFeature.identifier);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"name"], stringAttribute);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"bool"], boolAttribute);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"double"], doubleAttribute);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"dictionary-attribute"], dictionaryValue);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-attribute"], arrayValue);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-of-array-attribute"], arrayOfArrays);
+ XCTAssertEqualObjects(expectedPolygonFeature.attributes[@"array-of-dictionary-attribute"], arrayOfDictionaries);
}
- (void)testMGLGeoJSONSourceWithPolygonFeaturesInculdingInteriorPolygons {
@@ -101,7 +136,7 @@
MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[polygonFeature] options:nil];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[polygonFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
@@ -114,17 +149,20 @@
- (void)testMGLGeoJSONSourceWithMultiPointFeaturesUsingPolylines {
CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(100.0, 0.0),
- CLLocationCoordinate2DMake(101.0, 0.0)};
+ CLLocationCoordinate2DMake(101.0, 0.0),
+ CLLocationCoordinate2DMake(101.0, 1.0),
+ CLLocationCoordinate2DMake(100.0, 1.0),
+ CLLocationCoordinate2DMake(100.0, 0.0)};
- MGLMultiPointFeature *multiPointFeature = (MGLMultiPointFeature *)[MGLPolylineFeature polylineWithCoordinates:coordinates count:2];
+ MGLMultiPointFeature *multiPointFeature = [MGLMultiPointFeature multiPointWithCoordinates:coordinates count:5];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[multiPointFeature] options:nil];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[multiPointFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
XCTAssertNotNil(source.features);
XCTAssertEqual(source.features.count, 1);
- XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPolylineFeature class]]);
+ XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLMultiPointFeature class]]);
}
- (void)testMGLGeoJSONSourceWithMultiPointFeaturesUsingPolygons {
@@ -146,7 +184,7 @@
MGLMultiPointFeature *multiPointFeature = (MGLMultiPointFeature *)[MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[multiPointFeature] options:nil];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[multiPointFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
@@ -156,13 +194,13 @@
}
- (void)testMGLGeoJSONSourceWithMultiPolylineFeatures {
- CLLocationCoordinate2D coordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)};
- MGLPolylineFeature *polylineFeature = [MGLPolylineFeature polylineWithCoordinates:coordinates count:2];
- CLLocationCoordinate2D coordinates_1[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)};
- MGLPolylineFeature *polylineFeature_1 = [MGLPolylineFeature polylineWithCoordinates:coordinates_1 count:2];
- MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[polylineFeature, polylineFeature_1]];
+ CLLocationCoordinate2D firstCoordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)};
+ MGLPolylineFeature *firstPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:firstCoordinates count:2];
+ CLLocationCoordinate2D secondCoordinates[] = { CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10)};
+ MGLPolylineFeature *secondPolylineFeature = [MGLPolylineFeature polylineWithCoordinates:secondCoordinates count:2];
+ MGLMultiPolylineFeature *multiPolylineFeature = [MGLMultiPolylineFeature multiPolylineWithPolylines:@[firstPolylineFeature, secondPolylineFeature]];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[multiPolylineFeature] options:nil];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[multiPolylineFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
@@ -188,12 +226,12 @@
MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:interiorCoordinates count:5];
- MGLPolygonFeature *polygon_1 = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]];
- MGLPolygonFeature *polygon_2 = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]];
+ MGLPolygonFeature *firstPolygon = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]];
+ MGLPolygonFeature *secondPolygon = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5 interiorPolygons:@[polygon]];
- MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[polygon_1, polygon_2]];
+ MGLMultiPolygonFeature *multiPolygonFeature = [MGLMultiPolygonFeature multiPolygonWithPolygons:@[firstPolygon, secondPolygon]];
- MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[multiPolygonFeature] options:nil];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" features:@[multiPolygonFeature] options:nil];
std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
@@ -203,6 +241,19 @@
}
+- (void)testMGLGeoJSONSourceWithPointFeature {
+ MGLPointFeature *pointFeature = [MGLPointFeature new];
+ pointFeature.coordinate = CLLocationCoordinate2DMake(100.2, 0.2);
+
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"souce-id" features:@[pointFeature] options:nil];
+
+ std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
+
+ XCTAssertNotNil(source.features);
+ XCTAssertEqual(source.features.count, 1);
+ XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLPointFeature class]]);
+}
+
- (void)testMGLGeoJSONSourceWithShapeCollectionFeatures {
CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(100.0, 0.0),
@@ -240,12 +291,7 @@
MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"" features:@[shapeCollectionFeature_1] options:nil];
- std::unique_ptr<mbgl::style::Source> mbglSource = [source mbglSource];
-
- XCTAssertNotNil(source.features);
- XCTAssertEqual(source.features.count, 1);
- XCTAssertTrue([source.features.firstObject isMemberOfClass:[MGLShapeCollectionFeature class]]);
-
+ XCTAssertThrowsSpecificNamed([source mbglSource], NSException, @"Method unavailable");
}
@end