Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (109 sloc) 4.49 KB
#import <AppKit/AppKit.h>
#import "Simulator.h"
#import "termios.h"
static BOOL gReset = false;
void printUsage();
void resetSignal(int sig);
int main(int argc, char *argv[]) {
signal(SIGQUIT, resetSignal);
int c;
char *sdk = nil;
char *family = nil;
char *appPath = nil;
char *videoPath = nil;
char *testBundle = nil;
NSMutableArray *additionalArgs = [NSMutableArray array];
NSMutableDictionary *environment = [NSMutableDictionary dictionary];
NSString *environment_variable;
NSArray *environment_variable_parts;
while ((c = getopt(argc, argv, "e:s:f:v:t:ah")) != -1) {
switch(c) {
case 'e':
environment_variable = [NSString stringWithCString:optarg encoding:NSUTF8StringEncoding];
environment_variable_parts = [environment_variable componentsSeparatedByString:@"="];
[environment setObject:[environment_variable_parts objectAtIndex:1] forKey:[environment_variable_parts objectAtIndex:0]];
case 's':
sdk = optarg;
case 'f':
family = optarg;
case 'a':
fprintf(stdout, "Available SDK Versions.\n");
for (NSString *sdkVersion in [Simulator availableSDKs]) {
fprintf(stderr, " %s\n", [sdkVersion UTF8String]);
return 1;
case 'h':
return 1;
case 'v':
videoPath = optarg;
case 't':
testBundle = optarg;
case '?':
if (optopt == 's' || optopt == 'f') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
return 1;
abort ();
if (argc > optind) {
appPath = argv[optind++];
// Additional args are sent to app
for (int i = optind; i < argc; i++) {
[additionalArgs addObject:[NSString stringWithUTF8String:argv[i]]];
else {
fprintf(stderr, "No app-path was specified!\n");
return 1;
NSString *sdkString = sdk ? [NSString stringWithUTF8String:sdk] : nil;
NSString *familyString = family ? [NSString stringWithUTF8String:family] : nil;
NSString *appPathString = [NSString stringWithUTF8String:appPath];
NSString *videoPathString = videoPath ? [NSString stringWithUTF8String:videoPath] : nil;
if (testBundle) {
NSString *testBundlePathString = [NSString stringWithUTF8String:testBundle];
if (![[NSFileManager defaultManager] fileExistsAtPath:testBundlePathString]) {
fprintf(stderr, "The test bundle at '%s' was not found",testBundle);
return 1;
[environment setObject:testBundlePathString forKey:@"XCInjectBundle"];
[environment setObject:appPathString forKey:@"XCInjectBundleInto"];
[environment setObject:@"/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection" forKey:@"DYLD_INSERT_LIBRARIES"];
[additionalArgs addObject:@"-SenTest"];
[additionalArgs addObject:@"All"];
Simulator *simulator = [[Simulator alloc] initWithAppPath:appPathString sdk:sdkString family:familyString video:videoPathString env:environment args:additionalArgs];
[simulator launch];
[[NSRunLoop mainRunLoop] run];
return 0;
void printUsage() {
fprintf(stderr, "usage: waxsim [options] app-path\n");
fprintf(stderr, "example: waxsim -s 2.2 /path/to/\n");
fprintf(stderr, "Available options are:\n");
fprintf(stderr, "\t-s sdk\tVersion number of sdk to use (-s 3.1)\n");
fprintf(stderr, "\t-f family\tDevice to use (-f ipad)\n");
fprintf(stderr, "\t-e VAR=value\tEnvironment variable to set (-e CFFIXED_HOME=/tmp/iphonehome)\n");
fprintf(stderr, "\t-t test-bundle\tinject test-bundle into app and run all tests\n");
fprintf(stderr, "\t-a \tAvailable SDKs\n");
fprintf(stderr, "\t-v path\tOutput video recording at path\n");
fprintf(stderr, "\t-h \tPrints out this wonderful documentation!\n");
void resetSignal(int sig) {
gReset = true;