iCuke 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/.gitignore +13 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +69 -0
  4. data/Rakefile +80 -0
  5. data/VERSION +1 -0
  6. data/app/iCuke/.gitignore +1 -0
  7. data/app/iCuke/Classes/FlipsideView.h +13 -0
  8. data/app/iCuke/Classes/FlipsideView.m +32 -0
  9. data/app/iCuke/Classes/FlipsideViewController.h +25 -0
  10. data/app/iCuke/Classes/FlipsideViewController.m +54 -0
  11. data/app/iCuke/Classes/MainView.h +15 -0
  12. data/app/iCuke/Classes/MainView.m +32 -0
  13. data/app/iCuke/Classes/MainViewController.h +16 -0
  14. data/app/iCuke/Classes/MainViewController.m +86 -0
  15. data/app/iCuke/Classes/iCukeAppDelegate.h +20 -0
  16. data/app/iCuke/Classes/iCukeAppDelegate.m +33 -0
  17. data/app/iCuke/FlipsideView.xib +444 -0
  18. data/app/iCuke/MainView.xib +520 -0
  19. data/app/iCuke/MainWindow.xib +355 -0
  20. data/app/iCuke/SniffingView.h +20 -0
  21. data/app/iCuke/SniffingView.m +191 -0
  22. data/app/iCuke/iCuke-Info.plist +30 -0
  23. data/app/iCuke/iCuke.xcodeproj/project.pbxproj +313 -0
  24. data/app/iCuke/iCuke_Prefix.pch +14 -0
  25. data/app/iCuke/main.m +16 -0
  26. data/ext/iCuke/.gitignore +2 -0
  27. data/ext/iCuke/DefaultsResponse.h +5 -0
  28. data/ext/iCuke/DefaultsResponse.m +67 -0
  29. data/ext/iCuke/EventResponse.h +5 -0
  30. data/ext/iCuke/EventResponse.m +122 -0
  31. data/ext/iCuke/Rakefile +22 -0
  32. data/ext/iCuke/Recorder.h +15 -0
  33. data/ext/iCuke/Recorder.m +85 -0
  34. data/ext/iCuke/RecorderResponse.h +5 -0
  35. data/ext/iCuke/RecorderResponse.m +59 -0
  36. data/ext/iCuke/SynthesizeSingleton.h +68 -0
  37. data/ext/iCuke/ViewResponse.h +5 -0
  38. data/ext/iCuke/ViewResponse.m +84 -0
  39. data/ext/iCuke/Viewer.h +8 -0
  40. data/ext/iCuke/Viewer.m +153 -0
  41. data/ext/iCuke/iCukeHTTPResponseHandler.h +50 -0
  42. data/ext/iCuke/iCukeHTTPResponseHandler.m +381 -0
  43. data/ext/iCuke/iCukeHTTPServer.h +53 -0
  44. data/ext/iCuke/iCukeHTTPServer.m +365 -0
  45. data/ext/iCuke/iCukeServer.h +16 -0
  46. data/ext/iCuke/iCukeServer.m +46 -0
  47. data/ext/iCuke/json/JSON.h +50 -0
  48. data/ext/iCuke/json/NSObject+SBJSON.h +68 -0
  49. data/ext/iCuke/json/NSObject+SBJSON.m +53 -0
  50. data/ext/iCuke/json/NSString+SBJSON.h +58 -0
  51. data/ext/iCuke/json/NSString+SBJSON.m +55 -0
  52. data/ext/iCuke/json/SBJSON.h +75 -0
  53. data/ext/iCuke/json/SBJSON.m +212 -0
  54. data/ext/iCuke/json/SBJsonBase.h +86 -0
  55. data/ext/iCuke/json/SBJsonBase.m +78 -0
  56. data/ext/iCuke/json/SBJsonParser.h +87 -0
  57. data/ext/iCuke/json/SBJsonParser.m +475 -0
  58. data/ext/iCuke/json/SBJsonWriter.h +129 -0
  59. data/ext/iCuke/json/SBJsonWriter.m +228 -0
  60. data/features/icuke.feature +17 -0
  61. data/features/support/env.rb +3 -0
  62. data/iCuke.gemspec +113 -0
  63. data/lib/icuke/cucumber.rb +211 -0
  64. data/lib/icuke/simulate.rb +132 -0
  65. data/lib/icuke/simulator.rb +107 -0
  66. data/lib/icuke.rb +1 -0
  67. metadata +163 -0
