From 4ab98387f1fda80b7bf9328d5aee77f37363d068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 25 May 2016 01:40:14 -0700 Subject: [PATCH] [ios, osx] MGLFeature tests --- platform/darwin/test/MGLFeatureTests.mm | 130 +++++++++++++++++++++ platform/ios/ios.xcodeproj/project.pbxproj | 6 + platform/osx/osx.xcodeproj/project.pbxproj | 6 + 3 files changed, 142 insertions(+) create mode 100644 platform/darwin/test/MGLFeatureTests.mm diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm new file mode 100644 index 000000000..d9334c76a --- /dev/null +++ b/platform/darwin/test/MGLFeatureTests.mm @@ -0,0 +1,130 @@ +#import +#import + +#import "../../darwin/src/MGLFeature_Private.h" + +@interface MGLFeatureTests : XCTestCase + +@end + +@implementation MGLFeatureTests + +- (void)testGeometryConversion { + std::vector features; + + mapbox::geometry::point point = { -90.066667, 29.95 }; + features.emplace_back(point); + + mapbox::geometry::line_string lineString = { + { -84.516667, 39.1 }, + { -90.066667, 29.95 }, + }; + features.emplace_back(lineString); + + mapbox::geometry::polygon 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 *) *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 features; + + mapbox::geometry::point 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 vector; + vector.push_back(true); + vector.push_back(false); + vector.push_back(true); + features.push_back(pointFeature); + + NS_ARRAY_OF(MGLShape *) *shapes = MGLFeaturesFromMBGLFeatures(features); + XCTAssertEqual(shapes.count, 1, @"All features should be converted into shapes"); + + MGLShape *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 diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 3f233441f..811fb89b7 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 4018B1CA1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4018B1CB1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */; }; + DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */; }; DA17BE301CC4BAC300402C41 /* MGLMapView_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Internal.h */; }; DA17BE311CC4BDAA00402C41 /* MGLMapView_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = DA17BE2F1CC4BAC300402C41 /* MGLMapView_Internal.h */; }; DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1DC9671CB6C6B7006E619F /* MBXCustomCalloutView.m */; }; @@ -325,6 +326,7 @@ 402E9DE01CD2C76200FD4519 /* Mapbox.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Mapbox.playground; sourceTree = ""; }; 40FDA7691CCAAA6800442548 /* MBXAnnotationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXAnnotationView.h; sourceTree = ""; }; 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXAnnotationView.m; sourceTree = ""; }; + DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA17BE2F1CC4BAC300402C41 /* MGLMapView_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapView_Internal.h; sourceTree = ""; }; DA1DC94A1CB6C1C2006E619F /* Mapbox GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mapbox GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DA1DC9501CB6C1C2006E619F /* MBXAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBXAppDelegate.h; sourceTree = ""; }; @@ -638,6 +640,7 @@ DA35A2C31CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m */, DA35A2C41CCA9F8300E826B2 /* MGLCompassDirectionFormatterTests.m */, DA35A2A91CCA058D00E826B2 /* MGLCoordinateFormatterTests.m */, + DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */, DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */, DA2E885D1CC0382C00F24E7B /* MGLOfflinePackTests.m */, DA2E885E1CC0382C00F24E7B /* MGLOfflineRegionTests.m */, @@ -1334,6 +1337,7 @@ DA35A2C51CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m in Sources */, DA2E88621CC0382C00F24E7B /* MGLOfflinePackTests.m in Sources */, DA35A2AA1CCA058D00E826B2 /* MGLCoordinateFormatterTests.m in Sources */, + DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1659,6 +1663,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", + "$(variant_cflags)", "$(geometry_cflags)", ); PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test; @@ -1676,6 +1681,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", + "$(variant_cflags)", "$(geometry_cflags)", ); PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test; diff --git a/platform/osx/osx.xcodeproj/project.pbxproj b/platform/osx/osx.xcodeproj/project.pbxproj index 762cd39fa..51d9f0671 100644 --- a/platform/osx/osx.xcodeproj/project.pbxproj +++ b/platform/osx/osx.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 52BECB0A1CC5A26F009CD791 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52BECB091CC5A26F009CD791 /* SystemConfiguration.framework */; }; + DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; DA35A2A41CC9EB1A00E826B2 /* MGLCoordinateFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA35A2A61CC9EB2700E826B2 /* MGLCoordinateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2A51CC9EB2700E826B2 /* MGLCoordinateFormatter.m */; }; DA35A2A81CC9F41600E826B2 /* MGLCoordinateFormatterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */; }; @@ -146,6 +147,7 @@ /* Begin PBXFileReference section */ 52BECB091CC5A26F009CD791 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; DA35A2A31CC9EB1A00E826B2 /* MGLCoordinateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLCoordinateFormatter.h; sourceTree = ""; }; DA35A2A51CC9EB2700E826B2 /* MGLCoordinateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLCoordinateFormatter.m; sourceTree = ""; }; DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLCoordinateFormatterTests.m; path = ../../darwin/test/MGLCoordinateFormatterTests.m; sourceTree = ""; }; @@ -474,6 +476,7 @@ DA35A2C11CCA9F4A00E826B2 /* MGLClockDirectionFormatterTests.m */, DA35A2B51CCA14D700E826B2 /* MGLCompassDirectionFormatterTests.m */, DA35A2A71CC9F41600E826B2 /* MGLCoordinateFormatterTests.m */, + DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */, DAE6C3C81CC34BD800DB3429 /* MGLGeometryTests.mm */, DAE6C3C91CC34BD800DB3429 /* MGLOfflinePackTests.m */, DAE6C3CA1CC34BD800DB3429 /* MGLOfflineRegionTests.m */, @@ -806,6 +809,7 @@ DAE6C3D51CC34C9900DB3429 /* MGLOfflineStorageTests.m in Sources */, DAE6C3D31CC34C9900DB3429 /* MGLOfflinePackTests.m in Sources */, DA35A2A81CC9F41600E826B2 /* MGLCoordinateFormatterTests.m in Sources */, + DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1094,6 +1098,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", + "$(variant_cflags)", "$(geometry_cflags)", ); PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test; @@ -1111,6 +1116,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", + "$(variant_cflags)", "$(geometry_cflags)", ); PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;