From 9340b4822a9d5f43952ba71ff16315d606de50bc Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 12 Apr 2017 15:22:55 -0400 Subject: [ios, macos] Add Swift integration tests for map view delegate --- platform/darwin/test/MGLSDKTestHelpers.swift | 47 +++++++++++++ platform/ios/ios.xcodeproj/project.pbxproj | 26 +++++++ .../test/MGLMapViewDelegateIntegrationTests.swift | 82 ++++++++++++++++++++++ platform/macos/macos.xcodeproj/project.pbxproj | 32 +++++++++ .../test/MGLMapViewDelegateIntegrationTests.swift | 56 +++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 platform/darwin/test/MGLSDKTestHelpers.swift create mode 100644 platform/ios/test/MGLMapViewDelegateIntegrationTests.swift create mode 100644 platform/macos/test/MGLMapViewDelegateIntegrationTests.swift diff --git a/platform/darwin/test/MGLSDKTestHelpers.swift b/platform/darwin/test/MGLSDKTestHelpers.swift new file mode 100644 index 0000000000..82b5caa273 --- /dev/null +++ b/platform/darwin/test/MGLSDKTestHelpers.swift @@ -0,0 +1,47 @@ +import Foundation + +class MGLSDKTestHelpers { + + class func checkTestsContainAllMethods(testClass: Swift.AnyClass, in p: Protocol) { + let testMethods = self.classMethodDescriptions(testClass) + let subjectMethods = self.protocolMethodDescriptions(p) + + for method in subjectMethods { + if !testMethods.contains(method) { + XCTFail("\(String(describing: testClass)) does not contain \(method) from \(String(describing: p))") + } + } + + XCTAssert(true) + } + +} + +extension MGLSDKTestHelpers { + + class func protocolMethodDescriptions(_ p: Protocol) -> Set { + var methods = Set() + var methodCount = UInt32() + let methodDescriptionList: UnsafeMutablePointer! = protocol_copyMethodDescriptionList(p, false, true, &methodCount) + for i in 0.. Set { + var methods = Set() + var methodCount = UInt32() + let methodList: UnsafeMutablePointer! = class_copyMethodList(cls, &methodCount) + for i in 0.. CGFloat { return 0 } + + func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { return nil } + + func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? { return nil } + + func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { return false } + + func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> MGLCalloutView? { return nil } + + func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor { return .black } + + func mapView(_ mapView: MGLMapView, fillColorForPolygonAnnotation annotation: MGLPolygon) -> UIColor { return .black } + + func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { return nil } + + func mapView(_ mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { return 0 } + + func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { return nil } + + func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {} + + func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> Bool { return false } + +} diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index a42619c9bb..175629d126 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -49,6 +49,8 @@ 35C6DF871E214C1800ACA483 /* MGLDistanceFormatterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 35C6DF861E214C1800ACA483 /* MGLDistanceFormatterTests.m */; }; 35D65C5A1D65AD5500722C23 /* NSDate+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35D65C581D65AD5500722C23 /* NSDate+MGLAdditions.h */; }; 35D65C5B1D65AD5500722C23 /* NSDate+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35D65C591D65AD5500722C23 /* NSDate+MGLAdditions.mm */; }; + 4031ACFC1E9EB3C100A3EA26 /* MGLMapViewDelegateIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4031ACFB1E9EB3C100A3EA26 /* MGLMapViewDelegateIntegrationTests.swift */; }; + 4031AD031E9FD6AA00A3EA26 /* MGLSDKTestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4031AD011E9FD6A300A3EA26 /* MGLSDKTestHelpers.swift */; }; 4049C2A51DB6CE7F00B3F799 /* MGLPointCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4049C2A11DB6CE7800B3F799 /* MGLPointCollection.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4049C2AD1DB8020600B3F799 /* MGLPointCollection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4049C2A71DB6D09B00B3F799 /* MGLPointCollection.mm */; }; 408AA85B1DAEECFE00022900 /* MGLShape_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 408AA85A1DAEECF100022900 /* MGLShape_Private.h */; }; @@ -305,6 +307,8 @@ 35C6DF861E214C1800ACA483 /* MGLDistanceFormatterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLDistanceFormatterTests.m; path = ../../darwin/test/MGLDistanceFormatterTests.m; sourceTree = ""; }; 35D65C581D65AD5500722C23 /* NSDate+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+MGLAdditions.h"; sourceTree = ""; }; 35D65C591D65AD5500722C23 /* NSDate+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSDate+MGLAdditions.mm"; sourceTree = ""; }; + 4031ACFB1E9EB3C100A3EA26 /* MGLMapViewDelegateIntegrationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MGLMapViewDelegateIntegrationTests.swift; sourceTree = ""; }; + 4031AD011E9FD6A300A3EA26 /* MGLSDKTestHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MGLSDKTestHelpers.swift; path = ../../darwin/test/MGLSDKTestHelpers.swift; sourceTree = ""; }; 4049C2A11DB6CE7800B3F799 /* MGLPointCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPointCollection.h; sourceTree = ""; }; 4049C2A71DB6D09B00B3F799 /* MGLPointCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLPointCollection.mm; sourceTree = ""; }; 405C03961DB0004E001AC280 /* NSImage+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+MGLAdditions.h"; sourceTree = ""; }; @@ -661,6 +665,22 @@ name = Styling; sourceTree = ""; }; + 4031ACFA1E9EB39A00A3EA26 /* Swift Integration */ = { + isa = PBXGroup; + children = ( + 4031ACFB1E9EB3C100A3EA26 /* MGLMapViewDelegateIntegrationTests.swift */, + ); + name = "Swift Integration"; + sourceTree = ""; + }; + 4031AD001E9FD61000A3EA26 /* Test Helpers */ = { + isa = PBXGroup; + children = ( + 4031AD011E9FD6A300A3EA26 /* MGLSDKTestHelpers.swift */, + ); + name = "Test Helpers"; + sourceTree = ""; + }; DA839E891CC2E3400062CAFB = { isa = PBXGroup; children = ( @@ -943,6 +963,8 @@ DAE6C3371CC30DB200DB3429 /* SDK Tests */ = { isa = PBXGroup; children = ( + 4031AD001E9FD61000A3EA26 /* Test Helpers */, + 4031ACFA1E9EB39A00A3EA26 /* Swift Integration */, DA8F257D1D51C5F40010E6B5 /* Styling */, DAEDC4311D6033F1000224FF /* MGLAttributionInfoTests.m */, DAEDC4361D606291000224FF /* MGLAttributionButtonTests.m */, @@ -1225,6 +1247,7 @@ TargetAttributes = { DA839E911CC2E3400062CAFB = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0830; }; DAAA17961CE13BAE00731EFE = { CreatedOnToolsVersion = 7.3.1; @@ -1423,6 +1446,8 @@ DA87A9A61DCACC5000810D09 /* MGLCircleStyleLayerTests.mm in Sources */, DA87A99E1DC9DC2100810D09 /* MGLPredicateTests.mm in Sources */, DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */, + 4031ACFC1E9EB3C100A3EA26 /* MGLMapViewDelegateIntegrationTests.swift in Sources */, + 4031AD031E9FD6AA00A3EA26 /* MGLSDKTestHelpers.swift in Sources */, DA87A9A71DCACC5000810D09 /* MGLBackgroundStyleLayerTests.mm in Sources */, DA29875A1E1A4290002299F5 /* MGLDocumentationExampleTests.swift in Sources */, DAE6C3D31CC34C9900DB3429 /* MGLOfflinePackTests.m in Sources */, @@ -1661,12 +1686,15 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; OTHER_CFLAGS = "-fvisibility=hidden"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -1674,12 +1702,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; OTHER_CFLAGS = "-fvisibility=hidden"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -1791,6 +1821,7 @@ "$(geometry_cflags)", "$(geojson_cflags)", ); + OTHER_SWIFT_FLAGS = "-warnings-as-errors"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "../darwin/test/test-Bridging-Header.h"; @@ -1815,6 +1846,7 @@ "$(geometry_cflags)", "$(geojson_cflags)", ); + OTHER_SWIFT_FLAGS = "-warnings-as-errors"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "../darwin/test/test-Bridging-Header.h"; diff --git a/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift new file mode 100644 index 0000000000..3f82e7c61a --- /dev/null +++ b/platform/macos/test/MGLMapViewDelegateIntegrationTests.swift @@ -0,0 +1,56 @@ +import XCTest +import Mapbox + +class MGLMapViewDelegateIntegrationTests: XCTestCase { + + func testCoverage() { + MGLSDKTestHelpers.checkTestsContainAllMethods(testClass: MGLMapViewDelegateIntegrationTests.self, in: MGLMapViewDelegate.self) + } + +} + +extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate { + + func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera) -> Bool { return false } + + func mapView(_ mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { return 0 } + + func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { return false } + + func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? { return nil } + + func mapView(_ mapView: MGLMapView, alphaForShapeAnnotation annotation: MGLShape) -> CGFloat { return 0 } + + func mapViewDidFinishRenderingFrame(_ mapView: MGLMapView, fullyRendered: Bool) {} + + func mapViewDidFinishRenderingMap(_ mapView: MGLMapView, fullyRendered: Bool) {} + + func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {} + + func mapView(_ mapView: MGLMapView, didDeselect annotation: MGLAnnotation) {} + + func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {} + + func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {} + + func mapViewWillStartRenderingFrame(_ mapView: MGLMapView) {} + + func mapViewWillStartRenderingMap(_ mapView: MGLMapView) {} + + func mapViewWillStartLoadingMap(_ mapView: MGLMapView) {} + + func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {} + + func mapViewCameraIsChanging(_ mapView: MGLMapView) {} + + func mapView(_ mapView: MGLMapView, cameraDidChangeAnimated animated: Bool) {} + + func mapView(_ mapView: MGLMapView, cameraWillChangeAnimated animated: Bool) {} + + func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> NSColor { return .black } + + func mapView(_ mapView: MGLMapView, fillColorForPolygonAnnotation annotation: MGLPolygon) -> NSColor { return .black } + + func mapView(_ mapView: MGLMapView, calloutViewControllerFor annotation: MGLAnnotation) -> NSViewController? { return nil } + +} -- cgit v1.2.1