iCuke 0.6.3 → 0.6.4

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 (129) hide show
  1. data/.gitmodules +1 -1
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +41 -0
  4. data/README.markdown +126 -0
  5. data/Rakefile +34 -12
  6. data/VERSION +1 -1
  7. data/bin/icuke +12 -10
  8. data/ext/Rakefile +6 -0
  9. data/ext/iCuke/{sdk3.1/DefaultsResponse.h → DefaultsResponse.h} +0 -0
  10. data/ext/iCuke/{sdk3.1/DefaultsResponse.m → DefaultsResponse.m} +0 -0
  11. data/ext/iCuke/{sdk3.1/EventResponse.h → EventResponse.h} +0 -0
  12. data/ext/iCuke/{sdk3.1/EventResponse.m → EventResponse.m} +0 -0
  13. data/ext/iCuke/{sdk3.1/ModuleResponse.h → ModuleResponse.h} +0 -0
  14. data/ext/iCuke/{sdk3.1/ModuleResponse.m → ModuleResponse.m} +0 -0
  15. data/ext/iCuke/{sdk3.1/QuitResponse.h → QuitResponse.h} +0 -0
  16. data/ext/iCuke/{sdk3.1/QuitResponse.m → QuitResponse.m} +0 -0
  17. data/ext/iCuke/Rakefile +14 -13
  18. data/ext/iCuke/{sdk3.1/Recorder.h → Recorder.h} +0 -0
  19. data/ext/iCuke/{sdk3.1/Recorder.m → Recorder.m} +0 -0
  20. data/ext/iCuke/{sdk3.1/RecorderResponse.h → RecorderResponse.h} +0 -0
  21. data/ext/iCuke/{sdk3.1/RecorderResponse.m → RecorderResponse.m} +0 -0
  22. data/ext/iCuke/{sdk3.1/SynthesizeSingleton.h → SynthesizeSingleton.h} +0 -0
  23. data/ext/iCuke/{sdk3.1/ViewResponse.h → ViewResponse.h} +0 -0
  24. data/ext/iCuke/{sdk3.1/ViewResponse.m → ViewResponse.m} +0 -0
  25. data/ext/iCuke/{sdk3.1/Viewer.h → Viewer.h} +0 -0
  26. data/ext/iCuke/{sdk4.0/Viewer.m → Viewer.m} +0 -0
  27. data/ext/iCuke/{sdk3.1/iCukeHTTPResponseHandler.h → iCukeHTTPResponseHandler.h} +0 -0
  28. data/ext/iCuke/{sdk3.1/iCukeHTTPResponseHandler.m → iCukeHTTPResponseHandler.m} +0 -0
  29. data/ext/iCuke/{sdk3.1/iCukeHTTPServer.h → iCukeHTTPServer.h} +0 -0
  30. data/ext/iCuke/{sdk4.0/iCukeHTTPServer.m → iCukeHTTPServer.m} +4 -2
  31. data/ext/iCuke/{sdk3.1/iCukeServer.h → iCukeServer.h} +0 -0
  32. data/ext/iCuke/{sdk3.1/iCukeServer.m → iCukeServer.m} +0 -0
  33. data/ext/iCuke/{sdk3.1/json → json}/JSON.h +0 -0
  34. data/ext/iCuke/{sdk3.1/json → json}/NSObject+SBJSON.h +0 -0
  35. data/ext/iCuke/{sdk3.1/json → json}/NSObject+SBJSON.m +0 -0
  36. data/ext/iCuke/{sdk3.1/json → json}/NSString+SBJSON.h +0 -0
  37. data/ext/iCuke/{sdk3.1/json → json}/NSString+SBJSON.m +0 -0
  38. data/ext/iCuke/{sdk3.1/json → json}/SBJSON.h +0 -0
  39. data/ext/iCuke/{sdk3.1/json → json}/SBJSON.m +0 -0
  40. data/ext/iCuke/{sdk3.1/json → json}/SBJsonBase.h +0 -0
  41. data/ext/iCuke/{sdk3.1/json → json}/SBJsonBase.m +0 -0
  42. data/ext/iCuke/{sdk3.1/json → json}/SBJsonParser.h +0 -0
  43. data/ext/iCuke/{sdk3.1/json → json}/SBJsonParser.m +0 -0
  44. data/ext/iCuke/{sdk3.1/json → json}/SBJsonWriter.h +0 -0
  45. data/ext/iCuke/{sdk3.1/json → json}/SBJsonWriter.m +0 -0
  46. data/features/starting_project.feature +18 -0
  47. data/features/step_definitions/shell.rb +41 -0
  48. data/features/support/env.rb +2 -0
  49. data/features/support/environment.rb +40 -0
  50. data/features/supported_sdks.feature +12 -0
  51. data/iCuke.gemspec +149 -161
  52. data/lib/icuke/configuration.rb +19 -0
  53. data/lib/icuke/core_ext.rb +27 -0
  54. data/lib/icuke/cucumber.rb +29 -265
  55. data/lib/icuke/cucumber_compat.rb +4 -0
  56. data/lib/icuke/icuke_world.rb +149 -0
  57. data/lib/icuke/sdk.rb +5 -13
  58. data/lib/icuke/simulator_driver.rb +201 -0
  59. data/lib/icuke/waxsim.rb +47 -9
  60. data/spec/cucumber_spec.rb +130 -0
  61. data/spec/fixtures/controls_page.xml +252 -0
  62. data/spec/process_spec.rb +76 -0
  63. data/spec/screen_spec.rb +173 -0
  64. data/spec/simulate_spec.rb +75 -0
  65. data/spec/simulator_spec.rb +28 -0
  66. data/spec/spec.opts +2 -0
  67. data/spec/spec_helper.rb +67 -0
  68. metadata +222 -121
  69. data/.gitignore +0 -15
  70. data/README.rdoc +0 -68
  71. data/ext/WaxSim/Simulator.h +0 -31
  72. data/ext/WaxSim/Simulator.m +0 -131
  73. data/ext/WaxSim/WaxSim.m +0 -110
  74. data/ext/WaxSim/WaxSim.xcodeproj/project.pbxproj +0 -238
  75. data/ext/WaxSim/WaxSim_Prefix.pch +0 -7
  76. data/ext/WaxSim/build/Release/waxsim +0 -0
  77. data/ext/WaxSim/build/Release/waxsim.dSYM/Contents/Info.plist +0 -20
  78. data/ext/WaxSim/build/Release/waxsim.dSYM/Contents/Resources/DWARF/waxsim +0 -0
  79. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/Objects-normal/x86_64/Simulator.o +0 -0
  80. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/Objects-normal/x86_64/WaxSim.o +0 -0
  81. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/Objects-normal/x86_64/waxsim.LinkFileList +0 -2
  82. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/WaxSim.dep +0 -6
  83. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/WaxSim~.dep +0 -6
  84. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/build-state.dat +0 -227
  85. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/build-state~.dat +0 -227
  86. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-all-target-headers.hmap +0 -0
  87. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-generated-files.hmap +0 -0
  88. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-own-target-headers.hmap +0 -0
  89. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-project-headers.hmap +0 -0
  90. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim.hmap +0 -0
  91. data/ext/WaxSim/iPhoneSimulatorRemoteClient/iPhoneSimulatorRemoteClient.h +0 -126
  92. data/ext/iCuke/sdk3.1/Rakefile +0 -20
  93. data/ext/iCuke/sdk3.1/Viewer.m +0 -203
  94. data/ext/iCuke/sdk3.1/iCukeHTTPServer.m +0 -365
  95. data/ext/iCuke/sdk4.0/DefaultsResponse.h +0 -5
  96. data/ext/iCuke/sdk4.0/DefaultsResponse.m +0 -66
  97. data/ext/iCuke/sdk4.0/EventResponse.h +0 -5
  98. data/ext/iCuke/sdk4.0/EventResponse.m +0 -130
  99. data/ext/iCuke/sdk4.0/ModuleResponse.h +0 -5
  100. data/ext/iCuke/sdk4.0/ModuleResponse.m +0 -76
  101. data/ext/iCuke/sdk4.0/QuitResponse.h +0 -5
  102. data/ext/iCuke/sdk4.0/QuitResponse.m +0 -23
  103. data/ext/iCuke/sdk4.0/Rakefile +0 -20
  104. data/ext/iCuke/sdk4.0/Recorder.h +0 -17
  105. data/ext/iCuke/sdk4.0/Recorder.m +0 -90
  106. data/ext/iCuke/sdk4.0/RecorderResponse.h +0 -6
  107. data/ext/iCuke/sdk4.0/RecorderResponse.m +0 -68
  108. data/ext/iCuke/sdk4.0/SynthesizeSingleton.h +0 -68
  109. data/ext/iCuke/sdk4.0/ViewResponse.h +0 -5
  110. data/ext/iCuke/sdk4.0/ViewResponse.m +0 -84
  111. data/ext/iCuke/sdk4.0/Viewer.h +0 -8
  112. data/ext/iCuke/sdk4.0/iCukeHTTPResponseHandler.h +0 -50
  113. data/ext/iCuke/sdk4.0/iCukeHTTPResponseHandler.m +0 -381
  114. data/ext/iCuke/sdk4.0/iCukeHTTPServer.h +0 -53
  115. data/ext/iCuke/sdk4.0/iCukeServer.h +0 -14
  116. data/ext/iCuke/sdk4.0/iCukeServer.m +0 -65
  117. data/ext/iCuke/sdk4.0/json/JSON.h +0 -50
  118. data/ext/iCuke/sdk4.0/json/NSObject+SBJSON.h +0 -68
  119. data/ext/iCuke/sdk4.0/json/NSObject+SBJSON.m +0 -53
  120. data/ext/iCuke/sdk4.0/json/NSString+SBJSON.h +0 -58
  121. data/ext/iCuke/sdk4.0/json/NSString+SBJSON.m +0 -55
  122. data/ext/iCuke/sdk4.0/json/SBJSON.h +0 -75
  123. data/ext/iCuke/sdk4.0/json/SBJSON.m +0 -212
  124. data/ext/iCuke/sdk4.0/json/SBJsonBase.h +0 -86
  125. data/ext/iCuke/sdk4.0/json/SBJsonBase.m +0 -78
  126. data/ext/iCuke/sdk4.0/json/SBJsonParser.h +0 -87
  127. data/ext/iCuke/sdk4.0/json/SBJsonParser.m +0 -475
  128. data/ext/iCuke/sdk4.0/json/SBJsonWriter.h +0 -129
  129. data/ext/iCuke/sdk4.0/json/SBJsonWriter.m +0 -228
