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,537 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper" )
2
-
3
- module GuiTest
4
- def test_show_window *cmds, tests
5
- cmds.each do |cmd|
6
- test_app do |app|
7
- show_window(app.handle, cmd)
8
- tests.each{|test, result| send(test.to_sym, app.handle).should == result}
9
-
10
- hide_window(app.handle) # hiding window first
11
- show_window(app.handle, cmd)
12
- tests.each{|test, result| send(test.to_sym, app.handle).should == result}
13
-
14
- show_window(app.handle, SW_MAXIMIZE) # now maximizing window
15
- show_window(app.handle, cmd)
16
- tests.each{|test, result| send(test.to_sym, app.handle).should == result}
17
-
18
- show_window(app.handle, SW_MINIMIZE) # now minimizing window
19
- show_window(app.handle, cmd)
20
- tests.each{|test, result| send(test.to_sym, app.handle).should == result}
21
- end
22
- end
23
- end
24
-
25
- describe WinGui, ' contains a set of pre-defined GUI functions' do
26
- describe '#window?' do
27
- spec{ use{ IsWindow(any_handle) }}
28
- spec{ use{ is_window(any_handle) }}
29
- spec{ use{ window?(any_handle) }}
30
-
31
- it 'returns true if window exists' do
32
- window?(any_handle).should == true
33
- end
34
-
35
- it 'returns false for invalid window handle' do
36
- window?(not_a_handle).should == false
37
- end
38
-
39
- it 'changes from true to false when existing window is closed' do
40
- test_app do |app|
41
- @app_handle = app.handle
42
- @ta_handle = app.textarea.handle
43
- window?(@app_handle).should == true
44
- window?(@ta_handle).should == true
45
- end
46
- window?(@app_handle).should == false
47
- window?(@ta_handle).should == false
48
- end
49
- end
50
-
51
- describe '#window_visible?' do
52
- spec{ use{ IsWindowVisible(any_handle) }}
53
- spec{ use{ is_window_visible(any_handle) }}
54
- spec{ use{ window_visible?(any_handle) }}
55
- spec{ use{ visible?(any_handle) }}
56
-
57
- it 'returns true when window is visible, false when window is hidden' do
58
- test_app do |app|
59
- visible?(app.handle).should == true
60
- window_visible?(app.handle).should == true
61
- window_visible?(app.textarea.handle).should == true
62
- hide_window(app.handle)
63
- visible?(app.handle).should == false
64
- window_visible?(app.handle).should == false
65
- window_visible?(app.textarea.handle).should == false
66
- end
67
- end
68
- end
69
-
70
- describe '#maximized?' do
71
- spec{ use{ IsZoomed(any_handle) }}
72
- spec{ use{ is_zoomed(any_handle) }}
73
- spec{ use{ zoomed?(any_handle) }}
74
- spec{ use{ maximized?(any_handle) }}
75
-
76
- it 'returns true if the window is maximized, false otherwise' do
77
- test_app do |app|
78
- zoomed?(app.handle).should == false
79
- maximized?(app.handle).should == false
80
- show_window(app.handle, SW_MAXIMIZE)
81
- maximized?(app.handle).should == true
82
- zoomed?(app.handle).should == true
83
- end
84
- end
85
- end
86
-
87
- describe '#minimized?' do
88
- spec{ use{ IsIconic(any_handle) }}
89
- spec{ use{ is_iconic(any_handle) }}
90
- spec{ use{ iconic?(any_handle) }}
91
- spec{ use{ minimized?(any_handle) }}
92
-
93
- it 'returns true if the window is minimized, false otherwise' do
94
- test_app do |app|
95
- iconic?(app.handle).should == false
96
- minimized?(app.handle).should == false
97
- show_window(app.handle, SW_MINIMIZE)
98
- iconic?(app.handle).should == true
99
- minimized?(app.handle).should == true
100
- end
101
- end
102
- end
103
-
104
- describe '#child?' do
105
- spec{ use{ IsChild(parent_handle = any_handle, handle = any_handle) }}
106
- spec{ use{ is_child(parent_handle = any_handle, handle = any_handle) }}
107
- spec{ use{ child?(parent_handle = any_handle, handle = any_handle) }}
108
-
109
- it 'returns true if the window is a child of given parent, false otherwise' do
110
- test_app do |app|
111
- child?(app.handle, app.textarea.handle).should == true
112
- child?(app.handle, any_handle).should == false
113
- end
114
- end
115
- end
116
-
117
- describe '#find_window(w)' do
118
- spec{ use{ FindWindow(class_name = nil, win_name = nil) }}
119
- spec{ use{ find_window(class_name = nil, win_name = nil) }}
120
- # Widebyte (unicode) version
121
- spec{ use{ FindWindowW(class_name = nil, win_name = nil) }}
122
- spec{ use{ find_window_w(class_name = nil, win_name = nil) }}
123
-
124
- it 'returns either Integer Window handle or nil' do
125
- find_window(nil, nil).should be_a_kind_of Integer
126
- find_window(TEST_IMPOSSIBLE, nil).should == nil
127
- end
128
-
129
- it 'returns nil if Window is not found' do
130
- find_window(TEST_IMPOSSIBLE, nil).should == nil
131
- find_window(nil, TEST_IMPOSSIBLE).should == nil
132
- find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE).should == nil
133
- find_window_w(TEST_IMPOSSIBLE, nil).should == nil
134
- find_window_w(nil, TEST_IMPOSSIBLE).should == nil
135
- find_window_w(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE).should == nil
136
- end
137
-
138
- it 'finds at least one window if both args are nils' do
139
- find_window(nil, nil).should_not == nil
140
- find_window_w(nil, nil).should_not == nil
141
- end
142
-
143
- it 'finds top-level window by window class or title' do
144
- test_app do |app|
145
- find_window(TEST_WIN_CLASS, nil).should == app.handle
146
- find_window(nil, TEST_WIN_TITLE).should == app.handle
147
- find_window_w(TEST_WIN_CLASS.to_w, nil).should == app.handle
148
- find_window_w(nil, TEST_WIN_TITLE.to_w).should == app.handle
149
- end
150
- end
151
- end
152
-
153
- describe '#find_window_ex' do
154
- spec{ use{ FindWindowEx(parent = any_handle, after_child = 0, win_class = nil, win_title = nil) }}
155
- spec{ use{ find_window_ex(parent = any_handle, after_child = 0, win_class = nil, win_title = nil) }}
156
-
157
- it 'returns nil if wrong control is given' do
158
- parent_handle = any_handle
159
- find_window_ex(parent_handle, 0, TEST_IMPOSSIBLE, nil).should == nil
160
- find_window_ex(parent_handle, 0, nil, TEST_IMPOSSIBLE).should == nil
161
- end
162
-
163
- it 'finds child window/control by class' do
164
- test_app do |app|
165
- ta_handle = find_window_ex(app.handle, 0, TEST_TEXTAREA_CLASS, nil)
166
- ta_handle.should_not == nil
167
- ta_handle.should == app.textarea.handle
168
- end
169
- end
170
-
171
- it 'finds child window/control by text/title' do
172
- pending 'Identify appropriate (short name) control'
173
- test_app do |app|
174
- keystroke(VK_CONTROL, 'A'.ord)
175
- keystroke('1'.ord, '2'.ord)
176
- ta_handle = find_window_ex(app.handle, 0, nil, '12')
177
- ta_handle.should_not == 0
178
- ta_handle.should == app.textarea.handle
179
- end
180
- end
181
- end
182
-
183
- describe '#get_foreground_window' do
184
- # ! Different from GetActiveWindow !
185
- spec{ use{ handle = GetForegroundWindow() }}
186
- spec{ use{ handle = get_foreground_window }}
187
- spec{ use{ handle = foreground_window }}
188
-
189
- it 'returns handle to window that is currently in foreground' do
190
- test_app do |app|
191
- @app_handle = app.handle
192
- fg1 = foreground_window
193
- @app_handle.should == fg1
194
- end
195
- fg2 = foreground_window
196
- @app_handle.should_not == fg2
197
- end
198
-
199
- it 'defines #foreground? test function ' do
200
- test_app do |app|
201
- @app_handle = app.handle
202
- foreground?(@app_handle).should == true
203
- end
204
- foreground?(@app_handle).should == false
205
- end
206
- end
207
-
208
- describe '#get_active_window' do
209
- # ! Different from GetForegroundWindow !
210
- spec{ use{ handle = GetActiveWindow() }}
211
- spec{ use{ handle = get_active_window }}
212
- spec{ use{ handle = active_window }}
213
-
214
- it 'returns handle to the active window attached to the calling thread`s message queue' do
215
- pending 'No idea how to test it'
216
- test_app do |app|
217
- @app_handle = app.handle
218
- fg1 = active_window
219
- @app_handle.should == fg1
220
- end
221
- fg2 = active_window
222
- @app_handle.should_not == fg2
223
- end
224
- end
225
-
226
- describe '#get_window_text(w)' do
227
- spec{ use{ GetWindowText(any_handle, buffer = "\00"* 1024, buffer.size)}}
228
- # Improved with block to accept window handle as a single arg and return (rstripped) text string
229
- spec{ use{ text = get_window_text(handle = 0)}}
230
- # Unicode version of get_window_text (strings returned encoded as utf-8)
231
- spec{ use{ GetWindowTextW(any_handle, buffer = "\00"* 1024, buffer.size)}}
232
- spec{ use{ text = get_window_text_w(any_handle)}} # result encoded as utf-8
233
-
234
- it 'returns nil if incorrect window handle given' do
235
- get_window_text(not_a_handle).should == nil
236
- get_window_text_w(not_a_handle).should == nil
237
- end
238
-
239
- it 'returns correct window text' do
240
- test_app do |app|
241
- get_window_text(app.handle).should == TEST_WIN_TITLE
242
- get_window_text_w(app.handle).should == TEST_WIN_TITLE
243
- end
244
- end
245
- end
246
-
247
- describe '#get_class_name(w)' do
248
- spec{ use{ GetClassName(any_handle, buffer = "\00"* 1024, buffer.size)}}
249
- # Improved with block to accept window handle as a single arg and return class name string
250
- spec{ use{ class_name = get_class_name(any_handle)}}
251
- # Unicode version of get_class_name (strings returned encoded as utf-8)
252
- spec{ use{ GetClassNameW(any_handle, buffer = "\00"* 1024, buffer.size)}}
253
- spec{ use{ class_name = get_class_name_w(handle = 0)}} # result encoded as utf-8
254
-
255
- it 'returns correct window class name' do
256
- test_app do |app|
257
- get_class_name(app.handle).should == TEST_WIN_CLASS
258
- get_class_name_w(app.handle).should == TEST_WIN_CLASS
259
- end
260
- end
261
- end
262
-
263
- describe '#get_window_thread_process_id' do
264
- spec{ use{ thread = GetWindowThreadProcessId(any_handle, process_buffer = [1].pack('L')) }}
265
- spec{ use{ thread, process = get_window_thread_process_id(any_handle) }}
266
- # Improved with block to accept window handle as a single arg and return a pair of [thread, process]
267
-
268
- it 'returns a pair of nonzero Integer ids (thread and process) for valid window' do
269
- thread, process = get_window_thread_process_id(any_handle)
270
- thread.should be_a_kind_of Integer
271
- thread.should be > 0
272
- process.should be_a_kind_of Integer
273
- process.should be > 0
274
- end
275
-
276
- it 'returns a pair of nils (thread and process) for invalid window' do
277
- thread, process = get_window_thread_process_id(not_a_handle)
278
- thread.should == nil
279
- process.should == nil
280
- end
281
- end
282
-
283
- describe '#get_window_rect' do
284
- spec{ use{ success = GetWindowRect(any_handle, rectangle = [0, 0, 0, 0].pack('L*'))}}
285
- spec{ use{ left, top, right, bottom = get_window_rect(any_handle)}}
286
-
287
- it 'returns array of nils for invalid window' do
288
- get_window_rect(not_a_handle).should == [nil, nil, nil, nil]
289
- end
290
-
291
- it 'returns window`s border rectangle' do
292
- test_app do |app|
293
- get_window_rect(app.handle).should == TEST_WIN_RECT
294
- end
295
- end
296
- end
297
-
298
- describe '#show_window ', 'LI', 'I' do
299
- spec{ use{ was_visible = show_window(handle = any_handle, cmd = SW_SHOWNA) }}
300
-
301
- it 'was_visible = hide_window(handle = any_handle) # derived method (not a separate API function)' do
302
- test_app do |app|
303
- use{ @was_visible = hide_window(app.handle) }
304
- @was_visible.should == true
305
- visible?(app.handle).should == false
306
- hide_window(app.handle).should == false
307
- visible?(app.handle).should == false
308
- end
309
- end
310
-
311
- it 'returns true if the window was PREVIOUSLY visible, false otherwise' do
312
- test_app do |app|
313
- show_window(app.handle, SW_HIDE).should == true
314
- show_window(app.handle, SW_HIDE).should == false
315
- end
316
- end
317
-
318
- it 'hides window with SW_HIDE command ' do
319
- test_app do |app|
320
- show_window(app.handle, SW_HIDE)
321
- visible?(app.handle).should == false
322
- end
323
- end
324
-
325
- it 'shows hidden window with SW_SHOW command' do
326
- test_app do |app|
327
- hide_window(app.handle)
328
- show_window(app.handle, SW_SHOW)
329
- visible?(app.handle).should == true
330
- end
331
- end
332
-
333
- it 'SW_MAXIMIZE, SW_SHOWMAXIMIZED maximize window and activate it' do
334
- test_show_window SW_MAXIMIZE, SW_SHOWMAXIMIZED,
335
- :minimized? => false, :maximized? => true, :visible? => true, :foreground? => true
336
- end
337
-
338
- it 'SW_MINIMIZE minimizes window and activates the next top-level window in the Z order' do
339
- test_show_window SW_MINIMIZE,
340
- :minimized? => true, :maximized? => false, :visible? => true, :foreground? => false
341
- end
342
-
343
- it 'SW_SHOWMINNOACTIVE, SW_SHOWMINIMIZED displays the window as a minimized foreground window' do
344
- test_show_window SW_SHOWMINNOACTIVE, SW_SHOWMINIMIZED,
345
- :minimized? => true, :maximized? => false, :visible? => true, :foreground? => true
346
- end
347
-
348
- it 'SW_SHOWNORMAL, SW_RESTORE, SW_SHOWNOACTIVATE activate/display a window(if min/maximized it is restored' do
349
- test_show_window SW_SHOWNORMAL, SW_RESTORE, SW_SHOWNOACTIVATE,
350
- :minimized? => false, :maximized? => false, :visible? => true, :foreground? => true
351
- end
352
-
353
- it 'SW_SHOWNA displays the window in its current size and position (similar to SW_SHOW, but window is not activated)'
354
- it 'SW_SHOWDEFAULT sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application'
355
- it 'SW_FORCEMINIMIZE minimizes a window, even if the thread that owns the window is not responding - only Win2000/XP'
356
- end
357
-
358
- describe '#keydb_event' do
359
- spec{ use{ keybd_event(vkey = 0, bscan = 0, flags = 0, extra_info = 0) }}
360
- # vkey (I) - Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see msdn:Virtual Key Codes.
361
- # bscan (I) - Specifies a hardware scan code for the key.
362
- # flags (L) - Specifies various aspects of function operation. This parameter can be one or more of the following values.
363
- # KEYEVENTF_EXTENDEDKEY - If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
364
- # KEYEVENTF_KEYUP - If specified, the key is being released. If not specified, the key is being depressed.
365
- # extra_info (L) - Specifies an additional value associated with the key stroke.
366
- # no return value
367
-
368
- it 'synthesizes a numeric keystrokes, emulating keyboard driver' do
369
- test_app do |app|
370
- text = '123 456'
371
- text.upcase.each_byte do |b| # upcase needed since user32 keybd_event expects upper case chars
372
- keybd_event(b.ord, 0, KEYEVENTF_KEYDOWN, 0)
373
- sleep TEST_KEY_DELAY
374
- keybd_event(b.ord, 0, KEYEVENTF_KEYUP, 0)
375
- sleep TEST_KEY_DELAY
376
- end
377
- app.textarea.text.should =~ Regexp.new(text)
378
- 7.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
379
- end
380
- end
381
-
382
- it 'synthesizes a letter keystroke, emulating keyboard driver'
383
- end
384
-
385
- describe '#post_message' do
386
- spec{ use{ success = post_message(handle = 0, msg = 0, w_param = 0, l_param = 0) }}
387
- # handle (L) - Handle to the window whose window procedure will receive the message.
388
- # If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or
389
- # invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
390
- # msg (L) - Specifies the message to be posted.
391
- # w_param (L) - Specifies additional message-specific information.
392
- # l_param (L) - Specifies additional message-specific information.
393
- # returns (L) - Nonzero if success, zero if function failed. To get extended error information, call GetLastError.
394
-
395
- it 'places (posts) a message in the message queue associated with the thread that created the specified window'
396
- it 'returns without waiting for the thread to process the message'
397
- end
398
-
399
- describe '#send_message' do
400
- spec{ use{ success = send_message(handle = 0, msg = 0, w_param = 1024, l_param = "\x0"*1024) }}
401
- # handle (L) - Handle to the window whose window procedure is to receive the message. The following values have special meanings.
402
- # HWND_BROADCAST - The message is posted to all top-level windows in the system, including disabled or invisible unowned windows,
403
- # overlapped windows, and pop-up windows. The message is not posted to child windows.
404
- # NULL - The function behaves like a call to PostThreadMessage with the dwThreadId parameter set to the identifier of the current thread.
405
- # msg (L) - Specifies the message to be posted.
406
- # w_param (L) - Specifies additional message-specific information.
407
- # l_param (L) - Specifies additional message-specific information.
408
- # return (L) - Nonzero if success, zero if function failed. To get extended error information, call GetLastError.
409
-
410
- it 'sends the specified message to a window or windows'
411
- it 'calls the window procedure and does not return until the window procedure has processed the message'
412
- end
413
-
414
- describe '#get_dlg_item' do
415
- spec{ use{ control_handle = get_dlg_item(handle = 0, item_id = 1) }}
416
- # handle (L) - Handle of the dialog box that contains the control.
417
- # item_id (I) - Specifies the identifier of the control to be retrieved.
418
- # Returns (L) - handle of the specified control if success or nil for invalid dialog box handle or a nonexistent control.
419
- # To get extended error information, call GetLastError.
420
- # You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the handle
421
- # parameter specifies a parent window and the child window has a unique id (as specified by the hMenu parameter in the
422
- # CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window.
423
-
424
- it 'returns handle to correctly specified control'
425
- end
426
-
427
- describe '#enum_windows' do
428
- spec{ use{ enum_windows(message = 'Message') }}
429
-
430
- it 'return an array of top-level window handles if block is not given' do
431
- test_app do |app|
432
- enum = enum_windows(message = 'Message')
433
- enum.should be_a_kind_of Array
434
- enum.should_not be_empty
435
- enum.should have_at_least(60).elements # typical number of top windows in WinXP system?
436
- enum.each{|handle| handle.should be_an Integer }
437
- enum.any?{|handle| handle == app.handle}.should == true
438
- end
439
- end
440
- it 'iterates through all the top-level windows, passing each found window handle and message to a given block'
441
-
442
- end
443
-
444
- describe '#enum_child_windows' do
445
- spec{ use{ enum_child_windows(parent = any_handle, message = 'Message') }}
446
-
447
- it 'return an array of child window handles if block is not given' do
448
- test_app do |app|
449
- enum = enum_child_windows(app.handle, message = 'Message')
450
- enum.should be_a_kind_of Array
451
- enum.should have(2).elements
452
- class_name(enum.first).should == TEST_STATUSBAR_CLASS
453
- class_name(enum.last).should == TEST_TEXTAREA_CLASS
454
- end
455
- end
456
-
457
- it 'loops through all children of given window, passing each found window handle and a message to a given block' do
458
- test_app do |app|
459
- enum = []
460
- enum_child_windows(app.handle, 'Message') do |handle, message|
461
- enum << handle
462
- message.should == 'Message'
463
- end
464
- enum.should have(2).elements
465
- class_name(enum.first).should == TEST_STATUSBAR_CLASS
466
- class_name(enum.last).should == TEST_TEXTAREA_CLASS
467
- end
468
- end
469
-
470
- it 'breaks loop if given block returns false' do
471
- pending
472
- test_app do |app|
473
- enum = []
474
- enum_child_windows(app.handle, 'Message') do |handle, message|
475
- enum << handle
476
- 1
477
- end
478
- enum.should have(1).element
479
- class_name(enum.first).should == TEST_STATUSBAR_CLASS
480
- # class_name(enum.last).should == TEST_TEXTAREA_CLASS
481
- end
482
- end
483
- end
484
- end
485
-
486
- describe WinGui, ' convenience wrapper methods' do
487
- describe '#keystroke' do
488
- spec{ use{ keystroke( vkey = 30, vkey = 30) }}
489
- # this service method emulates combinations of (any amount of) keys pressed one after another (Ctrl+Alt+P) and then released
490
- # vkey (int) - Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see msdn:Virtual Key Codes.
491
-
492
- it 'emulates combinations of keys pressed (Ctrl+Alt+P+M, etc)' do
493
- test_app do |app|
494
- keystroke(VK_CONTROL, 'A'.ord)
495
- keystroke(VK_SPACE)
496
- app.textarea.text.should == ' '
497
- 2.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
498
- end
499
- end
500
- end
501
-
502
- describe '#type_in' do
503
- spec{ use{ type_in(message = '') }}
504
- # this service method types text message into window holding the focus
505
-
506
- it 'types text message into window holding the focus' do
507
- test_app do |app|
508
- text = '123 456'
509
- type_in(text)
510
- app.textarea.text.should =~ Regexp.new(text)
511
- 7.times {keystroke(VK_CONTROL, 'Z'.ord)} # dirty hack!
512
- end
513
- end
514
- end
515
-
516
- describe 'dialog' do
517
- spec{ use{ dialog( title ='Dialog Title', timeout_sec = 0.001, &any_block) }}
518
- # me od finds top-level dialog window by title and yields found dialog window to block if given
519
-
520
- it 'finds top-level dialog window by title' do
521
- pending 'Some problems (?with timeouts?) leave window open ~half of the runs'
522
- test_app do |app|
523
- keystroke(VK_ALT, 'F'.ord, 'A'.ord)
524
- @found = false
525
- dialog('Save As', 0.5) do |dialog_window|
526
- @found = true
527
- keystroke(VK_ESCAPE)
528
- dialog_window
529
- end
530
- @found.should == true
531
- end
532
- end
533
- it 'yields found dialog window to a given block'
534
- end
535
-
536
- end
537
- end