[test] Add iOS unit test runner
This commit is contained in:
@@ -191,4 +191,98 @@ if(MBGL_IOS_RENDER_TEST)
|
||||
set_target_properties(RenderTestAppTests PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/render-test/ios/tests/Info.plist)
|
||||
endif()
|
||||
|
||||
if(MBGL_IOS_UNIT_TEST)
|
||||
execute_process(COMMAND ditto ${PROJECT_SOURCE_DIR}/test/fixtures ${CMAKE_CURRENT_BINARY_DIR}/test-data/test/fixtures)
|
||||
execute_process(
|
||||
COMMAND
|
||||
ditto ${PROJECT_SOURCE_DIR}/mapbox-gl-js/src/style-spec/reference
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test-data/mapbox-gl-js/src/style-spec/reference
|
||||
)
|
||||
|
||||
set(
|
||||
RESOURCES
|
||||
${PROJECT_SOURCE_DIR}/test/ios/Main.storyboard
|
||||
${PROJECT_SOURCE_DIR}/test/ios/LaunchScreen.storyboard
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test-data
|
||||
)
|
||||
|
||||
add_executable(
|
||||
UnitTestsApp
|
||||
${PROJECT_SOURCE_DIR}/test/ios/ios_test_runner.hpp
|
||||
${PROJECT_SOURCE_DIR}/test/ios/ios_test_runner.cpp
|
||||
${PROJECT_SOURCE_DIR}/test/ios/AppDelegate.h
|
||||
${PROJECT_SOURCE_DIR}/test/ios/AppDelegate.m
|
||||
${PROJECT_SOURCE_DIR}/test/ios/ViewController.h
|
||||
${PROJECT_SOURCE_DIR}/test/ios/ViewController.m
|
||||
${PROJECT_SOURCE_DIR}/test/ios/iosTestRunner.h
|
||||
${PROJECT_SOURCE_DIR}/test/ios/iosTestRunner.mm
|
||||
${PROJECT_SOURCE_DIR}/test/ios/main.m
|
||||
${RESOURCES}
|
||||
)
|
||||
initialize_ios_target(UnitTestsApp)
|
||||
|
||||
set_target_properties(
|
||||
UnitTestsApp
|
||||
PROPERTIES
|
||||
MACOSX_BUNDLE
|
||||
TRUE
|
||||
MACOSX_BUNDLE_IDENTIFIER
|
||||
com.mapbox.UnitTestsApp
|
||||
MACOSX_BUNDLE_INFO_PLIST
|
||||
${PROJECT_SOURCE_DIR}/test/ios/Info.plist
|
||||
RESOURCE
|
||||
"${RESOURCES}"
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
UnitTestsApp
|
||||
PUBLIC {MBGL_ROOT}/test/include ${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
UnitTestsApp
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/test/ios
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
UnitTestsApp
|
||||
PRIVATE
|
||||
"-framework CoreGraphics"
|
||||
"-framework CoreLocation"
|
||||
"-framework Foundation"
|
||||
"-framework OpenGLES"
|
||||
"-framework QuartzCore"
|
||||
"-framework UIKit"
|
||||
mbgl-compiler-options
|
||||
-Wl,-force_load
|
||||
mbgl-test
|
||||
)
|
||||
|
||||
set_target_properties(UnitTestsApp PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
||||
set_target_properties(UnitTestsApp PROPERTIES XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
|
||||
|
||||
find_package(XCTest REQUIRED)
|
||||
|
||||
xctest_add_bundle(UnitTestsAppTests UnitTestsApp ${PROJECT_SOURCE_DIR}/test/ios/tests/Tests.m)
|
||||
|
||||
set_target_properties(
|
||||
UnitTestsAppTests
|
||||
PROPERTIES
|
||||
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET
|
||||
"${IOS_DEPLOYMENT_TARGET}"
|
||||
XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH
|
||||
$<$<CONFIG:Debug>:YES>
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
UnitTestsAppTests
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/test/ios
|
||||
)
|
||||
|
||||
xctest_add_test(XCTest.UnitTestsApp UnitTestsAppTests)
|
||||
|
||||
set_target_properties(UnitTestsAppTests PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/test/ios/tests/Info.plist)
|
||||
set_target_properties(UnitTestsAppTests PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
||||
set_target_properties(UnitTestsAppTests PROPERTIES XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
|
||||
endif()
|
||||
unset(IOS_DEPLOYMENT_TARGET CACHE)
|
||||
|
||||
@@ -134,6 +134,12 @@ else()
|
||||
COMPILE_FLAGS
|
||||
-Wno-shadow
|
||||
)
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/test/src/mbgl/test/http_server.cpp
|
||||
PROPERTIES
|
||||
COMPILE_OPTIONS
|
||||
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},iOS>:-Wno-shorten-64-to-32>
|
||||
)
|
||||
target_include_directories(
|
||||
mbgl-test
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/vendor/cpp-httplib
|
||||
@@ -167,6 +173,18 @@ target_include_directories(
|
||||
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/googletest.cmake)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL iOS)
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}")
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode)
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>)
|
||||
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}")
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode)
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>)
|
||||
endif()
|
||||
|
||||
# Needed for testing private classes
|
||||
get_target_property(MBGL_CORE_PRIVATE_LIBRARIES mbgl-core LINK_LIBRARIES)
|
||||
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if ANDROID
|
||||
#define TEST_READ_ONLY 0
|
||||
#elif TARGET_OS_IOS
|
||||
#define TEST_READ_ONLY 1
|
||||
#undef TEST_HAS_SERVER
|
||||
#define TEST_HAS_SERVER 0
|
||||
#else
|
||||
#define TEST_READ_ONLY 0
|
||||
#ifndef TEST_HAS_SERVER
|
||||
#define TEST_HAS_SERVER 1
|
||||
#endif
|
||||
#define TEST_READ_ONLY 0
|
||||
|
||||
#if !ANDROID
|
||||
#ifndef TEST_HAS_SERVER
|
||||
#define TEST_HAS_SERVER 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_SIMULATOR
|
||||
|
||||
7
test/ios/AppDelegate.h
Normal file
7
test/ios/AppDelegate.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#import <UIKit/UIApplication.h> // UIApplicationDelegate
|
||||
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
38
test/ios/AppDelegate.m
Normal file
38
test/ios/AppDelegate.m
Normal file
@@ -0,0 +1,38 @@
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface AppDelegate()
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
// Insert code here to initialize your application
|
||||
NSLog(@"didFinishLaunchingWithOptions");
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
3
test/ios/Gemfile
Normal file
3
test/ios/Gemfile
Normal file
@@ -0,0 +1,3 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "fastlane"
|
||||
62
test/ios/Info.plist
Normal file
62
test/ios/Info.plist
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>UnitTestsApp</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleLongVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>MBGL</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>7877</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>© 2014–2020 Mapbox</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>fetch</string>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
27
test/ios/LaunchScreen.storyboard
Normal file
27
test/ios/LaunchScreen.storyboard
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
27
test/ios/Main.storyboard
Normal file
27
test/ios/Main.storyboard
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
7
test/ios/README.md
Normal file
7
test/ios/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# iOS UnitTestsRunner App
|
||||
|
||||
This is a blank single-view-controller iOS app, linked against to a C++ static libraries, plus a a simple unit xctest. We use CMake to create an Xcode-friendly out-of-source build system. In another word, the build system is maintained by `CMakeLists` file,instead of a configured `.xcodeproj` file.
|
||||
|
||||
This CMake project can build the executable UnitTestsApp which is linked to the static C++ library 'mbgl-test'. CMakeLists.txt files are the only build configuration kept in source control. This is in contrast to committing the `.xcodeproj` directory which includes the backing XML, which is nonsensically hard to edit by hand.
|
||||
|
||||
The test instantiates ObjC object of class `IosTestRunner` from the app, the class will instantiates a C++ object from the linked library `mbgl-test` and calls running unit test function on it. It subsequently deletes the C++ object pointer. In the end, the test will check the existence of test report, which is an xml file that attach to xctest result.
|
||||
68
test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun
Normal file
68
test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UnitTestsAppTests</key>
|
||||
<dict>
|
||||
<key>BlueprintName</key>
|
||||
<string>UnitTestsAppTests</string>
|
||||
<key>BundleIdentifiersForCrashReportEmphasis</key>
|
||||
<array>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<string>com.mapbox.UnitTestsAppTests</string>
|
||||
</array>
|
||||
<key>CommandLineArguments</key>
|
||||
<array/>
|
||||
<key>DependentProductPaths</key>
|
||||
<array>
|
||||
<string>__TESTROOT__/Debug-iphoneos/UnitTestsApp.app</string>
|
||||
<string>__TESTROOT__/Debug-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest</string>
|
||||
</array>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>OS_ACTIVITY_DT_MODE</key>
|
||||
<string>YES</string>
|
||||
<key>SQLITE_ENABLE_THREAD_ASSERTIONS</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
<key>IsAppHostedTestBundle</key>
|
||||
<true/>
|
||||
<key>ProductModuleName</key>
|
||||
<string>UnitTestsAppTests</string>
|
||||
<key>RunOrder</key>
|
||||
<integer>0</integer>
|
||||
<key>SystemAttachmentLifetime</key>
|
||||
<string>deleteOnSuccess</string>
|
||||
<key>TestBundlePath</key>
|
||||
<string>__TESTHOST__/PlugIns/UnitTestsAppTests.xctest</string>
|
||||
<key>TestHostBundleIdentifier</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>TestHostPath</key>
|
||||
<string>__TESTROOT__/Debug-iphoneos/UnitTestsApp.app</string>
|
||||
<key>TestLanguage</key>
|
||||
<string></string>
|
||||
<key>TestRegion</key>
|
||||
<string></string>
|
||||
<key>TestingEnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>DYLD_FALLBACK_FRAMEWORK_PATH</key>
|
||||
<string></string>
|
||||
<key>DYLD_INSERT_LIBRARIES</key>
|
||||
<string>__PLATFORMS__/iPhoneOS.platform/Developer/usr/lib/libXCTestBundleInject.dylib</string>
|
||||
<key>XCInjectBundleInto</key>
|
||||
<string>unused</string>
|
||||
</dict>
|
||||
<key>ToolchainsSettingValue</key>
|
||||
<array/>
|
||||
<key>UITargetAppCommandLineArguments</key>
|
||||
<array/>
|
||||
<key>UserAttachmentLifetime</key>
|
||||
<string>deleteOnSuccess</string>
|
||||
</dict>
|
||||
<key>__xctestrun_metadata__</key>
|
||||
<dict>
|
||||
<key>FormatVersion</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
68
test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun
Normal file
68
test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UnitTestsAppTests</key>
|
||||
<dict>
|
||||
<key>BlueprintName</key>
|
||||
<string>UnitTestsAppTests</string>
|
||||
<key>BundleIdentifiersForCrashReportEmphasis</key>
|
||||
<array>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<string>com.mapbox.UnitTestsAppTests</string>
|
||||
</array>
|
||||
<key>CommandLineArguments</key>
|
||||
<array/>
|
||||
<key>DependentProductPaths</key>
|
||||
<array>
|
||||
<string>__TESTROOT__/Release-iphoneos/UnitTestsApp.app</string>
|
||||
<string>__TESTROOT__/Release-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest</string>
|
||||
</array>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>OS_ACTIVITY_DT_MODE</key>
|
||||
<string>YES</string>
|
||||
<key>SQLITE_ENABLE_THREAD_ASSERTIONS</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
<key>IsAppHostedTestBundle</key>
|
||||
<true/>
|
||||
<key>ProductModuleName</key>
|
||||
<string>UnitTestsAppTests</string>
|
||||
<key>RunOrder</key>
|
||||
<integer>0</integer>
|
||||
<key>SystemAttachmentLifetime</key>
|
||||
<string>deleteOnSuccess</string>
|
||||
<key>TestBundlePath</key>
|
||||
<string>__TESTHOST__/PlugIns/UnitTestsAppTests.xctest</string>
|
||||
<key>TestHostBundleIdentifier</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>TestHostPath</key>
|
||||
<string>__TESTROOT__/Release-iphoneos/UnitTestsApp.app</string>
|
||||
<key>TestLanguage</key>
|
||||
<string></string>
|
||||
<key>TestRegion</key>
|
||||
<string></string>
|
||||
<key>TestingEnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>DYLD_FALLBACK_FRAMEWORK_PATH</key>
|
||||
<string></string>
|
||||
<key>DYLD_INSERT_LIBRARIES</key>
|
||||
<string>__PLATFORMS__/iPhoneOS.platform/Developer/usr/lib/libXCTestBundleInject.dylib</string>
|
||||
<key>XCInjectBundleInto</key>
|
||||
<string>unused</string>
|
||||
</dict>
|
||||
<key>ToolchainsSettingValue</key>
|
||||
<array/>
|
||||
<key>UITargetAppCommandLineArguments</key>
|
||||
<array/>
|
||||
<key>UserAttachmentLifetime</key>
|
||||
<string>deleteOnSuccess</string>
|
||||
</dict>
|
||||
<key>__xctestrun_metadata__</key>
|
||||
<dict>
|
||||
<key>FormatVersion</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
6
test/ios/ViewController.h
Normal file
6
test/ios/ViewController.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
|
||||
@end
|
||||
|
||||
22
test/ios/ViewController.m
Normal file
22
test/ios/ViewController.m
Normal file
@@ -0,0 +1,22 @@
|
||||
#import "ViewController.h"
|
||||
#import "iosTestRunner.h"
|
||||
|
||||
@interface ViewController ()
|
||||
{
|
||||
IosTestRunner* i;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// In order to run test runner with app itself instead of with unit test, comment out the following line.
|
||||
// i = [[IosTestRunner alloc]init];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
}
|
||||
|
||||
@end
|
||||
16
test/ios/codesigning/UnitTestsApp.app.xcent.template
Normal file
16
test/ios/codesigning/UnitTestsApp.app.xcent.template
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>application-identifier</key>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsApp</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>$TEAM_ID</string>
|
||||
<key>get-task-allow</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsApp</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
16
test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template
Normal file
16
test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>application-identifier</key>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>$TEAM_ID</string>
|
||||
<key>get-task-allow</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>application-identifier</key>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>$TEAM_ID</string>
|
||||
<key>get-task-allow</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
16
test/ios/codesigning/XCTest.framework.xcent.template
Normal file
16
test/ios/codesigning/XCTest.framework.xcent.template
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>application-identifier</key>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>$TEAM_ID</string>
|
||||
<key>get-task-allow</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
8
test/ios/codesigning/codesign_all.sh
Executable file
8
test/ios/codesigning/codesign_all.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
codesign --force --sign $CODESIGNIDENTITY --entitlements ../codesigning/UnitTestsApp.app.xcent --timestamp=none ./Release-iphoneos/UnitTestsApp.app
|
||||
codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/libXCTestSwiftSupport.dylib
|
||||
codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/libXCTestBundleInject.dylib
|
||||
codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/XCTAutomationSupport.framework
|
||||
codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/XCTest.framework
|
||||
codesign --force --sign $CODESIGNIDENTITY --deep --entitlements ../codesigning/UnitTestsAppTests.xctest.xcent --timestamp=none ./Release-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest
|
||||
40
test/ios/codesigning/generate-entitlements.swift
Executable file
40
test/ios/codesigning/generate-entitlements.swift
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/swift
|
||||
|
||||
/// Generates Entitlement files .xcent for codesigning, containing the correct team id
|
||||
import Swift
|
||||
import Foundation
|
||||
|
||||
let fileManager = FileManager.default
|
||||
|
||||
let contentsOfCurrentWorkingDirectory = try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: "./codesigning/"), includingPropertiesForKeys: nil, options: [])
|
||||
|
||||
guard let rawTeamIdEnv = getenv("IOS_DEVELOPMENT_TEAM") else {
|
||||
print("Please add a IOS_DEVELOPMENT_TEAM environment variable.")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
let teamId2 = String(utf8String: rawTeamIdEnv)
|
||||
|
||||
for file in contentsOfCurrentWorkingDirectory {
|
||||
if (file.pathExtension == "template") {
|
||||
var content = ""
|
||||
do {
|
||||
content = try String(contentsOf: file, encoding: .utf8)
|
||||
}
|
||||
catch {
|
||||
print("Error reading xcent file: \(error).")
|
||||
}
|
||||
|
||||
content = content.replacingOccurrences(of: "$TEAM_ID", with: teamId2!)
|
||||
|
||||
var targetFile = file
|
||||
targetFile.deletePathExtension()
|
||||
do {
|
||||
try content.write(to: targetFile, atomically: false, encoding: .utf8)
|
||||
print("Entitlement " + targetFile.absoluteString + " generated.")
|
||||
}
|
||||
catch {
|
||||
print("Error writing xcent file: \(error).")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>application-identifier</key>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>$TEAM_ID</string>
|
||||
<key>get-task-allow</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
3
test/ios/fastlane/Appfile
Normal file
3
test/ios/fastlane/Appfile
Normal file
@@ -0,0 +1,3 @@
|
||||
app_identifier("com.mapbox.UnitTestsApp") # The bundle identifier of your app
|
||||
apple_id ENV['MAPBOX_APPLE_ID']
|
||||
team_id ENV['MAPBOX_APPLE_TEAM_ID'] # Developer Portal Team ID
|
||||
5
test/ios/fastlane/Matchfile
Normal file
5
test/ios/fastlane/Matchfile
Normal file
@@ -0,0 +1,5 @@
|
||||
git_url("git@github.com:mapbox/apple-certificates.git")
|
||||
type("development") # The default type, can be: appstore, adhoc, enterprise or development
|
||||
app_identifier(["com.mapbox.UnitTestsApp", "com.mapbox.UnitTestsAppTests"])
|
||||
username ENV['MAPBOX_APPLE_ID']
|
||||
keychain_name("fastlane_keychain")
|
||||
9
test/ios/iosTestRunner.h
Normal file
9
test/ios/iosTestRunner.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
__attribute__((visibility ("default")))
|
||||
@interface IosTestRunner : NSObject
|
||||
|
||||
- (NSString*) getResultPath;
|
||||
- (BOOL) getTestStatus;
|
||||
|
||||
@end
|
||||
82
test/ios/iosTestRunner.mm
Normal file
82
test/ios/iosTestRunner.mm
Normal file
@@ -0,0 +1,82 @@
|
||||
#import "iosTestRunner.h"
|
||||
|
||||
#include "ios_test_runner.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@interface IosTestRunner ()
|
||||
|
||||
@property (nullable) TestRunner* runner;
|
||||
|
||||
@property (copy, nullable) NSString *resultPath;
|
||||
|
||||
@property BOOL testStatus;
|
||||
|
||||
@end
|
||||
|
||||
@implementation IosTestRunner
|
||||
|
||||
-(instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.testStatus = NO;
|
||||
self.runner = new TestRunner();
|
||||
NSError *error;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
|
||||
NSArray *bundleContents = [fileManager contentsOfDirectoryAtPath: bundleRoot error: &error];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDir = [paths objectAtIndex: 0];
|
||||
|
||||
for (uint32_t i = 0; i < bundleContents.count; i++) {
|
||||
NSString *dirName = [bundleContents objectAtIndex: i];
|
||||
if ([dirName isEqualToString:@"test-data"]) {
|
||||
NSString *destinationPath = [documentsDir stringByAppendingPathComponent: dirName];
|
||||
BOOL success = [fileManager fileExistsAtPath: destinationPath];
|
||||
if (success) {
|
||||
[fileManager removeItemAtPath:destinationPath error:NULL];
|
||||
}
|
||||
|
||||
success = [fileManager fileExistsAtPath: destinationPath];
|
||||
if (!success) {
|
||||
NSString *copyDirPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: dirName];
|
||||
success = [fileManager copyItemAtPath: copyDirPath toPath: destinationPath error: &error];
|
||||
|
||||
if (!success) {
|
||||
NSLog(@"Failed to copy file '%@'", dirName);
|
||||
NSAssert1(0, @"Failed to copy file, error '%@'", [error localizedDescription]);
|
||||
} else {
|
||||
NSLog(@"File '%@' copied OK", dirName);
|
||||
}
|
||||
} else {
|
||||
NSLog(@"Failed to remove file '%@'", dirName);
|
||||
NSAssert1(0, @"Failed to remove file, error '%@'", [error localizedDescription]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string basePath = std::string([documentsDir UTF8String]) + std::string("/test-data");
|
||||
self.testStatus = self.runner->startTest(basePath) ? YES : NO;
|
||||
self.resultPath = [documentsDir stringByAppendingPathComponent:@"/test-data/test/results.xml"];
|
||||
|
||||
BOOL fileFound = [fileManager fileExistsAtPath: self.resultPath];
|
||||
if (fileFound == NO) {
|
||||
NSLog(@"Test result file '%@' does not exist", self.resultPath);
|
||||
self.testStatus = NO;
|
||||
}
|
||||
|
||||
delete self.runner;
|
||||
self.runner = nullptr;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString*) getResultPath {
|
||||
return self.resultPath;
|
||||
}
|
||||
|
||||
- (BOOL) getTestStatus {
|
||||
return self.testStatus;
|
||||
}
|
||||
@end
|
||||
31
test/ios/ios_test_runner.cpp
Normal file
31
test/ios/ios_test_runner.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "ios_test_runner.hpp"
|
||||
|
||||
#include <mbgl/test.hpp>
|
||||
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
|
||||
EXPORT
|
||||
bool TestRunner::startTest(const std::string& basePath) {
|
||||
std::vector<std::string> arguments = {"mbgl-test-runner", "--gtest_output=xml:" + basePath + "/test/results.xml"};
|
||||
std::vector<char*> argv;
|
||||
for (const auto& arg : arguments) {
|
||||
argv.push_back(const_cast<char*>(arg.data()));
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
|
||||
if (chdir(basePath.c_str())) {
|
||||
mbgl::Log::Error(mbgl::Event::General, "Failed to change the directory to " + basePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
mbgl::Log::Info(mbgl::Event::General, "Start TestRunner");
|
||||
int status = mbgl::runTests(static_cast<uint32_t>(argv.size()), argv.data());
|
||||
mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '%d'", status);
|
||||
|
||||
return status == 0;
|
||||
}
|
||||
14
test/ios/ios_test_runner.hpp
Normal file
14
test/ios/ios_test_runner.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef ios_test_runner_hpp
|
||||
#define ios_test_runner_hpp
|
||||
|
||||
#include <string>
|
||||
|
||||
class TestRunner {
|
||||
public:
|
||||
TestRunner() = default;
|
||||
~TestRunner() = default;
|
||||
|
||||
bool startTest(const std::string& basePath);
|
||||
};
|
||||
|
||||
#endif /* ios_test_runner_hpp */
|
||||
9
test/ios/main.m
Normal file
9
test/ios/main.m
Normal file
@@ -0,0 +1,9 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppDelegate.h"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||
}
|
||||
}
|
||||
22
test/ios/tests/Info.plist
Normal file
22
test/ios/tests/Info.plist
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>UnitTestsAppTests</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.mapbox.UnitTestsAppTests</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>UnitTestsAppTests</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
37
test/ios/tests/Tests.m
Normal file
37
test/ios/tests/Tests.m
Normal file
@@ -0,0 +1,37 @@
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "iosTestRunner.h"
|
||||
@interface Tests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation Tests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testStartUnitTestRunner {
|
||||
IosTestRunner* runner = [[IosTestRunner alloc] init];
|
||||
XCTAssert(runner, @"IOSTestRunner is not initialized correctly");
|
||||
|
||||
NSString* testResult = [runner getResultPath];
|
||||
XCTAssert(testResult, @"IOSTestRunner did not produce a test result file");
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL fileFound = [fileManager fileExistsAtPath: testResult];
|
||||
XCTAssert(fileFound, @"Test result file '%@' does not exit", testResult);
|
||||
NSURL *resultURL = [NSURL fileURLWithPath:testResult];
|
||||
XCTAttachment *attachment1URL = [XCTAttachment attachmentWithContentsOfFileAtURL: resultURL];
|
||||
XCTAssert(attachment1URL, @"Failed to attach test result '%@'", testResult);
|
||||
attachment1URL.lifetime = XCTAttachmentLifetimeKeepAlways;
|
||||
[self addAttachment:attachment1URL];
|
||||
|
||||
BOOL success = [runner getTestStatus];
|
||||
XCTAssert(success, @"IOSTestRunner reports error because some of the tests are not passed, please check the test report");
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user