@@ -1,126 +0,0 @@
1
- #import <Cocoa/Cocoa.h>
2
-
3
- /*
4
- * File: /Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework/Versions/A/iPhoneSimulatorRemoteClient
5
- * Arch: Intel 80x86 (i386)
6
- * Current version: 12.0.0, Compatibility version: 1.0.0
7
- */
8
-
9
- @class DTiPhoneSimulatorSession;
10
-
11
- @protocol DTiPhoneSimulatorSessionDelegate
12
-
13
- - (void) session: (DTiPhoneSimulatorSession *) session didEndWithError: (NSError *) error;
14
- - (void) session: (DTiPhoneSimulatorSession *) session didStart: (BOOL) started withError: (NSError *) error;
15
-
16
- @end
17
-
18
- @interface DTiPhoneSimulatorApplicationSpecifier : NSObject <NSCopying>
19
- {
20
- NSString *_appPath;
21
- NSString *_bundleID;
22
- }
23
-
24
- + (id) specifierWithApplicationPath: (NSString *) appPath;
25
- + (id) specifierWithApplicationBundleIdentifier: (NSString *) bundleID;
26
- - (NSString *) bundleID;
27
- - (void) setBundleID: (NSString *) bundleId;
28
- - (NSString *) appPath;
29
- - (void) setAppPath: (NSString *) appPath;
30
-
31
- @end
32
-
33
- @interface DTiPhoneSimulatorSystemRoot : NSObject <NSCopying>
34
- {
35
- NSString *sdkRootPath;
36
- NSString *sdkVersion;
37
- NSString *sdkDisplayName;
38
- }
39
-
40
- + (id) defaultRoot;
41
-
42
- + (id)rootWithSDKPath:(NSString *) path;
43
- + (id)rootWithSDKVersion:(NSString *)version;
44
-
45
- + (NSArray *) knownRoots;
46
- - (id)initWithSDKPath:(id)fp8;
47
- - (id)sdkDisplayName;
48
- - (void)setSdkDisplayName:(id)fp8;
49
- - (id)sdkVersion;
50
- - (void)setSdkVersion:(id)fp8;
51
- - (id)sdkRootPath;
52
- - (void)setSdkRootPath:(id)fp8;
53
-
54
- @end
55
-
56
-
57
-
58
- @interface DTiPhoneSimulatorSessionConfig : NSObject <NSCopying>
59
- {
60
- NSString *_localizedClientName;
61
- DTiPhoneSimulatorSystemRoot *_simulatedSystemRoot;
62
- DTiPhoneSimulatorApplicationSpecifier *_applicationToSimulateOnStart;
63
- NSArray *_simulatedApplicationLaunchArgs;
64
- NSDictionary *_simulatedApplicationLaunchEnvironment;
65
- BOOL _simulatedApplicationShouldWaitForDebugger;
66
- NSString *_simulatedApplicationStdOutPath;
67
- NSString *_simulatedApplicationStdErrPath;
68
- }
69
-
70
- + (NSString *) displayNameForDeviceFamily: (NSNumber *) family;
71
-
72
- - (id)simulatedApplicationStdErrPath;
73
- - (void)setSimulatedApplicationStdErrPath:(id)fp8;
74
- - (id)simulatedApplicationStdOutPath;
75
- - (void)setSimulatedApplicationStdOutPath:(id)fp8;
76
- - (id)simulatedApplicationLaunchEnvironment;
77
- - (void)setSimulatedApplicationLaunchEnvironment:(id)fp8;
78
- - (id)simulatedApplicationLaunchArgs;
79
- - (void)setSimulatedApplicationLaunchArgs:(id)fp8;
80
-
81
- - (DTiPhoneSimulatorApplicationSpecifier *) applicationToSimulateOnStart;
82
- - (void) setApplicationToSimulateOnStart: (DTiPhoneSimulatorApplicationSpecifier *) appSpec;
83
- - (DTiPhoneSimulatorSystemRoot *) simulatedSystemRoot;
84
- - (void) setSimulatedSystemRoot: (DTiPhoneSimulatorSystemRoot *) simulatedSystemRoot;
85
-
86
- - (NSNumber *) simulatedDeviceFamily;
87
- - (void) setSimulatedDeviceFamily: (NSNumber *) family;
88
-
89
- - (BOOL) simulatedApplicationShouldWaitForDebugger;
90
- - (void) setSimulatedApplicationShouldWaitForDebugger: (BOOL) waitForDebugger;
91
-
92
- - (id)localizedClientName;
93
- - (void)setLocalizedClientName:(id)fp8;
94
-
95
- @end
96
-
97
-
98
- @interface DTiPhoneSimulatorSession : NSObject {
99
- NSString *_uuid;
100
- id <DTiPhoneSimulatorSessionDelegate> _delegate;
101
- NSNumber *_simulatedApplicationPID;
102
- int _sessionLifecycleProgress;
103
- NSTimer *_timeoutTimer;
104
- DTiPhoneSimulatorSessionConfig *_sessionConfig;
105
- struct ProcessSerialNumber _simulatorPSN;
106
- }
107
-
108
- - (BOOL) requestStartWithConfig: (DTiPhoneSimulatorSessionConfig *) config timeout: (NSTimeInterval) timeout error: (NSError **) outError;
109
- - (void) requestEndWithTimeout: (NSTimeInterval) timeout;
110
-
111
- - (id)sessionConfig;
112
- - (void)setSessionConfig:(id)fp8;
113
- - (id)timeoutTimer;
114
- - (void)setTimeoutTimer:(id)fp8;
115
- - (int)sessionLifecycleProgress;
116
- - (void)setSessionLifecycleProgress:(int)fp8;
117
- - (id)simulatedApplicationPID;
118
- - (void)setSimulatedApplicationPID:(id)fp8;
119
-
120
- - (id<DTiPhoneSimulatorSessionDelegate>) delegate;
121
- - (void) setDelegate: (id<DTiPhoneSimulatorSessionDelegate>) delegate;
122
-
123
- - (id)uuid;
124
- - (void)setUuid:(id)fp8;
125
-
126
- @end
@@ -1,20 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'icuke', 'sdk')
2
- require 'rake/clean'
3
-
4
- version = '3.1'
5
- ICuke::SDK.use_latest(version)
6
-
7
- rule '.o' => '.m' do |o|
8
- sh "#{ICuke::SDK.gcc} -c -o #{o.name} #{o.source}"
9
- end
10
-
11
- CLEAN.include('**/*.o')
12
-
13
- file "../#{ICuke::SDK.dylib}" => FileList['**/*.m'].ext('.o') do |t|
14
- sh "#{ICuke::SDK.ld} -dynamiclib -o #{t.name} -framework Foundation -framework GraphicsServices -framework UIKit -framework CFNetwork -framework AXRuntime #{t.prerequisites.join(' ')}"
15
- end
16
-
17
- CLEAN.include("../#{ICuke::SDK.dylib}")
18
-
19
- task :install => "../#{ICuke::SDK.dylib}"
20
- task :default => :install
@@ -1,203 +0,0 @@
1
- #import <QuartzCore/QuartzCore.h>
2
- #import <UIKit/UIKit.h>
3
-
4
- #import "Viewer.h"
5
-
6
- static Viewer *sharedViewer = nil;
7
-
8
- @interface NSObject (Accessibility)
9
- -(BOOL)_accessibilityIsFrameOutOfBounds;
10
- @end
11
-
12
- @interface NSObject (UIAccessibilityViewer)
13
-
14
- -(void)appendToXml:(NSMutableString*)xml;
15
- -(void)appendTraitsToXml:(NSMutableString*)xml;
16
- -(void)appendFrameToXml:(NSMutableString*)xml;
17
- -(void)appendOpenToXml:(NSMutableString*)xml;
18
- -(void)appendCloseToXml:(NSMutableString*)xml;
19
- -(void)appendChildrenToXml:(NSMutableString*)xml;
20
-
21
- @end
22
-
23
- @implementation NSObject (UIAccessibilityViewer)
24
-
25
- -(void)appendOpenToXml:(NSMutableString*)xml {
26
- [xml appendFormat: @"<%@", NSStringFromClass([self class])];
27
- if ([self isAccessibilityElement]) {
28
- [self appendTraitsToXml: xml];
29
- if ([[self accessibilityLabel] length] > 0) {
30
- NSString *escaped_label = [self accessibilityLabel];
31
- escaped_label = [escaped_label stringByReplacingOccurrencesOfString: @"&" withString: @"&amp;"];
32
- escaped_label = [escaped_label stringByReplacingOccurrencesOfString: @"\"" withString: @"&quot;"];
33
- escaped_label = [escaped_label stringByReplacingOccurrencesOfString: @"'" withString: @"&apos;"];
34
- escaped_label = [escaped_label stringByReplacingOccurrencesOfString: @"\\" withString: @"&#39;"];
35
- escaped_label = [escaped_label stringByReplacingOccurrencesOfString: @">" withString: @"&gt;"];
36
- escaped_label = [escaped_label stringByReplacingOccurrencesOfString: @"<" withString: @"&lt;"];
37
- [xml appendFormat: @"label=\"%@\" ", escaped_label];
38
- }
39
- if ([[self accessibilityHint] length] > 0) {
40
- [xml appendFormat: @"hint=\"%@\" ", [self accessibilityHint]];
41
- }
42
- if ([[self accessibilityValue] length] > 0) {
43
- NSString *escaped_value = [self accessibilityValue];
44
- escaped_value = [escaped_value stringByReplacingOccurrencesOfString: @"&" withString: @"&amp;"];
45
- escaped_value = [escaped_value stringByReplacingOccurrencesOfString: @"\"" withString: @"&quot;"];
46
- escaped_value = [escaped_value stringByReplacingOccurrencesOfString: @"'" withString: @"&apos;"];
47
- escaped_value = [escaped_value stringByReplacingOccurrencesOfString: @"\\" withString: @"&#39;"];
48
- escaped_value = [escaped_value stringByReplacingOccurrencesOfString: @">" withString: @"&gt;"];
49
- escaped_value = [escaped_value stringByReplacingOccurrencesOfString: @"<" withString: @"&lt;"];
50
- [xml appendFormat: @"value=\"%@\" ", escaped_value];
51
- }
52
- }
53
- [xml appendString: @">"];
54
- }
55
-
56
- -(void)appendTraitsToXml:(NSMutableString *)xml {
57
- [xml appendString: @" traits=\""];
58
- if ([self accessibilityTraits] & UIAccessibilityTraitButton) {
59
- [xml appendString: @"button "];
60
- }
61
- if ([self accessibilityTraits] & UIAccessibilityTraitLink) {
62
- [xml appendString: @"link "];
63
- }
64
- if ([self accessibilityTraits] & UIAccessibilityTraitSearchField) {
65
- [xml appendString: @"search_field "];
66
- }
67
- if ([self accessibilityTraits] & UIAccessibilityTraitImage) {
68
- [xml appendString: @"image "];
69
- }
70
- if ([self accessibilityTraits] & UIAccessibilityTraitSelected) {
71
- [xml appendString: @"selected "];
72
- }
73
- if ([self accessibilityTraits] & UIAccessibilityTraitPlaysSound) {
74
- [xml appendString: @"plays_sound "];
75
- }
76
- if ([self accessibilityTraits] & UIAccessibilityTraitKeyboardKey) {
77
- [xml appendString: @"keyboard_key "];
78
- }
79
- if ([self accessibilityTraits] & UIAccessibilityTraitStaticText) {
80
- [xml appendString: @"static_text "];
81
- }
82
- if ([self accessibilityTraits] & UIAccessibilityTraitSummaryElement) {
83
- [xml appendString: @"summary_element "];
84
- }
85
- if ([self accessibilityTraits] & UIAccessibilityTraitNotEnabled) {
86
- [xml appendString: @"not_enabled "];
87
- }
88
- if ([self accessibilityTraits] & UIAccessibilityTraitUpdatesFrequently) {
89
- [xml appendString: @"updates_frequently "];
90
- }
91
- [xml appendString: @"\" "];
92
- }
93
-
94
- -(void)appendFrameToXml:(NSMutableString *)xml {
95
- CGRect frame = [self accessibilityFrame];
96
- [xml appendFormat: @"<frame x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"/>",
97
- frame.origin.x, frame.origin.y, frame.size.width, frame.size.height];
98
- }
99
-
100
- -(void)appendCloseToXml:(NSMutableString *)xml {
101
- [xml appendFormat: @"</%@>", NSStringFromClass([self class])];
102
- }
103
-
104
- -(void)appendChildrenToXml:(NSMutableString *)xml {
105
- // Bug that accessibilityElementCount is returning 2147483647 rather than 0?
106
- if ([self accessibilityElementCount] != 2147483647) {
107
- for (int i = 0; i < [self accessibilityElementCount]; i++) {
108
- id accessibilityElement = [self accessibilityElementAtIndex: i];
109
- [accessibilityElement appendToXml: xml];
110
- }
111
- }
112
- }
113
-
114
- -(void)appendToXml:(NSMutableString *)xml {
115
- [self appendOpenToXml: xml];
116
- [self appendFrameToXml: xml];
117
- [self appendChildrenToXml: xml];
118
- [self appendCloseToXml: xml];
119
- }
120
-
121
- @end
122
-
123
- @implementation UITableView (AccessibilityVisibilityFix)
124
-
125
- -(void)appendChildrenToXml:(NSMutableString *)xml {
126
- // Ignore the accessibility interface here because it doesn't allow us a way to tell if a cell is visible.
127
- for (UIView *view in [self visibleCells]) {
128
- [view appendToXml: xml];
129
- }
130
- }
131
-
132
- @end
133
-
134
- @interface UIView (Viewer)
135
-
136
- -(void)appendToXml:(NSMutableString *)xml;
137
- -(void)appendFrameToXml:(NSMutableString *)xml;
138
-
139
- @end
140
-
141
- @implementation UIView (Viewer)
142
-
143
- -(void)appendToXml:(NSMutableString *)xml {
144
- [self appendOpenToXml: xml];
145
-
146
- if ([self _accessibilityIsFrameOutOfBounds]) {
147
- [xml appendFormat: @"<invisible/>"];
148
- }
149
-
150
- [self appendFrameToXml: xml];
151
-
152
- for (UIView *view in self.subviews) {
153
- [view appendToXml: xml];
154
- }
155
-
156
- [self appendChildrenToXml: xml];
157
- [self appendCloseToXml: xml];
158
- }
159
-
160
- -(void)appendFrameToXml:(NSMutableString *)xml {
161
- CGRect frame;
162
-
163
- if ([self isAccessibilityElement]) {
164
- frame = [self accessibilityFrame];
165
- } else {
166
- frame = [self frame];
167
- }
168
- [xml appendFormat: @"<frame x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"/>",
169
- frame.origin.x, frame.origin.y, frame.size.width, frame.size.height];
170
-
171
- frame = [[[UIApplication sharedApplication] keyWindow] convertRect:self.layer.visibleRect fromView:self];
172
-
173
- [xml appendFormat: @"<visibleFrame x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"/>",
174
- frame.origin.x, frame.origin.y, frame.size.width, frame.size.height];
175
- }
176
-
177
- @end
178
-
179
- @implementation Viewer
180
-
181
- +(Viewer *)sharedViewer {
182
- if (sharedViewer == nil) {
183
- sharedViewer = [[super allocWithZone:NULL] init];
184
- }
185
- return sharedViewer;
186
- }
187
-
188
- -(NSString *)screen {
189
- NSMutableString *xml = [NSMutableString stringWithString: @"<screen>"];
190
- CGRect frame = [[UIScreen mainScreen] applicationFrame];
191
- [xml appendFormat: @"<frame x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"/>",
192
- frame.origin.x, frame.origin.y, frame.size.width, frame.size.height];
193
-
194
- for (UIWindow *window in [UIApplication sharedApplication].windows) {
195
- [window appendToXml: xml];
196
- }
197
-
198
- [xml appendString: @"</screen>"];
199
-
200
- return xml;
201
- }
202
-
203
- @end
@@ -1,365 +0,0 @@
1
- //
2
- // HTTPServer.m
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
- #import "iCukeHTTPServer.h"
16
- #import "SynthesizeSingleton.h"
17
- #import <sys/socket.h>
18
- #import <netinet/in.h>
19
- #if TARGET_OS_IPHONE
20
- #import <CFNetwork/CFNetwork.h>
21
- #endif
22
- #import "iCukeHTTPResponseHandler.h"
23
-
24
- #define HTTP_SERVER_PORT 50000
25
-
26
- NSString * const iCukeHTTPServerNotificationStateChanged = @"ServerNotificationStateChanged";
27
-
28
- //
29
- // Internal methods and properties:
30
- // The "lastError" and "state" are only writable by the server itself.
31
- //
32
- @interface iCukeHTTPServer ()
33
- @property (nonatomic, readwrite, retain) NSError *lastError;
34
- @property (readwrite, assign) iCukeHTTPServerState state;
35
- @end
36
-
37
- @implementation iCukeHTTPServer
38
-
39
- @synthesize lastError;
40
- @synthesize state;
41
-
42
- SYNTHESIZE_SINGLETON_FOR_CLASS(iCukeHTTPServer);
43
-
44
- //
45
- // init
46
- //
47
- // Set the initial state and allocate the responseHandlers and incomingRequests
48
- // collections.
49
- //
50
- // returns the initialized server object.
51
- //
52
- - (id)init
53
- {
54
- self = [super init];
55
- if (self != nil)
56
- {
57
- self.state = SERVER_STATE_IDLE;
58
- responseHandlers = [[NSMutableSet alloc] init];
59
- incomingRequests =
60
- CFDictionaryCreateMutable(
61
- kCFAllocatorDefault,
62
- 0,
63
- &kCFTypeDictionaryKeyCallBacks,
64
- &kCFTypeDictionaryValueCallBacks);
65
- }
66
- return self;
67
- }
68
-
69
- //
70
- // setLastError:
71
- //
72
- // Custom setter method. Stops the server and
73
- //
74
- // Parameters:
75
- // anError - the new error value (nil to clear)
76
- //
77
- - (void)setLastError:(NSError *)anError
78
- {
79
- [anError retain];
80
- [lastError release];
81
- lastError = anError;
82
-
83
- if (lastError == nil)
84
- {
85
- return;
86
- }
87
-
88
- [self stop];
89
-
90
- self.state = SERVER_STATE_IDLE;
91
- NSLog(@"HTTPServer error: %@", self.lastError);
92
- }
93
-
94
- //
95
- // errorWithName:
96
- //
97
- // Stops the server and sets the last error to "errorName", localized using the
98
- // HTTPServerErrors.strings file (if present).
99
- //
100
- // Parameters:
101
- // errorName - the description used for the error
102
- //
103
- - (void)errorWithName:(NSString *)errorName
104
- {
105
- self.lastError = [NSError
106
- errorWithDomain:@"HTTPServerError"
107
- code:0
108
- userInfo:
109
- [NSDictionary dictionaryWithObject:
110
- NSLocalizedStringFromTable(
111
- errorName,
112
- @"",
113
- @"HTTPServerErrors")
114
- forKey:NSLocalizedDescriptionKey]];
115
- }
116
-
117
- //
118
- // setState:
119
- //
120
- // Changes the server state and posts a notification (if the state changes).
121
- //
122
- // Parameters:
123
- // newState - the new state for the server
124
- //
125
- - (void)setState:(iCukeHTTPServerState)newState
126
- {
127
- if (state == newState)
128
- {
129
- return;
130
- }
131
-
132
- state = newState;
133
-
134
- [[NSNotificationCenter defaultCenter]
135
- postNotificationName:iCukeHTTPServerNotificationStateChanged
136
- object:self];
137
- }
138
-
139
- //
140
- // start
141
- //
142
- // Creates the socket and starts listening for connections on it.
143
- //
144
- - (void)start
145
- {
146
- self.lastError = nil;
147
- self.state = SERVER_STATE_STARTING;
148
-
149
- socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM,
150
- IPPROTO_TCP, 0, NULL, NULL);
151
- if (!socket)
152
- {
153
- [self errorWithName:@"Unable to create socket."];
154
- return;
155
- }
156
-
157
- int reuse = true;
158
- int fileDescriptor = CFSocketGetNative(socket);
159
- if (setsockopt(fileDescriptor, SOL_SOCKET, SO_REUSEADDR,
160
- (void *)&reuse, sizeof(int)) != 0)
161
- {
162
- [self errorWithName:@"Unable to set socket options."];
163
- return;
164
- }
165
-
166
- struct sockaddr_in address;
167
- memset(&address, 0, sizeof(address));
168
- address.sin_len = sizeof(address);
169
- address.sin_family = AF_INET;
170
- address.sin_addr.s_addr = htonl(INADDR_ANY);
171
- address.sin_port = htons(HTTP_SERVER_PORT);
172
- CFDataRef addressData =
173
- CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address));
174
- [(id)addressData autorelease];
175
-
176
- if (CFSocketSetAddress(socket, addressData) != kCFSocketSuccess)
177
- {
178
- [self errorWithName:@"Unable to bind socket to address."];
179
- return;
180
- }
181
-
182
- listeningHandle = [[NSFileHandle alloc]
183
- initWithFileDescriptor:fileDescriptor
184
- closeOnDealloc:YES];
185
-
186
- [[NSNotificationCenter defaultCenter]
187
- addObserver:self
188
- selector:@selector(receiveIncomingConnectionNotification:)
189
- name:NSFileHandleConnectionAcceptedNotification
190
- object:nil];
191
- [listeningHandle acceptConnectionInBackgroundAndNotify];
192
-
193
- self.state = SERVER_STATE_RUNNING;
194
- }
195
-
196
- //
197
- // stopReceivingForFileHandle:close:
198
- //
199
- // If a file handle is accumulating the header for a new connection, this
200
- // method will close the handle, stop listening to it and release the
201
- // accumulated memory.
202
- //
203
- // Parameters:
204
- // incomingFileHandle - the file handle for the incoming request
205
- // closeFileHandle - if YES, the file handle will be closed, if no it is
206
- // assumed that an HTTPResponseHandler will close it when done.
207
- //
208
- - (void)stopReceivingForFileHandle:(NSFileHandle *)incomingFileHandle
209
- close:(BOOL)closeFileHandle
210
- {
211
- if (closeFileHandle)
212
- {
213
- [incomingFileHandle closeFile];
214
- }
215
-
216
- [[NSNotificationCenter defaultCenter]
217
- removeObserver:self
218
- name:NSFileHandleDataAvailableNotification
219
- object:incomingFileHandle];
220
- CFDictionaryRemoveValue(incomingRequests, incomingFileHandle);
221
- }
222
-
223
- //
224
- // stop
225
- //
226
- // Stops the server.
227
- //
228
- - (void)stop
229
- {
230
- self.state = SERVER_STATE_STOPPING;
231
-
232
- [[NSNotificationCenter defaultCenter]
233
- removeObserver:self
234
- name:NSFileHandleConnectionAcceptedNotification
235
- object:nil];
236
-
237
- [responseHandlers removeAllObjects];
238
-
239
- [listeningHandle closeFile];
240
- [listeningHandle release];
241
- listeningHandle = nil;
242
-
243
- for (NSFileHandle *incomingFileHandle in
244
- [[(NSDictionary *)incomingRequests copy] autorelease])
245
- {
246
- [self stopReceivingForFileHandle:incomingFileHandle close:YES];
247
- }
248
-
249
- if (socket)
250
- {
251
- CFSocketInvalidate(socket);
252
- CFRelease(socket);
253
- socket = nil;
254
- }
255
-
256
- self.state = SERVER_STATE_IDLE;
257
- }
258
-
259
- //
260
- // receiveIncomingConnectionNotification:
261
- //
262
- // Receive the notification for a new incoming request. This method starts
263
- // receiving data from the incoming request's file handle and creates a
264
- // new CFHTTPMessageRef to store the incoming data..
265
- //
266
- // Parameters:
267
- // notification - the new connection notification
268
- //
269
- - (void)receiveIncomingConnectionNotification:(NSNotification *)notification
270
- {
271
- NSDictionary *userInfo = [notification userInfo];
272
- NSFileHandle *incomingFileHandle =
273
- [userInfo objectForKey:NSFileHandleNotificationFileHandleItem];
274
-
275
- if(incomingFileHandle)
276
- {
277
- CFDictionaryAddValue(
278
- incomingRequests,
279
- incomingFileHandle,
280
- [(id)CFHTTPMessageCreateEmpty(kCFAllocatorDefault, TRUE) autorelease]);
281
-
282
- [[NSNotificationCenter defaultCenter]
283
- addObserver:self
284
- selector:@selector(receiveIncomingDataNotification:)
285
- name:NSFileHandleDataAvailableNotification
286
- object:incomingFileHandle];
287
-
288
- [incomingFileHandle waitForDataInBackgroundAndNotify];
289
- }
290
-
291
- [listeningHandle acceptConnectionInBackgroundAndNotify];
292
- }
293
-
294
- //
295
- // receiveIncomingDataNotification:
296
- //
297
- // Receive new data for an incoming connection.
298
- //
299
- // Once enough data is received to fully parse the HTTP headers,
300
- // a HTTPResponseHandler will be spawned to generate a response.
301
- //
302
- // Parameters:
303
- // notification - data received notification
304
- //
305
- - (void)receiveIncomingDataNotification:(NSNotification *)notification
306
- {
307
- NSFileHandle *incomingFileHandle = [notification object];
308
- NSData *data = [incomingFileHandle availableData];
309
-
310
- if ([data length] == 0)
311
- {
312
- [self stopReceivingForFileHandle:incomingFileHandle close:NO];
313
- return;
314
- }
315
-
316
- CFHTTPMessageRef incomingRequest =
317
- (CFHTTPMessageRef)CFDictionaryGetValue(incomingRequests, incomingFileHandle);
318
- if (!incomingRequest)
319
- {
320
- [self stopReceivingForFileHandle:incomingFileHandle close:YES];
321
- return;
322
- }
323
-
324
- if (!CFHTTPMessageAppendBytes(
325
- incomingRequest,
326
- [data bytes],
327
- [data length]))
328
- {
329
- [self stopReceivingForFileHandle:incomingFileHandle close:YES];
330
- return;
331
- }
332
-
333
- if(CFHTTPMessageIsHeaderComplete(incomingRequest))
334
- {
335
- iCukeHTTPResponseHandler *handler =
336
- [iCukeHTTPResponseHandler
337
- handlerForRequest:incomingRequest
338
- fileHandle:incomingFileHandle
339
- server:self];
340
-
341
- [responseHandlers addObject:handler];
342
- [self stopReceivingForFileHandle:incomingFileHandle close:NO];
343
-
344
- [handler startResponse];
345
- return;
346
- }
347
-
348
- [incomingFileHandle waitForDataInBackgroundAndNotify];
349
- }
350
-
351
- //
352
- // closeHandler:
353
- //
354
- // Shuts down a response handler and removes it from the set of handlers.
355
- //
356
- // Parameters:
357
- // aHandler - the handler to shut down.
358
- //
359
- - (void)closeHandler:(iCukeHTTPResponseHandler *)aHandler
360
- {
361
- [aHandler endResponse];
362
- [responseHandlers removeObject:aHandler];
363
- }
364
-
365
- @end