win_gui 0.1.6 → 0.2.0

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 (169) hide show
  1. data/.gitignore +21 -21
  2. data/HISTORY +7 -0
  3. data/LICENSE +20 -20
  4. data/README.rdoc +77 -114
  5. data/Rakefile +24 -58
  6. data/VERSION +1 -1
  7. data/features/support/env.rb +7 -4
  8. data/features/win_gui.feature +9 -9
  9. data/lib/version.rb +8 -0
  10. data/lib/win_gui/window.rb +78 -69
  11. data/lib/win_gui.rb +25 -3
  12. data/spec/spec.opts +1 -1
  13. data/spec/spec_helper.rb +90 -118
  14. data/spec/win_gui/window_spec.rb +120 -123
  15. data/tasks/common.rake +14 -0
  16. data/tasks/doc.rake +14 -0
  17. data/tasks/gem.rake +39 -0
  18. data/tasks/git.rake +34 -0
  19. data/tasks/spec.rake +19 -0
  20. data/tasks/version.rake +71 -0
  21. metadata +68 -188
  22. data/.document +0 -5
  23. data/book_code/early_success/bundle.rb +0 -34
  24. data/book_code/early_success/english.txt +0 -1
  25. data/book_code/early_success/jruby_basics.rb +0 -47
  26. data/book_code/early_success/windows_basics.rb +0 -97
  27. data/book_code/guessing/locknote.rb +0 -379
  28. data/book_code/guessing/monkeyshines.rb +0 -14
  29. data/book_code/guessing/note.rb +0 -120
  30. data/book_code/guessing/note_spec.rb +0 -175
  31. data/book_code/guessing/replay.rb +0 -21
  32. data/book_code/guessing/seed.rb +0 -9
  33. data/book_code/guessing/spec_helper.rb +0 -69
  34. data/book_code/guessing/windows_gui.rb +0 -247
  35. data/book_code/home_stretch/junquenote.rb +0 -151
  36. data/book_code/home_stretch/locknote.rb +0 -180
  37. data/book_code/home_stretch/note.rb +0 -144
  38. data/book_code/home_stretch/note_spec.rb +0 -191
  39. data/book_code/home_stretch/spec_helper.rb +0 -55
  40. data/book_code/home_stretch/swing_gui.rb +0 -50
  41. data/book_code/home_stretch/windows_gui.rb +0 -232
  42. data/book_code/junquenote/exports.sh +0 -10
  43. data/book_code/junquenote/jruby_mac.sh +0 -10
  44. data/book_code/junquenote/junquenote_app.rb +0 -262
  45. data/book_code/novite/Rakefile +0 -10
  46. data/book_code/novite/app/controllers/application.rb +0 -18
  47. data/book_code/novite/app/controllers/guests_controller.rb +0 -28
  48. data/book_code/novite/app/controllers/parties_controller.rb +0 -77
  49. data/book_code/novite/app/helpers/application_helper.rb +0 -11
  50. data/book_code/novite/app/helpers/guests_helper.rb +0 -10
  51. data/book_code/novite/app/helpers/parties_helper.rb +0 -10
  52. data/book_code/novite/app/models/guest.rb +0 -11
  53. data/book_code/novite/app/models/party.rb +0 -32
  54. data/book_code/novite/app/models/party_mailer.rb +0 -19
  55. data/book_code/novite/app/views/layouts/application.rhtml +0 -44
  56. data/book_code/novite/app/views/parties/new.html.erb +0 -42
  57. data/book_code/novite/app/views/parties/show.html.erb +0 -43
  58. data/book_code/novite/app/views/party_mailer/invite.erb +0 -17
  59. data/book_code/novite/config/boot.rb +0 -117
  60. data/book_code/novite/config/database.yml +0 -19
  61. data/book_code/novite/config/environment.rb +0 -67
  62. data/book_code/novite/config/environments/development.rb +0 -29
  63. data/book_code/novite/config/environments/production.rb +0 -27
  64. data/book_code/novite/config/environments/test.rb +0 -30
  65. data/book_code/novite/config/initializers/inflections.rb +0 -18
  66. data/book_code/novite/config/initializers/mime_types.rb +0 -13
  67. data/book_code/novite/config/routes.rb +0 -47
  68. data/book_code/novite/db/migrate/001_create_parties.rb +0 -26
  69. data/book_code/novite/db/migrate/002_create_guests.rb +0 -23
  70. data/book_code/novite/db/schema.rb +0 -41
  71. data/book_code/novite/log/empty.txt +0 -0
  72. data/book_code/novite/public/.htaccess +0 -40
  73. data/book_code/novite/public/404.html +0 -38
  74. data/book_code/novite/public/422.html +0 -38
  75. data/book_code/novite/public/500.html +0 -38
  76. data/book_code/novite/public/dispatch.cgi +0 -10
  77. data/book_code/novite/public/dispatch.fcgi +0 -24
  78. data/book_code/novite/public/dispatch.rb +0 -18
  79. data/book_code/novite/public/favicon.ico +0 -0
  80. data/book_code/novite/public/images/rails.png +0 -0
  81. data/book_code/novite/public/index.html +0 -285
  82. data/book_code/novite/public/javascripts/application.js +0 -10
  83. data/book_code/novite/public/javascripts/controls.js +0 -971
  84. data/book_code/novite/public/javascripts/dragdrop.js +0 -980
  85. data/book_code/novite/public/javascripts/effects.js +0 -1128
  86. data/book_code/novite/public/javascripts/prototype.js +0 -4233
  87. data/book_code/novite/public/robots.txt +0 -5
  88. data/book_code/novite/script/about +0 -3
  89. data/book_code/novite/script/console +0 -3
  90. data/book_code/novite/script/destroy +0 -3
  91. data/book_code/novite/script/generate +0 -3
  92. data/book_code/novite/script/performance/benchmarker +0 -3
  93. data/book_code/novite/script/performance/profiler +0 -3
  94. data/book_code/novite/script/performance/request +0 -3
  95. data/book_code/novite/script/plugin +0 -3
  96. data/book_code/novite/script/process/inspector +0 -3
  97. data/book_code/novite/script/process/reaper +0 -3
  98. data/book_code/novite/script/process/spawner +0 -3
  99. data/book_code/novite/script/runner +0 -3
  100. data/book_code/novite/script/server +0 -3
  101. data/book_code/novite/test/test_helper.rb +0 -46
  102. data/book_code/one_more_thing/applescript.rb +0 -68
  103. data/book_code/one_more_thing/note_spec.rb +0 -50
  104. data/book_code/one_more_thing/spec_helper.rb +0 -17
  105. data/book_code/one_more_thing/textedit-pure.rb +0 -28
  106. data/book_code/one_more_thing/textedit.applescript +0 -26
  107. data/book_code/one_more_thing/textedit.rb +0 -32
  108. data/book_code/one_more_thing/textnote.rb +0 -87
  109. data/book_code/simplify/junquenote.rb +0 -48
  110. data/book_code/simplify/locknote.rb +0 -46
  111. data/book_code/simplify/note.rb +0 -35
  112. data/book_code/simplify/note_spec.rb +0 -28
  113. data/book_code/simplify/swing_gui.rb +0 -45
  114. data/book_code/simplify/windows_gui.rb +0 -232
  115. data/book_code/simplify/windows_gui_spec.rb +0 -35
  116. data/book_code/story/invite.story +0 -19
  117. data/book_code/story/journal.txt +0 -29
  118. data/book_code/story/novite_stories.rb +0 -156
  119. data/book_code/story/party.rb +0 -149
  120. data/book_code/story/password.rb +0 -61
  121. data/book_code/story/password.story +0 -26
  122. data/book_code/story/rsvp.story +0 -29
  123. data/book_code/tables/TestTime.html +0 -93
  124. data/book_code/tables/TestTimeSample.html +0 -63
  125. data/book_code/tables/calculate_time.rb +0 -39
  126. data/book_code/tables/calculator.rb +0 -108
  127. data/book_code/tables/calculator_actions.rb +0 -27
  128. data/book_code/tables/calculator_spec.rb +0 -47
  129. data/book_code/tables/fit.rb +0 -32
  130. data/book_code/tables/matrix.rb +0 -109
  131. data/book_code/tables/pseudocode.rb +0 -17
  132. data/book_code/tubes/book_selenium.rb +0 -67
  133. data/book_code/tubes/book_watir.rb +0 -60
  134. data/book_code/tubes/dragdrop.html +0 -81
  135. data/book_code/tubes/html_capture.rb +0 -33
  136. data/book_code/tubes/joke_list.rb +0 -67
  137. data/book_code/tubes/list_spec.rb +0 -41
  138. data/book_code/tubes/search_spec.rb +0 -32
  139. data/book_code/tubes/selenium_example.rb +0 -66
  140. data/book_code/tubes/selenium_link.rb +0 -23
  141. data/book_code/tubes/web_server.rb +0 -14
  142. data/book_code/windows/wgui.rb +0 -29
  143. data/book_code/windows/wobj.rb +0 -25
  144. data/book_code/windows/wsh.rb +0 -25
  145. data/book_code/with_rspec/empty_spec.rb +0 -13
  146. data/book_code/with_rspec/junquenote.rb +0 -60
  147. data/book_code/with_rspec/locknote.rb +0 -129
  148. data/book_code/with_rspec/note_spec.rb +0 -32
  149. data/book_code/with_rspec/should_examples.rb +0 -18
  150. data/lib/note/java/jemmy.jar +0 -0
  151. data/lib/note/java/jnote.rb +0 -48
  152. data/lib/note/java/jruby_basics.rb +0 -37
  153. data/lib/note/java/junquenote_app.rb +0 -262
  154. data/lib/note/java/note_spec.rb +0 -20
  155. data/lib/note/win/locknote.rb +0 -19
  156. data/lib/note.rb +0 -15
  157. data/lib/win_gui/constants.rb +0 -82
  158. data/lib/win_gui/def_api.rb +0 -160
  159. data/lib/win_gui/string_extensions.rb +0 -36
  160. data/lib/win_gui/win_gui.rb +0 -437
  161. data/old/windows_basics.rb +0 -80
  162. data/old/wnote.rb +0 -80
  163. data/old/wnote_spec.rb +0 -20
  164. data/spec/note/win/locknote_spec.rb +0 -7
  165. data/spec/test_apps/locknote/LockNote.exe +0 -0
  166. data/spec/win_gui/def_api_spec.rb +0 -339
  167. data/spec/win_gui/string_extensions_spec.rb +0 -61
  168. data/spec/win_gui/win_gui_spec.rb +0 -537
  169. data/win_gui.gemspec +0 -215