@@ -0,0 +1,59 @@
1
+ #import "RecorderResponse.h"
2
+ #import "iCukeHTTPServer.h"
3
+ #import "Recorder.h"
4
+
5
+ @implementation RecorderResponse
6
+ + (void)load
7
+ {
8
+ [iCukeHTTPResponseHandler registerHandler:self];
9
+ }
10
+
11
+ + (BOOL)canHandleRequest:(CFHTTPMessageRef)aRequest
12
+ method:(NSString *)requestMethod
13
+ url:(NSURL *)requestURL
14
+ headerFields:(NSDictionary *)requestHeaderFields
15
+ {
16
+ if ([requestURL.path isEqualToString:@"/record"] ||
17
+ [requestURL.path isEqualToString:@"/play"] ||
18
+ [requestURL.path isEqualToString:@"/load"] ||
19
+ [requestURL.path isEqualToString:@"/save"] ||
20
+ [requestURL.path isEqualToString:@"/stop"])
21
+ return YES;
22
+
23
+ return NO;
24
+ }
25
+
26
+ - (void)startResponse
27
+ {
28
+ if ([url.path isEqualToString:@"/record"]) {
29
+ [[Recorder sharedRecorder] record];
30
+ } else if ([url.path isEqualToString:@"/play"]) {
31
+ [[Recorder sharedRecorder] play];
32
+ } else if ([url.path isEqualToString:@"/load"]) {
33
+ [[Recorder sharedRecorder] loadFromFile: [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
34
+ } else if ([url.path isEqualToString:@"/save"]) {
35
+ [[Recorder sharedRecorder] saveToFile: [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
36
+ } else if ([url.path isEqualToString:@"/stop"]) {
37
+ [[Recorder sharedRecorder] stop];
38
+ }
39
+
40
+ CFHTTPMessageRef response = CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1);
41
+ CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Connection", (CFStringRef)@"close");
42
+ CFDataRef headerData = CFHTTPMessageCopySerializedMessage(response);
43
+
44
+ @try
45
+ {
46
+ [fileHandle writeData:(NSData *)headerData];
47
+ }
48
+ @catch (NSException *exception)
49
+ {
50
+ // Ignore the exception, it normally just means the client
51
+ // closed the connection from the other end.
52
+ }
53
+ @finally
54
+ {
55
+ CFRelease(headerData);
56
+ [server closeHandler:self];
57
+ }
58
+ }
59
+ @end
@@ -0,0 +1,68 @@
1
+ //
2
+ // SynthesizeSingleton.h
3
+ // iTrackSportsBets
4
+ //
5
+ // Created by Matt Gallagher on 20/10/08.
6
+ // Copyright 2008 Matt Gallagher. All rights reserved.
7
+ //
8
+ // Permission is given to use this source code file, free of charge, in any
9
+ // project, commercial or otherwise, entirely at your risk, with the condition
10
+ // that any redistribution (in part or whole) of source code must retain
11
+ // this copyright and permission notice. Attribution in compiled projects is
12
+ // appreciated but not required.
13
+ //
14
+
15
+ #define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
16
+ \
17
+ static classname *shared##classname = nil; \
18
+ \
19
+ + (classname *)shared##classname \
20
+ { \
21
+ @synchronized(self) \
22
+ { \
23
+ if (shared##classname == nil) \
24
+ { \
25
+ shared##classname = [[self alloc] init]; \
26
+ } \
27
+ } \
28
+ \
29
+ return shared##classname; \
30
+ } \
31
+ \
32
+ + (id)allocWithZone:(NSZone *)zone \
33
+ { \
34
+ @synchronized(self) \
35
+ { \
36
+ if (shared##classname == nil) \
37
+ { \
38
+ shared##classname = [super allocWithZone:zone]; \
39
+ return shared##classname; \
40
+ } \
41
+ } \
42
+ \
43
+ return nil; \
44
+ } \
45
+ \
46
+ - (id)copyWithZone:(NSZone *)zone \
47
+ { \
48
+ return self; \
49
+ } \
50
+ \
51
+ - (id)retain \
52
+ { \
53
+ return self; \
54
+ } \
55
+ \
56
+ - (NSUInteger)retainCount \
57
+ { \
58
+ return NSUIntegerMax; \
59
+ } \
60
+ \
61
+ - (void)release \
62
+ { \
63
+ } \
64
+ \
65
+ - (id)autorelease \
66
+ { \
67
+ return self; \
68
+ }
@@ -0,0 +1,5 @@
1
+ #import "iCukeHTTPResponseHandler.h"
2
+
3
+ @interface ViewResponse : iCukeHTTPResponseHandler {
4
+ }
5
+ @end
@@ -0,0 +1,84 @@
1
+ #import "ViewResponse.h"
2
+ #import "iCukeHTTPServer.h"
3
+ #import "Viewer.h"
4
+
5
+ // AX API
6
+ extern Boolean AXAPIEnabled(void);
7
+
8
+ @implementation ViewResponse
9
+ + (void)load
10
+ {
11
+ [iCukeHTTPResponseHandler registerHandler:self];
12
+ }
13
+
14
+ + (BOOL)canHandleRequest:(CFHTTPMessageRef)aRequest
15
+ method:(NSString *)requestMethod
16
+ url:(NSURL *)requestURL
17
+ headerFields:(NSDictionary *)requestHeaderFields
18
+ {
19
+ return [requestURL.path isEqualToString:@"/view"];
20
+ }
21
+
22
+ - (void)startResponse
23
+ {
24
+ if (!AXAPIEnabled()) {
25
+ CFHTTPMessageRef response =
26
+ CFHTTPMessageCreateResponse(
27
+ kCFAllocatorDefault, 500, NULL, kCFHTTPVersion1_1);
28
+ CFHTTPMessageSetHeaderFieldValue(
29
+ response, (CFStringRef)@"Content-Type", (CFStringRef)@"text/plain");
30
+ CFHTTPMessageSetHeaderFieldValue(
31
+ response, (CFStringRef)@"Connection", (CFStringRef)@"close");
32
+ CFHTTPMessageSetBody(
33
+ response,
34
+ (CFDataRef)[[NSString stringWithFormat:
35
+ @"Accessiblity Inspector Disabled: "
36
+ @"Please enable the accessibilty inspector in the simulator and retry"]
37
+ dataUsingEncoding:NSUTF8StringEncoding]);
38
+ CFDataRef headerData = CFHTTPMessageCopySerializedMessage(response);
39
+ @try
40
+ {
41
+ [fileHandle writeData:(NSData *)headerData];
42
+ }
43
+ @catch (NSException *exception)
44
+ {
45
+ // Ignore the exception, it normally just means the client
46
+ // closed the connection from the other end.
47
+ }
48
+ @finally
49
+ {
50
+ CFRelease(headerData);
51
+ CFRelease(response);
52
+ [server closeHandler:self];
53
+ }
54
+
55
+ return;
56
+ }
57
+
58
+ CFHTTPMessageRef response = CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1);
59
+ CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Content-Type", (CFStringRef)@"text/xml");
60
+ CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Connection", (CFStringRef)@"close");
61
+
62
+ NSData *viewData = [[[Viewer sharedViewer] screen] dataUsingEncoding:NSUTF8StringEncoding];
63
+
64
+ CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Content-Length",
65
+ (CFStringRef)[NSString stringWithFormat:@"%ld", [viewData length]]);
66
+ CFDataRef headerData = CFHTTPMessageCopySerializedMessage(response);
67
+
68
+ @try
69
+ {
70
+ [fileHandle writeData:(NSData *)headerData];
71
+ [fileHandle writeData:viewData];
72
+ }
73
+ @catch (NSException *exception)
74
+ {
75
+ // Ignore the exception, it normally just means the client
76
+ // closed the connection from the other end.
77
+ }
78
+ @finally
79
+ {
80
+ CFRelease(headerData);
81
+ [server closeHandler:self];
82
+ }
83
+ }
84
+ @end
@@ -0,0 +1,8 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface Viewer : NSObject
4
+
5
+ +(Viewer*)sharedViewer;
6
+ -(NSString*)screen;
7
+
8
+ @end
@@ -0,0 +1,153 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ #import "Viewer.h"
4
+
5
+ // AX API
6
+ extern Boolean AXAPIEnabled(void);
7
+
8
+ static Viewer *sharedViewer = nil;
9
+
10
+ @interface NSObject (UIAccessibilityViewer)
11
+
12
+ -(void)appendToXml:(NSMutableString*)xml;
13
+ -(void)appendTraitsToXml:(NSMutableString*)xml;
14
+ -(void)appendFrameToXml:(NSMutableString*)xml;
15
+ -(void)appendOpenToXml:(NSMutableString*)xml;
16
+ -(void)appendCloseToXml:(NSMutableString*)xml;
17
+ -(void)appendChildrenToXml:(NSMutableString*)xml;
18
+
19
+ @end
20
+
21
+ @implementation NSObject (UIAccessibilityViewer)
22
+
23
+ -(void)appendOpenToXml:(NSMutableString*)xml {
24
+ [xml appendFormat: @"<%@", NSStringFromClass([self class])];
25
+ [self appendTraitsToXml: xml];
26
+ if ([[self accessibilityLabel] length] > 0) {
27
+ [xml appendFormat: @"label=\"%@\" ", [self accessibilityLabel]];
28
+ }
29
+ if ([[self accessibilityHint] length] > 0) {
30
+ [xml appendFormat: @"hint=\"%@\" ", [self accessibilityHint]];
31
+ }
32
+ if ([[self accessibilityValue] length] > 0) {
33
+ [xml appendFormat: @"value=\"%@\" ", [self accessibilityValue]];
34
+ }
35
+ [xml appendString: @">"];
36
+ }
37
+
38
+ -(void)appendTraitsToXml:(NSMutableString *)xml {
39
+ [xml appendString: @" traits=\""];
40
+ if ([self accessibilityTraits] & UIAccessibilityTraitButton) {
41
+ [xml appendString: @"button "];
42
+ }
43
+ if ([self accessibilityTraits] & UIAccessibilityTraitLink) {
44
+ [xml appendString: @"link "];
45
+ }
46
+ if ([self accessibilityTraits] & UIAccessibilityTraitSearchField) {
47
+ [xml appendString: @"search_field "];
48
+ }
49
+ if ([self accessibilityTraits] & UIAccessibilityTraitImage) {
50
+ [xml appendString: @"image "];
51
+ }
52
+ if ([self accessibilityTraits] & UIAccessibilityTraitSelected) {
53
+ [xml appendString: @"selected "];
54
+ }
55
+ if ([self accessibilityTraits] & UIAccessibilityTraitPlaysSound) {
56
+ [xml appendString: @"plays_sound "];
57
+ }
58
+ if ([self accessibilityTraits] & UIAccessibilityTraitKeyboardKey) {
59
+ [xml appendString: @"keyboard_key "];
60
+ }
61
+ if ([self accessibilityTraits] & UIAccessibilityTraitStaticText) {
62
+ [xml appendString: @"static_text "];
63
+ }
64
+ if ([self accessibilityTraits] & UIAccessibilityTraitSummaryElement) {
65
+ [xml appendString: @"summary_element "];
66
+ }
67
+ if ([self accessibilityTraits] & UIAccessibilityTraitNotEnabled) {
68
+ [xml appendString: @"not_enabled "];
69
+ }
70
+ if ([self accessibilityTraits] & UIAccessibilityTraitUpdatesFrequently) {
71
+ [xml appendString: @"updates_frequently "];
72
+ }
73
+ [xml appendString: @"\" "];
74
+ }
75
+
76
+ -(void)appendFrameToXml:(NSMutableString *)xml {
77
+ CGRect frame = [self accessibilityFrame];
78
+ [xml appendFormat: @"<frame x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"/>",
79
+ frame.origin.x, frame.origin.y, frame.size.width, frame.size.height];
80
+ }
81
+
82
+ -(void)appendCloseToXml:(NSMutableString *)xml {
83
+ [xml appendFormat: @"</%@>", NSStringFromClass([self class])];
84
+ }
85
+
86
+ -(void)appendChildrenToXml:(NSMutableString *)xml {
87
+ // Bug that accessibilityElementCount is returning 2147483647 rather than 0?
88
+ if ([self accessibilityElementCount] != 2147483647) {
89
+ for (int i = 0; i < [self accessibilityElementCount]; i++) {
90
+ id accessibilityElement = [self accessibilityElementAtIndex: i];
91
+ [accessibilityElement appendToXml: xml];
92
+ }
93
+ }
94
+ }
95
+
96
+ -(void)appendToXml:(NSMutableString *)xml {
97
+ [self appendOpenToXml: xml];
98
+ [self appendFrameToXml: xml];
99
+ [self appendChildrenToXml: xml];
100
+ [self appendCloseToXml: xml];
101
+ }
102
+
103
+ @end
104
+
105
+ @interface UIView (Viewer)
106
+
107
+ -(void)appendToXml:(NSMutableString *)xml;
108
+
109
+ @end
110
+
111
+ @implementation UIView (Viewer)
112
+
113
+ -(void)appendToXml:(NSMutableString *)xml {
114
+ if ([self isAccessibilityElement]) {
115
+ [self appendOpenToXml: xml];
116
+ [self appendFrameToXml: xml];
117
+ }
118
+
119
+ for (UIView *view in self.subviews) {
120
+ [view appendToXml: xml];
121
+ }
122
+
123
+ [self appendChildrenToXml: xml];
124
+
125
+ if ([self isAccessibilityElement]) {
126
+ [self appendCloseToXml: xml];
127
+ }
128
+ }
129
+
130
+ @end
131
+
132
+ @implementation Viewer
133
+
134
+ +(Viewer *)sharedViewer {
135
+ if (sharedViewer == nil) {
136
+ sharedViewer = [[super allocWithZone:NULL] init];
137
+ }
138
+ return sharedViewer;
139
+ }
140
+
141
+ -(NSString *)screen {
142
+ NSMutableString *xml = [NSMutableString stringWithString: @"<screen>"];
143
+
144
+ for (UIWindow *window in [UIApplication sharedApplication].windows) {
145
+ [window appendToXml: xml];
146
+ }
147
+
148
+ [xml appendString: @"</screen>"];
149
+
150
+ return xml;
151
+ }
152
+
153
+ @end
@@ -0,0 +1,50 @@
1
+ //
2
+ // HTTPResponseHandler.h
3
+ // TextTransfer
4
+ //
5
+ // Created by Matt Gallagher on 2009/07/13.
6
+ // Copyright 2009 Matt Gallagher. All rights reserved.
7
+ //
8
+ // Permission is given to use this source code file, free of charge, in any
9
+ // project, commercial or otherwise, entirely at your risk, with the condition
10
+ // that any redistribution (in part or whole) of source code must retain
11
+ // this copyright and permission notice. Attribution in compiled projects is
12
+ // appreciated but not required.
13
+ //
14
+
15
+ #if TARGET_OS_IPHONE
16
+ #import <UIKit/UIKit.h>
17
+ #import <CFNetwork/CFNetwork.h>
18
+ #else
19
+ #import <Cocoa/Cocoa.h>
20
+ #endif
21
+
22
+ @class iCukeHTTPServer;
23
+
24
+ @interface iCukeHTTPResponseHandler : NSObject
25
+ {
26
+ CFHTTPMessageRef request;
27
+ NSString *requestMethod;
28
+ NSDictionary *headerFields;
29
+ NSFileHandle *fileHandle;
30
+ iCukeHTTPServer *server;
31
+ NSURL *url;
32
+ }
33
+
34
+ + (NSUInteger)priority;
35
+ + (void)registerHandler:(Class)handlerClass;
36
+
37
+ + (iCukeHTTPResponseHandler *)handlerForRequest:(CFHTTPMessageRef)aRequest
38
+ fileHandle:(NSFileHandle *)requestFileHandle
39
+ server:(iCukeHTTPServer *)aServer;
40
+
41
+ - (id)initWithRequest:(CFHTTPMessageRef)aRequest
42
+ method:(NSString *)method
43
+ url:(NSURL *)requestURL
44
+ headerFields:(NSDictionary *)requestHeaderFields
45
+ fileHandle:(NSFileHandle *)requestFileHandle
46
+ server:(iCukeHTTPServer *)aServer;
47
+ - (void)startResponse;
48
+ - (void)endResponse;
49
+
50
+ @end