Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial push

  • Loading branch information...
commit 0507035afcd662b0aa747c3006908b8530588652 1 parent 1fd07ca
@jhaynie authored
View
1  .gitignore
@@ -0,0 +1 @@
+iphonesim
View
21 Makefile
@@ -0,0 +1,21 @@
+CC=gcc
+
+SIM_PRIVATE_FRAMEWORK_DIR=/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks
+CFLAGS=-Wall -Werror -I. -ISource
+LDFLAGS=-framework AppKit -F${SIM_PRIVATE_FRAMEWORK_DIR} -framework iPhoneSimulatorRemoteClient -Wl,-rpath -Wl,${SIM_PRIVATE_FRAMEWORK_DIR}
+OBJS= \
+ Source/main.o \
+ Source/nsprintf.o \
+ Source/iPhoneSimulator.o
+
+.SUFFIXES: .m
+.m.o:
+ ${CC} ${CFLAGS} -c $< -o $@
+
+all: iphonesim
+
+iphonesim: ${OBJS}
+ ${CC} -o $@ ${OBJS} ${LDFLAGS}
+
+clean:
+ rm -f ${OBJS} iphonesim
View
58 README
@@ -0,0 +1,58 @@
+ iPhone Simulator
+ ----------------
+
+ The iPhone Simulator is a simple command line utility for
+ launching an iphone application in the simulator. This allows
+ for nice things like automated testing of unit tests, etc without
+ having to open XCode.
+
+ The original code was written by Landon Fuller (with license
+ below). Minor modifications made by Jeff Haynie (Appcelerator).
+
+
+ You can run the application by first building your application in
+ xcode using the xcodebuild command from the command line. You can
+ then run it in the simulator using the following as an example:
+
+ ./iphonesim launch ~/tmp/yourproject/build/Debug.simulator/yourproject.app
+
+ You need to point to either Debug.simulator or Release.simulator based
+ on which build type you built with.
+
+
+ Cheers!
+
+ Jeff Haynie
+ jhaynie@appcelerator.com
+
+
+
+ Author: Landon Fuller <landonf@plausiblelabs.com>
+ Copyright (c) 2008 Plausible Labs Cooperative, Inc.
+ All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+
+ Modifications made by Appcelerator, Inc. relicensed under
+ the same license as above.
+
View
1  Source/.gitignore
@@ -0,0 +1 @@
+*.o
View
42 Source/iPhoneSimulator.h
@@ -0,0 +1,42 @@
+/*
+ * Author: Landon Fuller <landonf@plausiblelabs.com>
+ * Copyright (c) 2008 Plausible Labs Cooperative, Inc.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ /**
+ * Modifications made by Appcelerator, Inc. relicensed under
+ * the same license as above.
+ */
+
+#import <Foundation/Foundation.h>
+#import <iPhoneSimulatorRemoteClient/iPhoneSimulatorRemoteClient.h>
+
+@interface iPhoneSimulator : NSObject <DTiPhoneSimulatorSessionDelegate> {
+@private
+}
+
+- (void) runWithArgc: (int) argc argv: (char **) argv;
+
+@end
View
164 Source/iPhoneSimulator.m
@@ -0,0 +1,164 @@
+/*
+ * Author: Landon Fuller <landonf@plausiblelabs.com>
+ * Copyright (c) 2008 Plausible Labs Cooperative, Inc.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ /**
+ * Modifications made by Appcelerator, Inc. licensed under the
+ * same license as above.
+ */
+
+#import "iPhoneSimulator.h"
+#import "nsprintf.h"
+
+
+/**
+ * A simple iPhoneSimulatorRemoteClient framework.
+ */
+@implementation iPhoneSimulator
+
+/**
+ * Print usage.
+ */
+- (void) printUsage {
+ fprintf(stderr, "Usage: iphonesim <options> <command> ...\n");
+ fprintf(stderr, "Commands:\n");
+ fprintf(stderr, " showsdks\n");
+ fprintf(stderr, " launch <application path>\n");
+}
+
+
+/**
+ * List available SDK roots.
+ */
+- (int) showSDKs {
+ NSArray *roots = [DTiPhoneSimulatorSystemRoot knownRoots];
+
+ nsprintf(@"Simulator SDK Roots:\n");
+ for (DTiPhoneSimulatorSystemRoot *root in roots) {
+ nsfprintf(stderr, @"'%@' (%@)\n\t%@\n", [root sdkDisplayName], [root sdkVersion], [root sdkRootPath]);
+ }
+
+ return EXIT_SUCCESS;
+}
+
+- (void) session: (DTiPhoneSimulatorSession *) session didEndWithError: (NSError *) error {
+ nsprintf(@"Session did end with error %@\n", error);
+
+ if (error != nil)
+ exit(EXIT_FAILURE);
+
+ exit(EXIT_SUCCESS);
+}
+
+
+- (void) session: (DTiPhoneSimulatorSession *) session didStart: (BOOL) started withError: (NSError *) error {
+ if (started) {
+ nsprintf(@"Session started\n");
+ } else {
+ nsprintf(@"Session could not be started: %@", error);
+ exit(EXIT_FAILURE);
+ }
+}
+
+
+/**
+ * Launch the given Simulator binary.
+ */
+- (int) launchApp: (NSString *) path {
+ DTiPhoneSimulatorApplicationSpecifier *appSpec;
+ DTiPhoneSimulatorSystemRoot *sdkRoot;
+ DTiPhoneSimulatorSessionConfig *config;
+ DTiPhoneSimulatorSession *session;
+ NSError *error;
+
+ /* Create the app specifier */
+ appSpec = [DTiPhoneSimulatorApplicationSpecifier specifierWithApplicationPath: path];
+ if (appSpec == nil) {
+ nsprintf(@"Could not load application specification for %s", path);
+ return EXIT_FAILURE;
+ }
+ nsprintf(@"App Spec: %@\n", appSpec);
+
+ /* Load the default SDK root */
+ sdkRoot = [DTiPhoneSimulatorSystemRoot defaultRoot];
+ nsprintf(@"SDK Root: %@\n", sdkRoot);
+
+ /* Set up the session configuration */
+ config = [[[DTiPhoneSimulatorSessionConfig alloc] init] autorelease];
+ [config setApplicationToSimulateOnStart: appSpec];
+ [config setSimulatedSystemRoot: sdkRoot];
+ [config setSimulatedApplicationShouldWaitForDebugger: NO];
+
+ [config setSimulatedApplicationLaunchArgs: [NSArray array]];
+ [config setSimulatedApplicationLaunchEnvironment: [NSDictionary dictionary]];
+
+ [config setLocalizedClientName: @"TitaniumDeveloper"];
+
+ /* Start the session */
+ session = [[[DTiPhoneSimulatorSession alloc] init] autorelease];
+ [session setDelegate: self];
+ [session setSimulatedApplicationPID: [NSNumber numberWithInt: 35]];
+
+ if (![session requestStartWithConfig: config timeout: 10 error: &error]) {
+ nsprintf(@"Could not start simulator session: %@", error);
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+/**
+ * Execute 'main'
+ */
+- (void) runWithArgc: (int) argc argv: (char **) argv {
+ /* Read the command */
+ if (argc < 2) {
+ [self printUsage];
+ exit(EXIT_FAILURE);
+ }
+
+ if (strcmp(argv[1], "showsdks") == 0) {
+ exit([self showSDKs]);
+ }
+ else if (strcmp(argv[1], "launch") == 0) {
+ /* Requires an additional argument */
+ if (argc < 3) {
+ fprintf(stderr, "Missing application path argument\n");
+ [self printUsage];
+ exit(EXIT_FAILURE);
+ }
+
+ /* Don't exit, adds to runloop */
+ [self launchApp: [NSString stringWithUTF8String: argv[2]]];
+ } else {
+ fprintf(stderr, "Unknown command\n");
+ [self printUsage];
+ exit(EXIT_FAILURE);
+ }
+}
+
+@end
View
52 Source/main.m
@@ -0,0 +1,52 @@
+/*
+ * Author: Landon Fuller <landonf@plausiblelabs.com>
+ * Copyright (c) 2008 Plausible Labs Cooperative, Inc.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ /**
+ * Some modifications made by Appcelerator which are licensed
+ * under the same license as above.
+ */
+
+#import <AppKit/AppKit.h>
+
+#import "iPhoneSimulator.h"
+
+/*
+ * Runs the iPhoneSimulator backed by a main runloop.
+ */
+int main (int argc, char *argv[]) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ iPhoneSimulator *sim = [[iPhoneSimulator alloc] init];
+
+ /* Execute command line handler */
+ [sim runWithArgc: argc argv: argv];
+
+ /* Run the loop to handle added input sources, if any */
+ [[NSRunLoop mainRunLoop] run];
+
+ [pool release];
+ return 0;
+}
View
3  Source/nsprintf.h
@@ -0,0 +1,3 @@
+int nsvfprintf (FILE *stream, NSString *format, va_list args);
+int nsfprintf (FILE *stream, NSString *format, ...);
+int nsprintf (NSString *format, ...);
View
42 Source/nsprintf.m
@@ -0,0 +1,42 @@
+/*
+ * NSLog() clone, but writes to arbitrary output stream
+ */
+
+#import <Foundation/Foundation.h>
+#import <stdio.h>
+
+int nsvfprintf (FILE *stream, NSString *format, va_list args) {
+ int retval;
+
+ NSString *str = (NSString *) CFStringCreateWithFormatAndArguments(NULL, NULL, (CFStringRef) format, args);
+ retval = fprintf(stream, [str UTF8String]);
+ [str release];
+
+ return retval;
+}
+
+int nsfprintf (FILE *stream, NSString *format, ...) {
+ va_list ap;
+ int retval;
+
+ va_start(ap, format);
+ {
+ retval = nsvfprintf(stream, format, ap);
+ }
+ va_end(ap);
+
+ return retval;
+}
+
+int nsprintf (NSString *format, ...) {
+ va_list ap;
+ int retval;
+
+ va_start(ap, format);
+ {
+ retval = nsvfprintf(stderr, format, ap);
+ }
+ va_end(ap);
+
+ return retval;
+}
View
121 iPhoneSimulatorRemoteClient/iPhoneSimulatorRemoteClient.h
@@ -0,0 +1,121 @@
+#import <Cocoa/Cocoa.h>
+
+/*
+ * File: /Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework/Versions/A/iPhoneSimulatorRemoteClient
+ * Arch: Intel 80x86 (i386)
+ * Current version: 12.0.0, Compatibility version: 1.0.0
+ */
+
+@class DTiPhoneSimulatorSession;
+
+@protocol DTiPhoneSimulatorSessionDelegate
+
+- (void) session: (DTiPhoneSimulatorSession *) session didEndWithError: (NSError *) error;
+- (void) session: (DTiPhoneSimulatorSession *) session didStart: (BOOL) started withError: (NSError *) error;
+
+@end
+
+@interface DTiPhoneSimulatorApplicationSpecifier : NSObject <NSCopying>
+{
+ NSString *_appPath;
+ NSString *_bundleID;
+}
+
++ (id) specifierWithApplicationPath: (NSString *) appPath;
++ (id) specifierWithApplicationBundleIdentifier: (NSString *) bundleID;
+- (NSString *) bundleID;
+- (void) setBundleID: (NSString *) bundleId;
+- (NSString *) appPath;
+- (void) setAppPath: (NSString *) appPath;
+
+@end
+
+@interface DTiPhoneSimulatorSystemRoot : NSObject <NSCopying>
+{
+ NSString *sdkRootPath;
+ NSString *sdkVersion;
+ NSString *sdkDisplayName;
+}
+
++ (id) defaultRoot;
+
++ (id)rootWithSDKPath:(id)fp8;
++ (id)rootWithSDKVersion:(id)fp8;
++ (NSArray *) knownRoots;
+- (id)initWithSDKPath:(id)fp8;
+- (id)sdkDisplayName;
+- (void)setSdkDisplayName:(id)fp8;
+- (id)sdkVersion;
+- (void)setSdkVersion:(id)fp8;
+- (id)sdkRootPath;
+- (void)setSdkRootPath:(id)fp8;
+
+@end
+
+
+
+@interface DTiPhoneSimulatorSessionConfig : NSObject <NSCopying>
+{
+ NSString *_localizedClientName;
+ DTiPhoneSimulatorSystemRoot *_simulatedSystemRoot;
+ DTiPhoneSimulatorApplicationSpecifier *_applicationToSimulateOnStart;
+ NSArray *_simulatedApplicationLaunchArgs;
+ NSDictionary *_simulatedApplicationLaunchEnvironment;
+ BOOL _simulatedApplicationShouldWaitForDebugger;
+ NSString *_simulatedApplicationStdOutPath;
+ NSString *_simulatedApplicationStdErrPath;
+}
+
+- (id)simulatedApplicationStdErrPath;
+- (void)setSimulatedApplicationStdErrPath:(id)fp8;
+- (id)simulatedApplicationStdOutPath;
+- (void)setSimulatedApplicationStdOutPath:(id)fp8;
+- (id)simulatedApplicationLaunchEnvironment;
+- (void)setSimulatedApplicationLaunchEnvironment:(id)fp8;
+- (id)simulatedApplicationLaunchArgs;
+- (void)setSimulatedApplicationLaunchArgs:(id)fp8;
+
+- (DTiPhoneSimulatorApplicationSpecifier *) applicationToSimulateOnStart;
+- (void) setApplicationToSimulateOnStart: (DTiPhoneSimulatorApplicationSpecifier *) appSpec;
+- (DTiPhoneSimulatorSystemRoot *) simulatedSystemRoot;
+- (void) setSimulatedSystemRoot: (DTiPhoneSimulatorSystemRoot *) simulatedSystemRoot;
+
+
+- (BOOL) simulatedApplicationShouldWaitForDebugger;
+- (void) setSimulatedApplicationShouldWaitForDebugger: (BOOL) waitForDebugger;
+
+- (id)localizedClientName;
+- (void)setLocalizedClientName:(id)fp8;
+
+@end
+
+
+@interface DTiPhoneSimulatorSession : NSObject {
+ NSString *_uuid;
+ id <DTiPhoneSimulatorSessionDelegate> _delegate;
+ NSNumber *_simulatedApplicationPID;
+ int _sessionLifecycleProgress;
+ NSTimer *_timeoutTimer;
+ DTiPhoneSimulatorSessionConfig *_sessionConfig;
+ struct ProcessSerialNumber _simulatorPSN;
+}
+
+- (BOOL) requestStartWithConfig: (DTiPhoneSimulatorSessionConfig *) config timeout: (NSTimeInterval) timeout error: (NSError **) outError;
+- (void) requestEndWithTimeout: (NSTimeInterval) timeout;
+
+- (id)sessionConfig;
+- (void)setSessionConfig:(id)fp8;
+- (id)timeoutTimer;
+- (void)setTimeoutTimer:(id)fp8;
+- (int)sessionLifecycleProgress;
+- (void)setSessionLifecycleProgress:(int)fp8;
+- (id)simulatedApplicationPID;
+- (void)setSimulatedApplicationPID:(id)fp8;
+
+- (id<DTiPhoneSimulatorSessionDelegate>) delegate;
+- (void) setDelegate: (id<DTiPhoneSimulatorSessionDelegate>) delegate;
+
+- (id)uuid;
+- (void)setUuid:(id)fp8;
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.