Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
iOS test app: code refactoring, removed file, indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
enricogior committed Mar 1, 2017
1 parent 7c61c01 commit 0152624
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
4 changes: 0 additions & 4 deletions tools/ios-test/iOS-Test.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
5E38548E1E395EFB001B8813 /* main.js in Resources */ = {isa = PBXBuildFile; fileRef = 5E38548D1E395EFB001B8813 /* main.js */; };
5E5741111E380AA500BD866E /* libcares.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E5740F91E38098100BD866E /* libcares.a */; };
5E5741121E380AA500BD866E /* libchrome_zlib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E5740FA1E38098100BD866E /* libchrome_zlib.a */; };
5E5741131E380AA500BD866E /* libhttp_parser.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E5740FB1E38098100BD866E /* libhttp_parser.a */; };
Expand All @@ -31,7 +30,6 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
5E38548D1E395EFB001B8813 /* main.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = main.js; sourceTree = "<group>"; };
5E5740F91E38098100BD866E /* libcares.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcares.a; path = ../../out_ios/ios/bin/libcares.a; sourceTree = "<group>"; };
5E5740FA1E38098100BD866E /* libchrome_zlib.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libchrome_zlib.a; path = ../../out_ios/ios/bin/libchrome_zlib.a; sourceTree = "<group>"; };
5E5740FB1E38098100BD866E /* libhttp_parser.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libhttp_parser.a; path = ../../out_ios/ios/bin/libhttp_parser.a; sourceTree = "<group>"; };
Expand Down Expand Up @@ -105,7 +103,6 @@
5EF186D41E30305500A5F0DE /* iOS-Test */ = {
isa = PBXGroup;
children = (
5E38548D1E395EFB001B8813 /* main.js */,
5EF186EE1E3035DA00A5F0DE /* JXcoreCallback.h */,
5EF186F01E3035DA00A5F0DE /* TestRunner.h */,
5EF186F11E3035DA00A5F0DE /* TestRunner.m */,
Expand Down Expand Up @@ -213,7 +210,6 @@
5EF186E21E30305500A5F0DE /* Assets.xcassets in Resources */,
5EF186E01E30305500A5F0DE /* Main.storyboard in Resources */,
5EF187301E30403A00A5F0DE /* test in Resources */,
5E38548E1E395EFB001B8813 /* main.js in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
69 changes: 32 additions & 37 deletions tools/ios-test/iOS-Test/TestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ @implementation TestRunner
static NSMutableArray *scriptsQueue;
static NSMutableArray *nativeCallsQueue;
static NSString *requiredFile;
static NSString *srcTestsPath;
static NSString *dstTestsPath;

+ (NSArray*) listTests:(NSString*) path
{
Expand All @@ -238,22 +240,35 @@ + (NSArray*) listTests:(NSString*) path
}

+ (void) ReportMemory {
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&info,
&size);
if (kerr == KERN_SUCCESS) {
NSLog(@"Memory in use: %luMB", info.resident_size/1024/1024);
} else {
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
}
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&info,
&size);
if (kerr == KERN_SUCCESS) {
NSLog(@"Memory in use: %luMB", info.resident_size/1024/1024);
} else {
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
}
}

+ (void) CopyTestDir {
BOOL isDir;
if ([[NSFileManager defaultManager] fileExistsAtPath:dstTestsPath isDirectory:&isDir] && isDir) {
[[NSFileManager defaultManager] removeItemAtPath:dstTestsPath error:nil];
}

NSLog(@"Copying test files to temporary dir...");
NSError *copyError = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:srcTestsPath toPath:dstTestsPath error:&copyError]) {
NSLog(@"Error copying files: %@", [copyError localizedDescription]);
exit(1);
}
}

+ (void) startEngine:(NSString*) fileName
{

assert(mainEngineInitialized == false && "You can start JXcore main engine only once");
mainEngineInitialized = true;

Expand All @@ -263,33 +278,12 @@ + (void) startEngine:(NSString*) fileName
scriptsQueue = [[NSMutableArray alloc] init];
nativeCallsQueue = [[NSMutableArray alloc] init];

NSString *sandboxPath = NSHomeDirectory();
srcTestsPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:nil];
dstTestsPath = [NSString stringWithFormat:@"%@test", NSTemporaryDirectory()];

NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"js"];

NSString *homeFolder = sandboxPath;
NSUInteger location = [filePath rangeOfString:[NSString stringWithFormat:@"/%@.js", fileName]].location;
if (location > 0) {
homeFolder = [NSString stringWithFormat:@"%@/",[filePath substringToIndex:location]];
}

// We need to copy the test folder from the Application bundle to a temp folder
// where the tests have write access
NSLog(@"Copying test files to temporary dir...");
NSString *srcTestsPath = [NSString stringWithFormat:@"%@test", homeFolder];
NSString *dstTestsPath = [NSString stringWithFormat:@"%@test", NSTemporaryDirectory()];

BOOL isDir;
if ([[NSFileManager defaultManager] fileExistsAtPath:dstTestsPath isDirectory:&isDir] && isDir) {
[[NSFileManager defaultManager] removeItemAtPath:dstTestsPath error:nil];
}

NSError *copyError = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:srcTestsPath toPath:dstTestsPath error:&copyError]) {
NSLog(@"Error copying files: %@", [copyError localizedDescription]);
exit(1);
}
[TestRunner CopyTestDir];

NSString *homeFolder = [[NSBundle mainBundle] resourcePath];
NSString *fileContents = @"console.log('Main engine script done.');";

JX_InitializeOnce([homeFolder UTF8String]);
Expand Down Expand Up @@ -319,6 +313,7 @@ + (void) startEngine:(NSString*) fileName
for (i = 0; i < (int)[tests count]; i++)
{
// Remove and re-create the 'test/tmp' folder
BOOL isDir;
if ([[NSFileManager defaultManager] fileExistsAtPath:testTmpFolder isDirectory:&isDir] && isDir) {
[[NSFileManager defaultManager] removeItemAtPath:testTmpFolder error:nil];
}
Expand Down
3 changes: 0 additions & 3 deletions tools/ios-test/iOS-Test/main.js

This file was deleted.

0 comments on commit 0152624

Please sign in to comment.