From 6d815401b10aaf7facba5f0676931a9908c1ba5b Mon Sep 17 00:00:00 2001 From: Juha Alanen Date: Thu, 13 Feb 2020 14:12:44 +0200 Subject: [test-runner] Share common code between iOS test runners --- platform/ios/ios.cmake | 82 ++++++++++-------------- platform/ios/test/common/AppDelegate.h | 7 ++ platform/ios/test/common/AppDelegate.m | 38 +++++++++++ platform/ios/test/common/LaunchScreen.storyboard | 27 ++++++++ platform/ios/test/common/Main.storyboard | 27 ++++++++ platform/ios/test/common/Tests.m | 37 +++++++++++ platform/ios/test/common/ViewController.h | 6 ++ platform/ios/test/common/ViewController.m | 22 +++++++ platform/ios/test/common/ios_test_runner.hpp | 14 ++++ platform/ios/test/common/main.m | 9 +++ 10 files changed, 220 insertions(+), 49 deletions(-) create mode 100644 platform/ios/test/common/AppDelegate.h create mode 100644 platform/ios/test/common/AppDelegate.m create mode 100644 platform/ios/test/common/LaunchScreen.storyboard create mode 100644 platform/ios/test/common/Main.storyboard create mode 100644 platform/ios/test/common/Tests.m create mode 100644 platform/ios/test/common/ViewController.h create mode 100644 platform/ios/test/common/ViewController.m create mode 100644 platform/ios/test/common/ios_test_runner.hpp create mode 100644 platform/ios/test/common/main.m (limited to 'platform') diff --git a/platform/ios/ios.cmake b/platform/ios/ios.cmake index 85b22afcc0..16d0ed41c2 100644 --- a/platform/ios/ios.cmake +++ b/platform/ios/ios.cmake @@ -94,30 +94,26 @@ target_link_libraries( ) if(MBGL_IOS_RENDER_TEST) - set(CMAKE_OSX_ARCHITECTURES "armv7;i386;x86_64;arm64") - include(${PROJECT_SOURCE_DIR}/vendor/zip-archive.cmake) initialize_ios_target(mbgl-vendor-zip-archive) set(PREPARE_CMD "${PROJECT_SOURCE_DIR}/render-test/ios/setup_test_data.sh") - message("COMMAND: ${PREPARE_CMD}") execute_process(COMMAND ${PREPARE_CMD} RESULT_VARIABLE CMD_ERROR WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) - message(STATUS "CMD_ERROR:" ${CMD_ERROR}) - set(RESOURCES ${PROJECT_SOURCE_DIR}/render-test/ios/Main.storyboard ${PROJECT_SOURCE_DIR}/render-test/ios/LaunchScreen.storyboard - ${PROJECT_SOURCE_DIR}/test-data) + set(RESOURCES ${PROJECT_SOURCE_DIR}/platform/ios/test/common/Main.storyboard + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/LaunchScreen.storyboard ${PROJECT_SOURCE_DIR}/test-data) add_executable( RenderTestApp - ${PROJECT_SOURCE_DIR}/render-test/ios/ios_test_runner.hpp + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/ios_test_runner.hpp + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/AppDelegate.h + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/AppDelegate.m + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/ViewController.h + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/ViewController.m + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/main.m ${PROJECT_SOURCE_DIR}/render-test/ios/ios_test_runner.cpp - ${PROJECT_SOURCE_DIR}/render-test/ios/AppDelegate.h - ${PROJECT_SOURCE_DIR}/render-test/ios/AppDelegate.m - ${PROJECT_SOURCE_DIR}/render-test/ios/ViewController.h - ${PROJECT_SOURCE_DIR}/render-test/ios/ViewController.m ${PROJECT_SOURCE_DIR}/render-test/ios/iosTestRunner.h ${PROJECT_SOURCE_DIR}/render-test/ios/iosTestRunner.mm - ${PROJECT_SOURCE_DIR}/render-test/ios/main.m ${RESOURCES} ) initialize_ios_target(RenderTestApp) @@ -147,6 +143,7 @@ if(MBGL_IOS_RENDER_TEST) ${PROJECT_SOURCE_DIR}/platform/darwin/include ${PROJECT_SOURCE_DIR}/platform/darwin/include/mbgl/interface/ ${PROJECT_SOURCE_DIR}/platform/default/include + ${PROJECT_SOURCE_DIR}/platform/ios/test/common ${PROJECT_SOURCE_DIR}/src ) @@ -168,19 +165,13 @@ if(MBGL_IOS_RENDER_TEST) mbgl-vendor-zip-archive ) + set_target_properties(RenderTestApp PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "") + set_target_properties(RenderTestApp PROPERTIES XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") + find_package(XCTest REQUIRED) xctest_add_bundle(RenderTestAppTests RenderTestApp ${PROJECT_SOURCE_DIR}/render-test/ios/tests/Tests.m) - set_target_properties( - RenderTestAppTests - PROPERTIES - XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET - "${IOS_DEPLOYMENT_TARGET}" - XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH - $<$:YES> - ) - target_include_directories( RenderTestAppTests PUBLIC ${PROJECT_SOURCE_DIR}/render-test/ios @@ -188,7 +179,11 @@ if(MBGL_IOS_RENDER_TEST) xctest_add_test(XCTest.RenderTestApp RenderTestAppTests) + set_target_properties(RenderTestAppTests PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}") + set_target_properties(RenderTestAppTests PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$:YES>) set_target_properties(RenderTestAppTests PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/render-test/ios/tests/Info.plist) + set_target_properties(RenderTestAppTests PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "") + set_target_properties(RenderTestAppTests PROPERTIES XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") endif() if(MBGL_IOS_UNIT_TEST) @@ -199,24 +194,20 @@ if(MBGL_IOS_UNIT_TEST) ${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 - ) + set(RESOURCES ${PROJECT_SOURCE_DIR}/platform/ios/test/common/Main.storyboard + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/LaunchScreen.storyboard ${CMAKE_CURRENT_BINARY_DIR}/test-data) add_executable( UnitTestsApp - ${PROJECT_SOURCE_DIR}/test/ios/ios_test_runner.hpp + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/ios_test_runner.hpp + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/AppDelegate.h + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/AppDelegate.m + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/ViewController.h + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/ViewController.m + ${PROJECT_SOURCE_DIR}/platform/ios/test/common/main.m ${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) @@ -236,12 +227,11 @@ if(MBGL_IOS_UNIT_TEST) target_include_directories( UnitTestsApp - PUBLIC {MBGL_ROOT}/test/include ${PROJECT_SOURCE_DIR}/include - ) - - target_include_directories( - UnitTestsApp - PUBLIC ${PROJECT_SOURCE_DIR}/test/ios + PUBLIC + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/platform/ios/test/common + ${PROJECT_SOURCE_DIR}/test/include + ${PROJECT_SOURCE_DIR}/test/ios ) target_link_libraries( @@ -263,16 +253,7 @@ if(MBGL_IOS_UNIT_TEST) 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 - $<$:YES> - ) + xctest_add_bundle(UnitTestsAppTests UnitTestsApp ${PROJECT_SOURCE_DIR}/platform/ios/test/common/Tests.m) target_include_directories( UnitTestsAppTests @@ -281,8 +262,11 @@ if(MBGL_IOS_UNIT_TEST) xctest_add_test(XCTest.UnitTestsApp UnitTestsAppTests) + set_target_properties(UnitTestsAppTests PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}") + set_target_properties(UnitTestsAppTests PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$:YES>) 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) diff --git a/platform/ios/test/common/AppDelegate.h b/platform/ios/test/common/AppDelegate.h new file mode 100644 index 0000000000..134c8063dc --- /dev/null +++ b/platform/ios/test/common/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/platform/ios/test/common/AppDelegate.m b/platform/ios/test/common/AppDelegate.m new file mode 100644 index 0000000000..874d18de2a --- /dev/null +++ b/platform/ios/test/common/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/platform/ios/test/common/LaunchScreen.storyboard b/platform/ios/test/common/LaunchScreen.storyboard new file mode 100644 index 0000000000..c9b7564332 --- /dev/null +++ b/platform/ios/test/common/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/ios/test/common/Main.storyboard b/platform/ios/test/common/Main.storyboard new file mode 100644 index 0000000000..34d4c7e2ec --- /dev/null +++ b/platform/ios/test/common/Main.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/ios/test/common/Tests.m b/platform/ios/test/common/Tests.m new file mode 100644 index 0000000000..8d0719705a --- /dev/null +++ b/platform/ios/test/common/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)testStartTestRunner { + 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 diff --git a/platform/ios/test/common/ViewController.h b/platform/ios/test/common/ViewController.h new file mode 100644 index 0000000000..9c7dfc57ec --- /dev/null +++ b/platform/ios/test/common/ViewController.h @@ -0,0 +1,6 @@ +#import + +@interface ViewController : UIViewController + +@end + diff --git a/platform/ios/test/common/ViewController.m b/platform/ios/test/common/ViewController.m new file mode 100644 index 0000000000..e9c526122a --- /dev/null +++ b/platform/ios/test/common/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/platform/ios/test/common/ios_test_runner.hpp b/platform/ios/test/common/ios_test_runner.hpp new file mode 100644 index 0000000000..db263dc73c --- /dev/null +++ b/platform/ios/test/common/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& path); +}; + +#endif /* ios_test_runner_hpp */ diff --git a/platform/ios/test/common/main.m b/platform/ios/test/common/main.m new file mode 100644 index 0000000000..f813c8fea9 --- /dev/null +++ b/platform/ios/test/common/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])); + } +} -- cgit v1.2.1