summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-05-25 01:40:14 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-05-27 21:42:38 -0700
commit4ab98387f1fda80b7bf9328d5aee77f37363d068 (patch)
tree590a81e649b7cfe07f31bb5134996e2efed7ddba /platform/darwin/test
parentff0cc1c9ef4b1a8e2f6014fd9ef8cd7a3800e5f0 (diff)
downloadqtlocation-mapboxgl-4ab98387f1fda80b7bf9328d5aee77f37363d068.tar.gz
[ios, osx] MGLFeature tests
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLFeatureTests.mm130
1 files changed, 130 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm
new file mode 100644
index 0000000000..d9334c76af
--- /dev/null
+++ b/platform/darwin/test/MGLFeatureTests.mm
@@ -0,0 +1,130 @@
+#import <Mapbox/Mapbox.h>
+#import <XCTest/XCTest.h>
+
+#import "../../darwin/src/MGLFeature_Private.h"
+
+@interface MGLFeatureTests : XCTestCase
+
+@end
+
+@implementation MGLFeatureTests
+
+- (void)testGeometryConversion {
+ std::vector<mbgl::Feature> features;
+
+ mapbox::geometry::point<double> point = { -90.066667, 29.95 };
+ features.emplace_back(point);
+
+ mapbox::geometry::line_string<double> lineString = {
+ { -84.516667, 39.1 },
+ { -90.066667, 29.95 },
+ };
+ features.emplace_back(lineString);
+
+ mapbox::geometry::polygon<double> polygon = {
+ {
+ { -77.0325453144239, 38.9131982 },
+ { -122.4135302, 37.7757368 },
+ { 77.6368034, 12.9810816 },
+ { -74.2178961777998, -13.15589555 },
+ },
+ };
+ features.emplace_back(polygon);
+
+ NS_ARRAY_OF(MGLShape <MGLFeature> *) *shapes = MGLFeaturesFromMBGLFeatures(features);
+ XCTAssertEqual(shapes.count, 3, @"All features should be converted into shapes");
+
+ MGLPointFeature *pointShape = (MGLPointFeature *)shapes[0];
+ XCTAssertTrue([pointShape isKindOfClass:[MGLPointFeature class]]);
+ XCTAssertEqualObjects([NSValue valueWithMGLCoordinate:pointShape.coordinate],
+ [NSValue valueWithMGLCoordinate:CLLocationCoordinate2DMake(29.95, -90.066667)]);
+
+ MGLPolylineFeature *polylineShape = (MGLPolylineFeature *)shapes[1];
+ XCTAssertTrue([polylineShape isKindOfClass:[MGLPolylineFeature class]]);
+ XCTAssertEqual(polylineShape.pointCount, 2);
+ CLLocationCoordinate2D polylineCoordinates[2];
+ [polylineShape getCoordinates:polylineCoordinates range:NSMakeRange(0, polylineShape.pointCount)];
+ XCTAssertEqualObjects([NSValue valueWithMGLCoordinate:polylineCoordinates[0]],
+ [NSValue valueWithMGLCoordinate:CLLocationCoordinate2DMake(39.1, -84.516667)]);
+ XCTAssertEqualObjects([NSValue valueWithMGLCoordinate:polylineCoordinates[1]],
+ [NSValue valueWithMGLCoordinate:CLLocationCoordinate2DMake(29.95, -90.066667)]);
+
+ MGLPolygonFeature *polygonShape = (MGLPolygonFeature *)shapes[2];
+ XCTAssertTrue([polygonShape isKindOfClass:[MGLPolygonFeature class]]);
+ XCTAssertEqual(polygonShape.pointCount, 4);
+}
+
+- (void)testPropertyConversion {
+ std::vector<mbgl::Feature> features;
+
+ mapbox::geometry::point<double> point = { -90.066667, 29.95 };
+ mbgl::Feature pointFeature(point);
+ pointFeature.id = UINT64_MAX;
+ pointFeature.properties["null"] = nullptr;
+ pointFeature.properties["bool"] = true;
+ pointFeature.properties["unsigned int"] = UINT64_MAX;
+ pointFeature.properties["int"] = INT64_MIN;
+ pointFeature.properties["double"] = DBL_MAX;
+ pointFeature.properties["string"] = std::string("🚏");
+ std::vector<bool> vector;
+ vector.push_back(true);
+ vector.push_back(false);
+ vector.push_back(true);
+ features.push_back(pointFeature);
+
+ NS_ARRAY_OF(MGLShape <MGLFeature> *) *shapes = MGLFeaturesFromMBGLFeatures(features);
+ XCTAssertEqual(shapes.count, 1, @"All features should be converted into shapes");
+
+ MGLShape <MGLFeature> *shape = shapes.firstObject;
+ XCTAssertTrue([shape conformsToProtocol:@protocol(MGLFeature)]);
+ XCTAssertTrue([shape isKindOfClass:[MGLShape class]]);
+
+ NSNumber *identifier = shape.identifier;
+ XCTAssertTrue([identifier isKindOfClass:[NSNumber class]], @"Feature identifier should be NSNumber");
+ XCTAssertEqual(strcmp(identifier.objCType, @encode(uint64_t)), 0, @"Feature identifier should be 64-bit unsigned integer");
+
+ NSNull *null = [shape attributeForKey:@"null"];
+ XCTAssertNotNil(null);
+ XCTAssertTrue([null isKindOfClass:[NSNull class]]);
+ XCTAssertEqual(null, shape.attributes[@"null"]);
+
+ NSNumber *boolean = [shape attributeForKey:@"bool"];
+ XCTAssertNotNil(boolean);
+ XCTAssertTrue([boolean isKindOfClass:[NSNumber class]]);
+#if (TARGET_OS_IPHONE && __LP64__) || TARGET_OS_WATCH
+ XCTAssertEqual(strcmp(boolean.objCType, @encode(char)), 0, @"Boolean property should be converted to bool NSNumber");
+#else
+ XCTAssertEqual(strcmp(boolean.objCType, @encode(BOOL)), 0, @"Boolean property should be converted to bool NSNumber");
+#endif
+ XCTAssertTrue(boolean.boolValue);
+ XCTAssertEqual(boolean, shape.attributes[@"bool"]);
+
+ NSNumber *unsignedInteger = [shape attributeForKey:@"unsigned int"];
+ XCTAssertNotNil(unsignedInteger);
+ XCTAssertTrue([unsignedInteger isKindOfClass:[NSNumber class]]);
+ XCTAssertEqual(strcmp(unsignedInteger.objCType, @encode(uint64_t)), 0, @"Unsigned integer property should be converted to unsigned long long NSNumber");
+ XCTAssertEqual(unsignedInteger.unsignedLongLongValue, UINT64_MAX);
+ XCTAssertEqual(unsignedInteger, shape.attributes[@"unsigned int"]);
+
+ NSNumber *integer = [shape attributeForKey:@"int"];
+ XCTAssertNotNil(integer);
+ XCTAssertTrue([integer isKindOfClass:[NSNumber class]]);
+ XCTAssertEqual(strcmp(integer.objCType, @encode(int64_t)), 0, @"Integer property should be converted to long long NSNumber");
+ XCTAssertEqual(integer.longLongValue, INT64_MIN);
+ XCTAssertEqual(integer, shape.attributes[@"int"]);
+
+ NSNumber *floatingPointNumber = [shape attributeForKey:@"double"];
+ XCTAssertNotNil(floatingPointNumber);
+ XCTAssertTrue([floatingPointNumber isKindOfClass:[NSNumber class]]);
+ XCTAssertEqual(strcmp(floatingPointNumber.objCType, @encode(double)), 0, @"Floating-point number property should be converted to double NSNumber");
+ XCTAssertEqual(floatingPointNumber.doubleValue, DBL_MAX);
+ XCTAssertEqual(floatingPointNumber, shape.attributes[@"double"]);
+
+ NSString *string = [shape attributeForKey:@"string"];
+ XCTAssertNotNil(string);
+ XCTAssertTrue([string isKindOfClass:[NSString class]]);
+ XCTAssertEqualObjects(string, @"🚏");
+ XCTAssertEqual(string, shape.attributes[@"string"]);
+}
+
+@end