@@ -1,339 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper" )
2
-
3
- module GuiTest
4
-
5
- def should_be symbol, api
6
- case symbol
7
- when :find_window
8
- api.dll_name.should == 'user32' # The name of the DLL that exports the API function
9
- api.effective_function_name.should == 'FindWindowA' # Actual function returned by the constructor: 'GetUserName' ->'GetUserNameA' or 'GetUserNameW'
10
- api.function_name.should == 'FindWindow' # The name of the function passed to the constructor
11
- api.prototype.should == ['P', 'P'] # The prototype, returned as an array of characters
12
- end
13
- end
14
-
15
- def redefined_methods
16
- [:FindWindow, :IsWindow, :EnumWindows, :GetComputerName, :GetForegroundWindow]
17
- end
18
-
19
- def should_count_args(*methods, rights, wrongs)
20
- rights = [rights].flatten
21
- wrongs = [wrongs].flatten
22
- methods.each do |method|
23
- (0..8).each do |n|
24
- if n == rights.size
25
- expect {send method, *rights}.to_not raise_error
26
- else
27
- args = (1..n).map {wrongs[rand(wrongs.size)]}
28
- expect {send method, *args}.
29
- to raise_error "wrong number of parameters: expected #{rights.size}, got #{args.size}"
30
- end
31
- end
32
- end
33
- end
34
-
35
- describe WinGui::DefApi, 'defines wrappers for Win32::API functions' do
36
- before(:each) { hide_method *redefined_methods } # hide original methods if defined
37
- after(:each) { restore_method *redefined_methods } # restore original methods if hidden
38
-
39
- context 'defining enhanced API function method' do
40
- spec{ use{ WinGui.def_api('FindWindow', 'PP', 'L', rename: nil, aliases: nil, boolean: nil, zeronil: nil, &any_block) }}
41
-
42
- it 'defines new instance methods with appropriate names' do
43
- WinGui.def_api 'FindWindow', 'PP', 'L'
44
- respond_to?(:find_window).should be_true
45
- respond_to?(:FindWindow).should be_true
46
- end
47
-
48
- it 'constructs argument prototype from uppercase string, enforces the args count' do
49
- expect { WinGui.def_api 'FindWindow', 'PP', 'L' }.to_not raise_error
50
- should_count_args :find_window, :FindWindow, [nil, nil], [nil, TEST_IMPOSSIBLE, 'cmd']
51
- end
52
-
53
- it 'constructs argument prototype from lowercase string, enforces the args count' do
54
- expect { WinGui.def_api 'FindWindow', 'pp', 'l' }.to_not raise_error
55
- should_count_args :find_window, :FindWindow, [nil, nil], [nil, TEST_IMPOSSIBLE, 'cmd']
56
- end
57
-
58
- it 'constructs argument prototype from (mixedcase) array, enforces the args count' do
59
- expect { WinGui.def_api 'FindWindow', ['p', 'P'], 'L' }.to_not raise_error
60
- should_count_args :find_window, :FindWindow, [nil, nil], [nil, TEST_IMPOSSIBLE, 'cmd']
61
- end
62
-
63
- it 'with :rename option, overrides snake_case name for defined method but leaves CamelCase intact' do
64
- WinGui.def_api 'FindWindow', 'PP', 'L', :rename=> 'my_own_find'
65
- expect {find_window(nil, nil)}.to raise_error NoMethodError
66
- expect {FindWindow(nil, nil)}.to_not raise_error
67
- expect {my_own_find(nil, nil)}.to_not raise_error
68
- end
69
-
70
- it 'defined snake_case method returns expected value when called' do
71
- WinGui.def_api 'FindWindow', 'PP', 'L'
72
- find_window(nil, nil).should_not == 0
73
- find_window(nil, TEST_IMPOSSIBLE).should == 0
74
- find_window(TEST_IMPOSSIBLE, nil).should == 0
75
- find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE).should == 0
76
- end
77
-
78
- it 'defined CamelCase method returns expected value when called' do
79
- WinGui.def_api 'FindWindow', 'PP', 'L'
80
- FindWindow(nil, nil).should_not == 0
81
- FindWindow(nil, TEST_IMPOSSIBLE).should == 0
82
- FindWindow(TEST_IMPOSSIBLE, nil).should == 0
83
- FindWindow(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE).should == 0
84
- end
85
-
86
- it 'returns underlying Win32::API object if defined method is called with (:api) argument ' do
87
- WinGui.def_api 'FindWindow', 'PP', 'L'
88
- expect {find_window(:api)}.to_not raise_error
89
- should_be :find_window, find_window(:api)
90
- end
91
- end
92
-
93
- context 'defining aliases' do
94
- it 'adds alias for defined method with :alias option' do
95
- WinGui.def_api 'FindWindow', 'PP', 'L', :alias => 'my_own_find'
96
- expect {find_window(nil, nil)}.to_not raise_error
97
- expect {my_own_find(nil, nil)}.to_not raise_error
98
- end
99
-
100
- it 'adds aliases for defined method with :aliases option' do
101
- WinGui.def_api 'FindWindow', 'PP', 'L', :aliases => ['my_own_find', 'my_own_find1']
102
- expect {find_window(nil, nil)}.to_not raise_error
103
- expect {my_own_find(nil, nil)}.to_not raise_error
104
- expect {my_own_find1(nil, nil)}.to_not raise_error
105
- end
106
-
107
- it 'adds Rubyesque alias to IsXxx API test function' do
108
- WinGui.def_api 'IsWindow', 'L', 'L'
109
- respond_to?(:window?).should be_true
110
- respond_to?(:is_window).should be_true
111
- end
112
-
113
- it 'adds Rubyesque alias to GetXxx API getter function' do
114
- WinGui.def_api 'GetComputerName', 'PP', 'I', :dll=> 'kernel32'
115
- respond_to?(:get_computer_name).should be_true
116
- respond_to?(:computer_name).should be_true
117
- end
118
-
119
- end
120
-
121
- context 'auto-defining Ruby-like boolean methods if API function name starts with "Is_"' do
122
- before(:each) {WinGui.def_api 'IsWindow', 'L', 'L'}
123
-
124
- it 'defines new instance method name dropping Is_ and adding ?' do
125
- respond_to?(:window?).should be_true
126
- respond_to?(:is_window).should be_true
127
- respond_to?(:IsWindow).should be_true
128
- end
129
-
130
- it 'defined CamelCase method returns zero/non-zero as expected' do
131
- IsWindow(any_handle).should_not == true
132
- IsWindow(any_handle).should_not == 0
133
- IsWindow(not_a_handle).should == 0
134
- end
135
-
136
- it 'defined snake_case method returns false/true instead of zero/non-zero' do
137
- window?(any_handle).should == true
138
- window?(not_a_handle).should == false
139
- is_window(any_handle).should == true
140
- is_window(not_a_handle).should == false
141
- end
142
-
143
- it 'defined methods enforce the argument count' do
144
- should_count_args :window?, :is_window, :IsWindow, [not_a_handle], [nil, not_a_handle, any_handle]
145
- end
146
- end
147
-
148
- context 'defining API with :boolean option converts result to boolean' do
149
- before(:each) do
150
- WinGui.def_api 'FindWindow', 'PP', 'L', :boolean => true
151
- end
152
-
153
- it 'defines new instance method' do
154
- respond_to?(:find_window).should be_true
155
- respond_to?(:FindWindow).should be_true
156
- end
157
-
158
- it 'defined snake_case method returns false/true instead of zero/non-zero' do
159
- find_window(nil, nil).should == true
160
- find_window(nil, TEST_IMPOSSIBLE).should == false
161
- end
162
-
163
- it 'defined CamelCase method still returns zero/non-zero' do
164
- FindWindow(nil, nil).should_not == true
165
- FindWindow(nil, nil).should_not == 0
166
- FindWindow(nil, TEST_IMPOSSIBLE).should == 0
167
- end
168
-
169
- it 'defined methods enforce the argument count' do
170
- should_count_args :find_window, :FindWindow, [nil, nil], [nil, TEST_IMPOSSIBLE, 'cmd']
171
- end
172
- end
173
-
174
- context 'defining API with :zeronil option converts zero result to nil' do
175
- before(:each) do
176
- WinGui.def_api 'FindWindow', 'PP', 'L', :zeronil => true
177
- end
178
-
179
- it 'defines new instance method' do
180
- respond_to?(:find_window).should be_true
181
- respond_to?(:FindWindow).should be_true
182
- end
183
-
184
- it 'defined CamelCase method still returns zero/non-zero' do
185
- FindWindow(nil, nil).should_not == true
186
- FindWindow(nil, nil).should_not == 0
187
- FindWindow(nil, TEST_IMPOSSIBLE).should == 0
188
- end
189
-
190
- it 'defined method returns nil (but NOT false) instead of zero' do
191
- find_window(nil, TEST_IMPOSSIBLE).should_not == false
192
- find_window(nil, TEST_IMPOSSIBLE).should == nil
193
- end
194
-
195
- it 'defined method does not return true when result is non-zero' do
196
- find_window(nil, nil).should_not == true
197
- find_window(nil, nil).should_not == 0
198
- end
199
-
200
- it 'defined methods enforce the argument count' do
201
- should_count_args :find_window, :FindWindow, [nil, nil], [nil, TEST_IMPOSSIBLE, 'cmd']
202
- end
203
- end
204
-
205
- context 'using DLL other than default user32 with :dll option' do
206
- before(:each) {WinGui.def_api 'GetComputerName', 'PP', 'I', :dll=> 'kernel32'}
207
-
208
- it 'defines new instance method with appropriate name' do
209
- respond_to?(:GetComputerName).should be_true
210
- respond_to?(:get_computer_name).should be_true
211
- respond_to?(:computer_name).should be_true
212
- end
213
-
214
- it 'returns expected result' do
215
- WinGui.def_api 'GetComputerName', ['P', 'P'], 'I', :dll=> 'kernel32'
216
- hostname = `hostname`.strip.upcase
217
- name = " " * 128
218
- get_computer_name(name, "128")
219
- name.unpack("A*").first.should == hostname
220
- end
221
- end
222
-
223
- context 'trying to define an invalid API function' do
224
- it 'raises error when trying to define function with a wrong function name' do
225
- expect { WinGui.def_api 'FindWindowImpossible', 'PP', 'L' }.
226
- to raise_error( /Unable to load function 'FindWindowImpossible'/ )
227
- end
228
- end
229
-
230
- context 'defining API function using definition block' do
231
- it 'defines new instance method' do
232
- WinGui.def_api( 'FindWindow', 'PP', 'L' ){|api, *args|}
233
- respond_to?(:find_window).should be_true
234
- respond_to?(:FindWindow).should be_true
235
- end
236
-
237
- it 'does not enforce argument count outside of block' do
238
- WinGui.def_api( 'FindWindow', 'PP', 'L' ){|api, *args|}
239
- expect { find_window }.to_not raise_error
240
- expect { find_window(nil) }.to_not raise_error
241
- expect { find_window(nil, 'Str', 1) }.to_not raise_error
242
- end
243
-
244
- it 'returns block return value when defined method is called' do
245
- WinGui.def_api( 'FindWindow', 'PP', 'L' ){|api, *args| 'Value'}
246
- find_window(nil).should == 'Value'
247
- end
248
-
249
- it 'passes arguments and underlying Win32::API object to the block' do
250
- WinGui.def_api( 'FindWindow', 'PP', 'L' ) do |api, *args|
251
- @api = api
252
- @args = args
253
- end
254
- expect {find_window(1, 2, 3) }.to_not raise_error
255
- @args.should == [1, 2, 3]
256
- should_be :find_window, @api
257
- end
258
-
259
- it ':rename option overrides standard name for defined method' do
260
- WinGui.def_api( 'FindWindow', 'PP', 'L', :rename => 'my_own_find' ){|api, *args|}
261
- expect {find_window(nil, nil, nil)}.to raise_error
262
- expect {my_own_find(nil, nil)}.to_not raise_error
263
- end
264
-
265
- it 'adds alias for defined method with :alias option' do
266
- WinGui.def_api( 'FindWindow', 'PP', 'L', :alias => 'my_own_find' ){|api, *args|}
267
- expect {find_window(nil, nil)}.to_not raise_error
268
- expect {my_own_find(nil, nil)}.to_not raise_error
269
- end
270
-
271
- it 'adds aliases for defined method with :aliases option' do
272
- WinGui.def_api( 'FindWindow', 'PP', 'L', :aliases => ['my_own_find', 'my_own_find1'] ) {|api, *args|}
273
- expect {find_window(nil, nil)}.to_not raise_error
274
- expect {my_own_find(nil, nil)}.to_not raise_error
275
- expect {my_own_find1(nil, nil)}.to_not raise_error
276
- end
277
-
278
- it 'returns underlying Win32::API object if defined method is called with (:api) argument ' do
279
- WinGui.def_api( 'FindWindow', 'PP', 'L' ){|api, *args|}
280
- expect {find_window(:api)}.to_not raise_error
281
- should_be :find_window, find_window(:api)
282
- end
283
- end
284
-
285
- context 'calling defined methods with attached block to preprocess the API function results' do
286
- it 'defined method yields raw result to block attached to its invocation' do
287
- WinGui.def_api 'FindWindow', 'PP', 'L', zeronil: true
288
- find_window(nil, TEST_IMPOSSIBLE) {|result| result.should == 0 }
289
- end
290
-
291
- it 'defined method returns result of block attached to its invocation' do
292
- WinGui.def_api 'FindWindow', 'PP', 'L', zeronil: true
293
- return_value = find_window(nil, TEST_IMPOSSIBLE) {|result| 'Value'}
294
- return_value.should == 'Value'
295
- end
296
-
297
- it 'defined method transforms result of block before returning it' do
298
- WinGui.def_api 'FindWindow', 'PP', 'L', zeronil: true
299
- return_value = find_window(nil, TEST_IMPOSSIBLE) {|result| 0 }
300
- return_value.should_not == 0
301
- return_value.should == nil
302
- end
303
- end
304
-
305
- context 'defining API function without arguments - f(VOID)' do
306
- it 'should enforce argument count to 0, NOT 1 (enhanced methods)' do
307
- WinGui.def_api 'GetForegroundWindow', 'V', 'L', zeronil: true
308
- should_count_args :get_foreground_window, :foreground_window, [], [nil, 0, 123]
309
- end
310
-
311
- it 'should NOT enforce argument count (raw method)' do
312
- WinGui.def_api 'GetForegroundWindow', 'V', 'L', zeronil: true
313
- expect {GetForegroundWindow()}.to_not raise_error
314
- expect {GetForegroundWindow(nil)}.to_not raise_error
315
- expect {GetForegroundWindow(1,2)}.to_not raise_error
316
- expect {GetForegroundWindow(1,2,3)}.to_not raise_error
317
- end
318
- end
319
-
320
- context 'working with API function callbacks' do
321
- it '#callback method creates a valid callback object' do
322
- expect { @callback = WinGui.callback('LP', 'I') {|handle, message| true} }.to_not raise_error
323
- @callback.should be_a_kind_of(Win32::API::Callback)
324
- end
325
-
326
- it 'created callback object can be used as a valid arg of API function expecting callback' do
327
- WinGui.def_api 'EnumWindows', 'KP', 'L'
328
- @callback = WinGui.callback('LP', 'I'){|handle, message| true }
329
- expect { enum_windows(@callback, 'Message') }.to_not raise_error
330
- end
331
-
332
- it 'defined API functions expecting callback convert given block into callback' do
333
- pending ' What about prototype!? API is not exactly clear atm (.with_callback method?)'
334
- WinGui.def_api 'EnumWindows', 'KP', 'L'
335
- expect { enum_windows('Message'){|handle, message| true } }.to_not raise_error
336
- end
337
- end
338
- end
339
- end
@@ -1,61 +0,0 @@
1
- require File.join(File.dirname(__FILE__), ".." , "spec_helper" )
2
-
3
- module GuiTest
4
-
5
- describe String do
6
- context '#snake_case' do
7
- it 'transforms CamelCase strings' do
8
- 'GetCharWidth32'.snake_case.should == 'get_char_width_32'
9
- end
10
-
11
- it 'leaves snake_case strings intact' do
12
- 'keybd_event'.snake_case.should == 'keybd_event'
13
- end
14
- end
15
-
16
- context '#to_w' do
17
- it 'transcodes string to utf-16LE' do
18
- 'GetCharWidth32'.to_w.encoding.name.should == 'UTF-16LE'
19
- end
20
-
21
- it 'ensures that encoded string is null-terminated' do
22
- 'GetCharWidth32'.to_w.bytes.to_a[-2..-1].should == [0, 0]
23
- end
24
- end
25
-
26
- context '#to_vkeys' do
27
- it 'transforms number char into [equivalent key code]' do
28
- ('0'..'9').each {|char| char.to_vkeys.should == char.unpack('C')}
29
- end
30
-
31
- it 'transforms uppercase letters into [shift, equivalent key code]' do
32
- ('A'..'Z').each {|char| char.to_vkeys.should == [VK_SHIFT, *char.unpack('C')]}
33
- end
34
-
35
- it 'transforms lowercase letters into [(upcase) key code]' do
36
- ('a'..'z').each {|char| char.to_vkeys.should == char.upcase.unpack('C')}
37
- end
38
-
39
- it 'transforms space into [equivalent key code]' do
40
- " ".to_vkeys.should == " ".unpack('C')
41
- end
42
-
43
- it 'raises error if char is not implemented punctuation' do
44
- ('!'..'/').each {|char| lambda {char.to_vkeys}.should raise_error TEST_ERROR_CONVERSION }
45
- (':'..'@').each {|char| lambda {char.to_vkeys}.should raise_error TEST_ERROR_CONVERSION }
46
- ('['..'`').each {|char| lambda {char.to_vkeys}.should raise_error TEST_ERROR_CONVERSION }
47
- ('{'..'~').each {|char| lambda {char.to_vkeys}.should raise_error TEST_ERROR_CONVERSION }
48
- end
49
-
50
- it 'raises error if char is non-printable or non-ascii' do
51
- lambda {1.chr.to_vkeys}.should raise_error TEST_ERROR_CONVERSION
52
- lambda {230.chr.to_vkeys}.should raise_error TEST_ERROR_CONVERSION
53
- end
54
-
55
- it 'raises error if string is multi-char' do
56
- lambda {'hello'.to_vkeys}.should raise_error TEST_ERROR_CONVERSION
57
- lambda {'23'.to_vkeys}.should raise_error TEST_ERROR_CONVERSION
58
- end
59
- end
60
- end
61
- end