From 632c5f9d4c42a6e408c0565e34b2d1bd428ff018 Mon Sep 17 00:00:00 2001 From: Juha Alanen Date: Fri, 31 Jan 2020 11:52:12 +0200 Subject: [test] Add iOS unit test runner --- test/ios/AppDelegate.h | 7 ++ test/ios/AppDelegate.m | 38 ++++++++++ test/ios/Gemfile | 3 + test/ios/Info.plist | 62 ++++++++++++++++ test/ios/LaunchScreen.storyboard | 27 +++++++ test/ios/Main.storyboard | 27 +++++++ test/ios/README.md | 7 ++ ...nitTestsApp_iphoneos13.2-arm64e-debug.xctestrun | 68 ++++++++++++++++++ ...tTestsApp_iphoneos13.2-arm64e-release.xctestrun | 68 ++++++++++++++++++ test/ios/ViewController.h | 6 ++ test/ios/ViewController.m | 22 ++++++ .../codesigning/UnitTestsApp.app.xcent.template | 16 +++++ .../UnitTestsAppTests.xctest.xcent.template | 16 +++++ .../XCTAutomationSupport.framework.xcent.template | 16 +++++ .../codesigning/XCTest.framework.xcent.template | 16 +++++ test/ios/codesigning/codesign_all.sh | 8 +++ test/ios/codesigning/generate-entitlements.swift | 40 +++++++++++ .../libXCTestSwiftSupport.dylib.xcent.template | 16 +++++ test/ios/fastlane/Appfile | 3 + test/ios/fastlane/Matchfile | 5 ++ test/ios/iosTestRunner.h | 9 +++ test/ios/iosTestRunner.mm | 82 ++++++++++++++++++++++ test/ios/ios_test_runner.cpp | 31 ++++++++ test/ios/ios_test_runner.hpp | 14 ++++ test/ios/main.m | 9 +++ test/ios/tests/Info.plist | 22 ++++++ test/ios/tests/Tests.m | 37 ++++++++++ 27 files changed, 675 insertions(+) create mode 100644 test/ios/AppDelegate.h create mode 100644 test/ios/AppDelegate.m create mode 100644 test/ios/Gemfile create mode 100644 test/ios/Info.plist create mode 100644 test/ios/LaunchScreen.storyboard create mode 100644 test/ios/Main.storyboard create mode 100644 test/ios/README.md create mode 100644 test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun create mode 100644 test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun create mode 100644 test/ios/ViewController.h create mode 100644 test/ios/ViewController.m create mode 100644 test/ios/codesigning/UnitTestsApp.app.xcent.template create mode 100644 test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template create mode 100644 test/ios/codesigning/XCTAutomationSupport.framework.xcent.template create mode 100644 test/ios/codesigning/XCTest.framework.xcent.template create mode 100755 test/ios/codesigning/codesign_all.sh create mode 100755 test/ios/codesigning/generate-entitlements.swift create mode 100644 test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template create mode 100644 test/ios/fastlane/Appfile create mode 100644 test/ios/fastlane/Matchfile create mode 100644 test/ios/iosTestRunner.h create mode 100644 test/ios/iosTestRunner.mm create mode 100644 test/ios/ios_test_runner.cpp create mode 100644 test/ios/ios_test_runner.hpp create mode 100644 test/ios/main.m create mode 100644 test/ios/tests/Info.plist create mode 100644 test/ios/tests/Tests.m (limited to 'test/ios') diff --git a/test/ios/AppDelegate.h b/test/ios/AppDelegate.h new file mode 100644 index 0000000000..134c8063dc --- /dev/null +++ b/test/ios/AppDelegate.h @@ -0,0 +1,7 @@ +#import // UIApplicationDelegate + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end \ No newline at end of file diff --git a/test/ios/AppDelegate.m b/test/ios/AppDelegate.m new file mode 100644 index 0000000000..874d18de2a --- /dev/null +++ b/test/ios/AppDelegate.m @@ -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 diff --git a/test/ios/Gemfile b/test/ios/Gemfile new file mode 100644 index 0000000000..adc90d98cf --- /dev/null +++ b/test/ios/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem "fastlane" \ No newline at end of file diff --git a/test/ios/Info.plist b/test/ios/Info.plist new file mode 100644 index 0000000000..c53d0d06e9 --- /dev/null +++ b/test/ios/Info.plist @@ -0,0 +1,62 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + UnitTestsApp + CFBundleIdentifier + com.mapbox.UnitTestsApp + CFBundleGetInfoString + com.mapbox.UnitTestsApp + CFBundleInfoDictionaryVersion + 1.0 + CFBundleLongVersionString + 1.0 + CFBundleName + com.mapbox.UnitTestsApp + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + MBGL + CFBundleVersion + 7877 + CSResourcesFileMapped + + NSHumanReadableCopyright + © 2014–2020 Mapbox + LSMinimumSystemVersion + ${MACOSX_DEPLOYMENT_TARGET} + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIBackgroundModes + + fetch + remote-notification + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + + \ No newline at end of file diff --git a/test/ios/LaunchScreen.storyboard b/test/ios/LaunchScreen.storyboard new file mode 100644 index 0000000000..c9b7564332 --- /dev/null +++ b/test/ios/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/ios/Main.storyboard b/test/ios/Main.storyboard new file mode 100644 index 0000000000..34d4c7e2ec --- /dev/null +++ b/test/ios/Main.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/ios/README.md b/test/ios/README.md new file mode 100644 index 0000000000..5b0d1f6a08 --- /dev/null +++ b/test/ios/README.md @@ -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. diff --git a/test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun new file mode 100644 index 0000000000..b6b7a9d1b0 --- /dev/null +++ b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun @@ -0,0 +1,68 @@ + + + + + UnitTestsAppTests + + BlueprintName + UnitTestsAppTests + BundleIdentifiersForCrashReportEmphasis + + com.mapbox.UnitTestsApp + com.mapbox.UnitTestsAppTests + + CommandLineArguments + + DependentProductPaths + + __TESTROOT__/Debug-iphoneos/UnitTestsApp.app + __TESTROOT__/Debug-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest + + EnvironmentVariables + + OS_ACTIVITY_DT_MODE + YES + SQLITE_ENABLE_THREAD_ASSERTIONS + 1 + + IsAppHostedTestBundle + + ProductModuleName + UnitTestsAppTests + RunOrder + 0 + SystemAttachmentLifetime + deleteOnSuccess + TestBundlePath + __TESTHOST__/PlugIns/UnitTestsAppTests.xctest + TestHostBundleIdentifier + com.mapbox.UnitTestsApp + TestHostPath + __TESTROOT__/Debug-iphoneos/UnitTestsApp.app + TestLanguage + + TestRegion + + TestingEnvironmentVariables + + DYLD_FALLBACK_FRAMEWORK_PATH + + DYLD_INSERT_LIBRARIES + __PLATFORMS__/iPhoneOS.platform/Developer/usr/lib/libXCTestBundleInject.dylib + XCInjectBundleInto + unused + + ToolchainsSettingValue + + UITargetAppCommandLineArguments + + UserAttachmentLifetime + deleteOnSuccess + + __xctestrun_metadata__ + + FormatVersion + 1 + + + diff --git a/test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun new file mode 100644 index 0000000000..02038a4417 --- /dev/null +++ b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun @@ -0,0 +1,68 @@ + + + + + UnitTestsAppTests + + BlueprintName + UnitTestsAppTests + BundleIdentifiersForCrashReportEmphasis + + com.mapbox.UnitTestsApp + com.mapbox.UnitTestsAppTests + + CommandLineArguments + + DependentProductPaths + + __TESTROOT__/Release-iphoneos/UnitTestsApp.app + __TESTROOT__/Release-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest + + EnvironmentVariables + + OS_ACTIVITY_DT_MODE + YES + SQLITE_ENABLE_THREAD_ASSERTIONS + 1 + + IsAppHostedTestBundle + + ProductModuleName + UnitTestsAppTests + RunOrder + 0 + SystemAttachmentLifetime + deleteOnSuccess + TestBundlePath + __TESTHOST__/PlugIns/UnitTestsAppTests.xctest + TestHostBundleIdentifier + com.mapbox.UnitTestsApp + TestHostPath + __TESTROOT__/Release-iphoneos/UnitTestsApp.app + TestLanguage + + TestRegion + + TestingEnvironmentVariables + + DYLD_FALLBACK_FRAMEWORK_PATH + + DYLD_INSERT_LIBRARIES + __PLATFORMS__/iPhoneOS.platform/Developer/usr/lib/libXCTestBundleInject.dylib + XCInjectBundleInto + unused + + ToolchainsSettingValue + + UITargetAppCommandLineArguments + + UserAttachmentLifetime + deleteOnSuccess + + __xctestrun_metadata__ + + FormatVersion + 1 + + + diff --git a/test/ios/ViewController.h b/test/ios/ViewController.h new file mode 100644 index 0000000000..9c7dfc57ec --- /dev/null +++ b/test/ios/ViewController.h @@ -0,0 +1,6 @@ +#import + +@interface ViewController : UIViewController + +@end + diff --git a/test/ios/ViewController.m b/test/ios/ViewController.m new file mode 100644 index 0000000000..e9c526122a --- /dev/null +++ b/test/ios/ViewController.m @@ -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 diff --git a/test/ios/codesigning/UnitTestsApp.app.xcent.template b/test/ios/codesigning/UnitTestsApp.app.xcent.template new file mode 100644 index 0000000000..a851541766 --- /dev/null +++ b/test/ios/codesigning/UnitTestsApp.app.xcent.template @@ -0,0 +1,16 @@ + + + + + application-identifier + $TEAM_ID.com.mapbox.UnitTestsApp + com.apple.developer.team-identifier + $TEAM_ID + get-task-allow + + keychain-access-groups + + $TEAM_ID.com.mapbox.UnitTestsApp + + + \ No newline at end of file diff --git a/test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template b/test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template @@ -0,0 +1,16 @@ + + + + + application-identifier + $TEAM_ID.com.mapbox.UnitTestsAppTests + com.apple.developer.team-identifier + $TEAM_ID + get-task-allow + + keychain-access-groups + + $TEAM_ID.com.mapbox.UnitTestsAppTests + + + \ No newline at end of file diff --git a/test/ios/codesigning/XCTAutomationSupport.framework.xcent.template b/test/ios/codesigning/XCTAutomationSupport.framework.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/XCTAutomationSupport.framework.xcent.template @@ -0,0 +1,16 @@ + + + + + application-identifier + $TEAM_ID.com.mapbox.UnitTestsAppTests + com.apple.developer.team-identifier + $TEAM_ID + get-task-allow + + keychain-access-groups + + $TEAM_ID.com.mapbox.UnitTestsAppTests + + + \ No newline at end of file diff --git a/test/ios/codesigning/XCTest.framework.xcent.template b/test/ios/codesigning/XCTest.framework.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/XCTest.framework.xcent.template @@ -0,0 +1,16 @@ + + + + + application-identifier + $TEAM_ID.com.mapbox.UnitTestsAppTests + com.apple.developer.team-identifier + $TEAM_ID + get-task-allow + + keychain-access-groups + + $TEAM_ID.com.mapbox.UnitTestsAppTests + + + \ No newline at end of file diff --git a/test/ios/codesigning/codesign_all.sh b/test/ios/codesigning/codesign_all.sh new file mode 100755 index 0000000000..1a6007ea94 --- /dev/null +++ b/test/ios/codesigning/codesign_all.sh @@ -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 diff --git a/test/ios/codesigning/generate-entitlements.swift b/test/ios/codesigning/generate-entitlements.swift new file mode 100755 index 0000000000..83834483bf --- /dev/null +++ b/test/ios/codesigning/generate-entitlements.swift @@ -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).") + } + } +} \ No newline at end of file diff --git a/test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template b/test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template @@ -0,0 +1,16 @@ + + + + + application-identifier + $TEAM_ID.com.mapbox.UnitTestsAppTests + com.apple.developer.team-identifier + $TEAM_ID + get-task-allow + + keychain-access-groups + + $TEAM_ID.com.mapbox.UnitTestsAppTests + + + \ No newline at end of file diff --git a/test/ios/fastlane/Appfile b/test/ios/fastlane/Appfile new file mode 100644 index 0000000000..f9e7e1e7c1 --- /dev/null +++ b/test/ios/fastlane/Appfile @@ -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 \ No newline at end of file diff --git a/test/ios/fastlane/Matchfile b/test/ios/fastlane/Matchfile new file mode 100644 index 0000000000..2a815bfc8e --- /dev/null +++ b/test/ios/fastlane/Matchfile @@ -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") \ No newline at end of file diff --git a/test/ios/iosTestRunner.h b/test/ios/iosTestRunner.h new file mode 100644 index 0000000000..dcbb77e9d4 --- /dev/null +++ b/test/ios/iosTestRunner.h @@ -0,0 +1,9 @@ +#import + +__attribute__((visibility ("default"))) +@interface IosTestRunner : NSObject + +- (NSString*) getResultPath; +- (BOOL) getTestStatus; + +@end diff --git a/test/ios/iosTestRunner.mm b/test/ios/iosTestRunner.mm new file mode 100644 index 0000000000..383b9036ec --- /dev/null +++ b/test/ios/iosTestRunner.mm @@ -0,0 +1,82 @@ +#import "iosTestRunner.h" + +#include "ios_test_runner.hpp" + +#include + +@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 diff --git a/test/ios/ios_test_runner.cpp b/test/ios/ios_test_runner.cpp new file mode 100644 index 0000000000..293a2955b5 --- /dev/null +++ b/test/ios/ios_test_runner.cpp @@ -0,0 +1,31 @@ +#include "ios_test_runner.hpp" + +#include + +#include + +#include +#include + +#define EXPORT __attribute__((visibility("default"))) + +EXPORT +bool TestRunner::startTest(const std::string& basePath) { + std::vector arguments = {"mbgl-test-runner", "--gtest_output=xml:" + basePath + "/test/results.xml"}; + std::vector argv; + for (const auto& arg : arguments) { + argv.push_back(const_cast(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(argv.size()), argv.data()); + mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '%d'", status); + + return status == 0; +} diff --git a/test/ios/ios_test_runner.hpp b/test/ios/ios_test_runner.hpp new file mode 100644 index 0000000000..3edae22828 --- /dev/null +++ b/test/ios/ios_test_runner.hpp @@ -0,0 +1,14 @@ +#ifndef ios_test_runner_hpp +#define ios_test_runner_hpp + +#include + +class TestRunner { +public: + TestRunner() = default; + ~TestRunner() = default; + + bool startTest(const std::string& basePath); +}; + +#endif /* ios_test_runner_hpp */ diff --git a/test/ios/main.m b/test/ios/main.m new file mode 100644 index 0000000000..f813c8fea9 --- /dev/null +++ b/test/ios/main.m @@ -0,0 +1,9 @@ +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/test/ios/tests/Info.plist b/test/ios/tests/Info.plist new file mode 100644 index 0000000000..ba6b34e5b6 --- /dev/null +++ b/test/ios/tests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + UnitTestsAppTests + CFBundleIdentifier + com.mapbox.UnitTestsAppTests + CFBundleInfoDictionaryVersion + 1.0 + CFBundleName + UnitTestsAppTests + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/test/ios/tests/Tests.m b/test/ios/tests/Tests.m new file mode 100644 index 0000000000..4c2131d61c --- /dev/null +++ b/test/ios/tests/Tests.m @@ -0,0 +1,37 @@ +#import +#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 -- cgit v1.2.1