diff options
Diffstat (limited to 'platform/ios/test')
-rw-r--r-- | platform/ios/test/common/ViewController.h | 6 | ||||
-rw-r--r-- | platform/ios/test/common/ViewController.m | 22 | ||||
-rw-r--r-- | platform/ios/test/common/iosTestRunner.mm | 83 |
3 files changed, 83 insertions, 28 deletions
diff --git a/platform/ios/test/common/ViewController.h b/platform/ios/test/common/ViewController.h deleted file mode 100644 index 9c7dfc57ec..0000000000 --- a/platform/ios/test/common/ViewController.h +++ /dev/null @@ -1,6 +0,0 @@ -#import <UIKit/UIKit.h> - -@interface ViewController : UIViewController - -@end - diff --git a/platform/ios/test/common/ViewController.m b/platform/ios/test/common/ViewController.m deleted file mode 100644 index e9c526122a..0000000000 --- a/platform/ios/test/common/ViewController.m +++ /dev/null @@ -1,22 +0,0 @@ -#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/iosTestRunner.mm b/platform/ios/test/common/iosTestRunner.mm new file mode 100644 index 0000000000..b1efa74e6a --- /dev/null +++ b/platform/ios/test/common/iosTestRunner.mm @@ -0,0 +1,83 @@ +#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: dataDir]) { + 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; + } + } + NSString *baseDir = [documentsDir stringByAppendingPathComponent: dataDir]; + std::string basePath = std::string([baseDir UTF8String]); + self.testStatus = self.runner->startTest(basePath) ? YES : NO; + self.resultPath = [baseDir stringByAppendingPathComponent: resultFilePath]; + + 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 |