win 0.3.24 → 0.3.25
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.
- data/HISTORY +4 -0
- data/README.rdoc +4 -5
- data/VERSION +1 -1
- data/lib/win.rb +1 -1
- data/lib/win/gui/menu.rb +34 -3
- data/lib/win/gui/message.rb +1 -3
- data/lib/win/gui/window.rb +1 -1
- data/lib/win/library.rb +10 -5
- data/lib/win/national.rb +585 -0
- data/lib/win/time.rb +140 -0
- data/spec/extension_spec.rb +2 -38
- data/spec/spec_helper.rb +60 -71
- data/spec/win/dde_spec.rb +435 -437
- data/spec/win/error_spec.rb +86 -88
- data/spec/win/gui/dialog_spec.rb +43 -46
- data/spec/win/gui/input_spec.rb +81 -85
- data/spec/win/gui/menu_spec.rb +260 -247
- data/spec/win/gui/message_spec.rb +218 -219
- data/spec/win/gui/window_spec.rb +558 -557
- data/spec/win/library_spec.rb +180 -199
- data/spec/win/system/info_spec.rb +42 -45
- data/spec/win/system/version_spec.rb +143 -146
- data/spec/win/time_spec.rb +48 -0
- data/tasks/spec.rake +5 -9
- metadata +16 -36
data/spec/win/gui/window_spec.rb
CHANGED
@@ -1,694 +1,695 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'win/gui/window'
|
3
3
|
|
4
|
-
|
4
|
+
include WinTestApp
|
5
|
+
include Win::Gui::Window
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def window_should_be(handle, tests)
|
8
|
+
tests.each { |test, result| send(test.to_sym, handle).should == result }
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
def commands_should_show_window(*cmds, tests)
|
12
|
+
cmds.each do |cmd|
|
13
|
+
test_app do |app|
|
14
|
+
show_window(app.handle, cmd)
|
15
|
+
window_should_be app.handle, tests
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
show_window(app.handle, cmd)
|
17
|
-
window_should_be app.handle, tests
|
17
|
+
hide_window(app.handle) # hiding window first
|
18
|
+
show_window(app.handle, cmd)
|
19
|
+
window_should_be app.handle, tests
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
show_window(app.handle, SW_MAXIMIZE) # now maximizing window
|
22
|
+
show_window(app.handle, cmd)
|
23
|
+
window_should_be app.handle, tests
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
show_window(app.handle, SW_MINIMIZE) # now minimizing window
|
28
|
-
show_window(app.handle, cmd)
|
29
|
-
window_should_be app.handle, tests
|
30
|
-
end
|
25
|
+
show_window(app.handle, SW_MINIMIZE) # now minimizing window
|
26
|
+
show_window(app.handle, cmd)
|
27
|
+
window_should_be app.handle, tests
|
31
28
|
end
|
32
29
|
end
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
describe Win::Gui::Window, ' defines a set of API functions related to Window manipulation' do
|
33
|
+
context 'ensuring test app closes' do
|
34
|
+
after(:each) { close_test_app if @launched_test_app }
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
describe '#window?' do
|
37
|
+
spec { use { IsWindow(any_handle) } }
|
38
|
+
spec { use { is_window(any_handle) } }
|
39
|
+
spec { use { window?(any_handle) } }
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
it 'returns true if window exists' do
|
42
|
+
window?(any_handle).should == true
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
it 'returns false for invalid window handle' do
|
46
|
+
window?(not_a_handle).should == false
|
47
|
+
end
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
window?(@app_handle).should == false
|
59
|
-
window?(@ta_handle).should == false
|
49
|
+
it 'changes from true to false when existing window is closed' do
|
50
|
+
test_app do |app|
|
51
|
+
@app_handle = app.handle
|
52
|
+
@ta_handle = app.textarea
|
53
|
+
window?(@app_handle).should == true
|
54
|
+
window?(@ta_handle).should == true
|
60
55
|
end
|
56
|
+
window?(@app_handle).should == false
|
57
|
+
window?(@ta_handle).should == false
|
61
58
|
end
|
59
|
+
end
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
describe '#window_visible?' do
|
62
|
+
spec { use { IsWindowVisible(any_handle) } }
|
63
|
+
spec { use { is_window_visible(any_handle) } }
|
64
|
+
spec { use { window_visible?(any_handle) } }
|
65
|
+
spec { use { visible?(any_handle) } }
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
67
|
+
it 'returns true when window is visible, false when window is hidden' do
|
68
|
+
test_app do |app|
|
69
|
+
visible?(app.handle).should == true
|
70
|
+
window_visible?(app.handle).should == true
|
71
|
+
window_visible?(app.textarea).should == true
|
72
|
+
hide_window(app.handle)
|
73
|
+
visible?(app.handle).should == false
|
74
|
+
window_visible?(app.handle).should == false
|
75
|
+
window_visible?(app.textarea).should == false
|
79
76
|
end
|
80
77
|
end
|
78
|
+
end
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
describe '#maximized?' do
|
81
|
+
spec { use { IsZoomed(any_handle) } }
|
82
|
+
spec { use { is_zoomed(any_handle) } }
|
83
|
+
spec { use { zoomed?(any_handle) } }
|
84
|
+
spec { use { maximized?(any_handle) } }
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
86
|
+
it 'returns true if the window is maximized, false otherwise' do
|
87
|
+
test_app do |app|
|
88
|
+
zoomed?(app.handle).should == false
|
89
|
+
maximized?(app.handle).should == false
|
90
|
+
show_window(app.handle, SW_MAXIMIZE)
|
91
|
+
maximized?(app.handle).should == true
|
92
|
+
zoomed?(app.handle).should == true
|
96
93
|
end
|
97
94
|
end
|
95
|
+
end
|
98
96
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
describe '#minimized?' do
|
98
|
+
spec { use { IsIconic(any_handle) } }
|
99
|
+
spec { use { is_iconic(any_handle) } }
|
100
|
+
spec { use { iconic?(any_handle) } }
|
101
|
+
spec { use { minimized?(any_handle) } }
|
104
102
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
103
|
+
it 'returns true if the window is minimized, false otherwise' do
|
104
|
+
test_app do |app|
|
105
|
+
iconic?(app.handle).should == false
|
106
|
+
minimized?(app.handle).should == false
|
107
|
+
show_window(app.handle, SW_MINIMIZE)
|
108
|
+
iconic?(app.handle).should == true # !
|
109
|
+
minimized?(app.handle).should == true
|
113
110
|
end
|
114
111
|
end
|
112
|
+
end
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
describe '#child?' do
|
115
|
+
spec { use { IsChild(parent_handle = any_handle, handle = any_handle) } }
|
116
|
+
spec { use { is_child(parent_handle = any_handle, handle = any_handle) } }
|
117
|
+
spec { use { child?(parent_handle = any_handle, handle = any_handle) } }
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
119
|
+
it 'returns true if the window is a child of given parent, false otherwise' do
|
120
|
+
test_app do |app|
|
121
|
+
child?(app.handle, app.textarea).should == true
|
122
|
+
child?(app.handle, any_handle).should == false
|
126
123
|
end
|
127
124
|
end
|
125
|
+
end
|
128
126
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
127
|
+
describe '#find_window(w)' do
|
128
|
+
spec { use { FindWindow(class_name = nil, win_name = nil) } }
|
129
|
+
spec { use { find_window(class_name = nil, win_name = nil) } }
|
130
|
+
# Widebyte (unicode) version
|
131
|
+
spec { use { FindWindowW(class_name = nil, win_name = nil) } }
|
132
|
+
spec { use { find_window_w(class_name = nil, win_name = nil) } }
|
135
133
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
134
|
+
it 'returns either Integer Window handle or nil' do
|
135
|
+
find_window(nil, nil).should be_a_kind_of Integer
|
136
|
+
find_window(IMPOSSIBLE, nil).should == nil
|
137
|
+
end
|
140
138
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
139
|
+
it 'returns nil if Window is not found' do
|
140
|
+
find_window(IMPOSSIBLE, nil).should == nil
|
141
|
+
find_window(nil, IMPOSSIBLE).should == nil
|
142
|
+
find_window(IMPOSSIBLE, IMPOSSIBLE).should == nil
|
143
|
+
find_window_w(IMPOSSIBLE, nil).should == nil
|
144
|
+
find_window_w(nil, IMPOSSIBLE).should == nil
|
145
|
+
find_window_w(IMPOSSIBLE, IMPOSSIBLE).should == nil
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'finds at least one window if both args are nils' do
|
149
|
+
find_window(nil, nil).should_not == nil
|
150
|
+
find_window_w(nil, nil).should_not == nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'finds top-level window by window class or title' do
|
154
|
+
test_app do |app|
|
155
|
+
find_window(WIN_CLASS, nil).should == app.handle
|
156
|
+
find_window(nil, WIN_TITLE).should == app.handle
|
157
|
+
find_window_w(WIN_CLASS.to_w, nil).should == app.handle
|
158
|
+
find_window_w(nil, WIN_TITLE.to_w).should == app.handle
|
148
159
|
end
|
160
|
+
end
|
161
|
+
end
|
149
162
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
163
|
+
describe '#find_window_ex' do
|
164
|
+
spec { use { FindWindowEx(parent = any_handle, after_child = 0, win_class = nil, win_title = nil) } }
|
165
|
+
spec { use { find_window_ex(parent = any_handle, after_child = 0, win_class = nil, win_title = nil) } }
|
154
166
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
167
|
+
it 'returns nil if wrong control is given' do
|
168
|
+
parent_handle = any_handle
|
169
|
+
find_window_ex(parent_handle, 0, IMPOSSIBLE, nil).should == nil
|
170
|
+
find_window_ex(parent_handle, 0, nil, IMPOSSIBLE).should == nil
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'finds child window/control by class' do
|
174
|
+
test_app do |app|
|
175
|
+
ta_handle = find_window_ex(app.handle, 0, TEXTAREA_CLASS, nil)
|
176
|
+
ta_handle.should_not == nil
|
177
|
+
ta_handle.should == app.textarea
|
162
178
|
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe '#find_window_ex' do
|
166
|
-
spec{ use{ FindWindowEx(parent = any_handle, after_child = 0, win_class = nil, win_title = nil) }}
|
167
|
-
spec{ use{ find_window_ex(parent = any_handle, after_child = 0, win_class = nil, win_title = nil) }}
|
179
|
+
end
|
168
180
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
181
|
+
it 'finds child window/control by text/title' do
|
182
|
+
pending 'Identify appropriate (short name) control'
|
183
|
+
test_app do |app|
|
184
|
+
keystroke(VK_CONTROL, 'A'.ord)
|
185
|
+
keystroke('1'.ord, '2'.ord)
|
186
|
+
ta_handle = find_window_ex(app.handle, 0, nil, '12')
|
187
|
+
ta_handle.should_not == 0
|
188
|
+
ta_handle.should == app.textarea.handle
|
173
189
|
end
|
190
|
+
end
|
191
|
+
end
|
174
192
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
193
|
+
describe "#set_foreground_window" do
|
194
|
+
spec { use { success = SetForegroundWindow(handle=0) } }
|
195
|
+
spec { use { success = set_foreground_window(handle=0) } }
|
196
|
+
|
197
|
+
it "puts the thread that created the specified window into the foreground and activates the window" do
|
198
|
+
test_app do |app|
|
199
|
+
set_foreground_window(any_handle).should be_true
|
200
|
+
foreground?(app.handle).should be_false
|
201
|
+
success = set_foreground_window(app.handle)
|
202
|
+
foreground?(app.handle).should be_true
|
181
203
|
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it "returns false/0 if operation failed" do
|
207
|
+
set_foreground_window(not_a_handle).should == false
|
208
|
+
SetForegroundWindow(not_a_handle).should == 0
|
209
|
+
end
|
210
|
+
end # describe set_foreground_window
|
182
211
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
212
|
+
describe '#get_foreground_window' do
|
213
|
+
# ! Different from GetActiveWindow !
|
214
|
+
spec { use { handle = GetForegroundWindow() } }
|
215
|
+
spec { use { handle = get_foreground_window } }
|
216
|
+
spec { use { handle = foreground_window } }
|
217
|
+
|
218
|
+
it 'returns handle to window that is currently in foreground' do
|
219
|
+
test_app do |app|
|
220
|
+
@app_handle = app.handle
|
221
|
+
get_foreground_window().should == @app_handle
|
222
|
+
GetForegroundWindow().should == @app_handle
|
192
223
|
end
|
224
|
+
get_foreground_window().should_not == @app_handle
|
225
|
+
GetForegroundWindow().should_not == @app_handle
|
193
226
|
end
|
194
227
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
it "puts the thread that created the specified window into the foreground and activates the window" do
|
200
|
-
test_app do |app|
|
201
|
-
set_foreground_window(any_handle).should be_true
|
202
|
-
foreground?(app.handle).should be_false
|
203
|
-
success = set_foreground_window(app.handle)
|
204
|
-
foreground?(app.handle).should be_true
|
205
|
-
end
|
228
|
+
it 'defines #foreground? test function ' do
|
229
|
+
test_app do |app|
|
230
|
+
@app_handle = app.handle
|
231
|
+
foreground?(@app_handle).should == true
|
206
232
|
end
|
233
|
+
foreground?(@app_handle).should == false
|
234
|
+
end
|
235
|
+
end
|
207
236
|
|
208
|
-
|
209
|
-
|
210
|
-
|
237
|
+
describe '#get_active_window' do
|
238
|
+
# ! Different from GetForegroundWindow !
|
239
|
+
spec { use { handle = GetActiveWindow() } }
|
240
|
+
spec { use { handle = get_active_window } }
|
241
|
+
spec { use { handle = active_window } }
|
242
|
+
|
243
|
+
it 'returns handle to the active window attached to the calling thread`s message queue' do
|
244
|
+
pending 'No idea how to test it'
|
245
|
+
test_app do |app|
|
246
|
+
@app_handle = app.handle
|
247
|
+
GetActiveWindow().should == @app_handle
|
248
|
+
get_active_window().should == @app_handle
|
211
249
|
end
|
212
|
-
|
250
|
+
GetActiveWindow().should_not == @app_handle
|
251
|
+
get_active_window().should_not == @app_handle
|
252
|
+
end
|
253
|
+
end
|
213
254
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
255
|
+
describe '#get_window_text(w)' do
|
256
|
+
spec { use { GetWindowText(any_handle, buffer, buffer.size) } }
|
257
|
+
# Improved with block to accept window handle as a single arg and return (rstripped) text string
|
258
|
+
spec { use { text = get_window_text(handle = 0) } }
|
259
|
+
spec { use { text = window_text(handle = 0) } }
|
260
|
+
# Unicode version of get_window_text (strings returned encoded as utf-8)
|
261
|
+
spec { use { GetWindowTextW(any_handle, buffer, buffer.size) } }
|
262
|
+
spec { use { text = get_window_text_w(any_handle) } } # result encoded as utf-8
|
263
|
+
spec { use { text = window_text_w(handle = 0) } }
|
264
|
+
|
265
|
+
it 'returns nil if incorrect window handle given' do
|
266
|
+
get_window_text(not_a_handle).should == nil
|
267
|
+
get_window_text_w(not_a_handle).should == nil
|
268
|
+
end
|
219
269
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
get_foreground_window().should_not == @app_handle
|
227
|
-
GetForegroundWindow().should_not == @app_handle
|
270
|
+
it 'returns correct window text' do
|
271
|
+
test_app do |app|
|
272
|
+
get_window_text(app.handle).should == WIN_TITLE
|
273
|
+
get_window_text_w(app.handle).should == WIN_TITLE
|
274
|
+
window_text(app.handle).should == WIN_TITLE
|
275
|
+
window_text_w(app.handle).should == WIN_TITLE
|
228
276
|
end
|
277
|
+
end
|
278
|
+
end
|
229
279
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
280
|
+
describe '#get_class_name(w)' do
|
281
|
+
spec { use { GetClassName(any_handle, buffer, buffer.size) } }
|
282
|
+
# Improved with block to accept window handle as a single arg and return class name string
|
283
|
+
spec { use { class_name = get_class_name(any_handle) } }
|
284
|
+
spec { use { class_name = class_name(any_handle) } }
|
285
|
+
# Unicode version of get_class_name (strings returned encoded as utf-8)
|
286
|
+
spec { use { GetClassNameW(any_handle, buffer, buffer.size) } }
|
287
|
+
spec { use { class_name = get_class_name_w(handle = 0) } } # result encoded as utf-8
|
288
|
+
spec { use { class_name = class_name_w(any_handle) } }
|
289
|
+
|
290
|
+
it 'returns correct window class name' do
|
291
|
+
test_app do |app|
|
292
|
+
get_class_name(app.handle).should == WIN_CLASS
|
293
|
+
class_name(app.handle).should == WIN_CLASS
|
294
|
+
class_name_w(app.handle).should == WIN_CLASS #!!!!!!!!!!! nil?
|
295
|
+
get_class_name_w(app.handle).should == WIN_CLASS #!!!!!! nil?
|
236
296
|
end
|
237
297
|
end
|
298
|
+
end
|
238
299
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
300
|
+
describe '#get_window_thread_process_id' do
|
301
|
+
spec { use { thread = GetWindowThreadProcessId(any_handle, process = FFI::MemoryPointer.new(:long).write_long(1)) } }
|
302
|
+
spec { use { thread, process = get_window_thread_process_id(any_handle) } }
|
303
|
+
# Improved with block to accept window handle as a single arg and return a pair of [thread, process]
|
304
|
+
|
305
|
+
it 'returns a pair of nonzero Integer ids (thread and process) for valid window' do
|
306
|
+
thread, process = get_window_thread_process_id(any_handle)
|
307
|
+
thread.should be_a_kind_of Integer
|
308
|
+
thread.should be > 0
|
309
|
+
process.should be_a_kind_of Integer
|
310
|
+
process.should be > 0
|
311
|
+
end
|
244
312
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
GetActiveWindow().should == @app_handle
|
250
|
-
get_active_window().should == @app_handle
|
251
|
-
end
|
252
|
-
GetActiveWindow().should_not == @app_handle
|
253
|
-
get_active_window().should_not == @app_handle
|
254
|
-
end
|
313
|
+
it 'returns a pair of nils (thread and process) for invalid window' do
|
314
|
+
thread, process = get_window_thread_process_id(not_a_handle)
|
315
|
+
thread.should == nil
|
316
|
+
process.should == nil
|
255
317
|
end
|
318
|
+
end
|
256
319
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
spec{ use{ text = get_window_text(handle = 0)}}
|
261
|
-
spec{ use{ text = window_text(handle = 0)}}
|
262
|
-
# Unicode version of get_window_text (strings returned encoded as utf-8)
|
263
|
-
spec{ use{ GetWindowTextW(any_handle, buffer, buffer.size)}}
|
264
|
-
spec{ use{ text = get_window_text_w(any_handle)}} # result encoded as utf-8
|
265
|
-
spec{ use{ text = window_text_w(handle = 0)}}
|
320
|
+
describe '#get_window_rect' do
|
321
|
+
spec { use { success = GetWindowRect(any_handle, rectangle = FFI::MemoryPointer.new(:long, 4)) } }
|
322
|
+
spec { use { left, top, right, bottom = get_window_rect(any_handle) } }
|
266
323
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
end
|
324
|
+
it 'returns array of nils for invalid window' do
|
325
|
+
get_window_rect(not_a_handle).should == [nil, nil, nil, nil]
|
326
|
+
end
|
271
327
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
get_window_text_w(app.handle).should == WIN_TITLE
|
276
|
-
window_text(app.handle).should == WIN_TITLE
|
277
|
-
window_text_w(app.handle).should == WIN_TITLE
|
278
|
-
end
|
328
|
+
it 'returns window`s border rectangle' do
|
329
|
+
test_app do |app|
|
330
|
+
get_window_rect(app.handle).should == WIN_RECT
|
279
331
|
end
|
280
332
|
end
|
333
|
+
end
|
281
334
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
spec{ use{ class_name = get_class_name(any_handle)}}
|
286
|
-
spec{ use{ class_name = class_name(any_handle)}}
|
287
|
-
# Unicode version of get_class_name (strings returned encoded as utf-8)
|
288
|
-
spec{ use{ GetClassNameW(any_handle, buffer, buffer.size)}}
|
289
|
-
spec{ use{ class_name = get_class_name_w(handle = 0)}} # result encoded as utf-8
|
290
|
-
spec{ use{ class_name = class_name_w(any_handle)}}
|
335
|
+
describe '#show_window' do
|
336
|
+
spec { use { was_visible = ShowWindow(handle = any_handle, cmd = SW_SHOW) } }
|
337
|
+
spec { use { was_visible = show_window(handle = any_handle) } }
|
291
338
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
get_class_name_w(app.handle).should == WIN_CLASS #!!!!!! nil?
|
298
|
-
end
|
339
|
+
it 'defaults to SW_SHOW if no command given' do
|
340
|
+
test_app do |app|
|
341
|
+
hide_window(app.handle)
|
342
|
+
use { show_window(app.handle) }
|
343
|
+
visible?(app.handle).should == true
|
299
344
|
end
|
300
345
|
end
|
301
346
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
347
|
+
it 'returns true if the window was PREVIOUSLY visible, false otherwise' do
|
348
|
+
test_app do |app|
|
349
|
+
show_window(app.handle, SW_HIDE).should == true
|
350
|
+
show_window(app.handle, SW_HIDE).should == false
|
351
|
+
end
|
352
|
+
end
|
306
353
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
process.should be_a_kind_of Integer
|
312
|
-
process.should be > 0
|
354
|
+
it 'hides window with SW_HIDE command ' do
|
355
|
+
test_app do |app|
|
356
|
+
show_window(app.handle, SW_HIDE)
|
357
|
+
visible?(app.handle).should == false
|
313
358
|
end
|
359
|
+
end
|
314
360
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
361
|
+
it 'shows hidden window with SW_SHOW command' do
|
362
|
+
test_app do |app|
|
363
|
+
hide_window(app.handle)
|
364
|
+
show_window(app.handle, SW_SHOW)
|
365
|
+
visible?(app.handle).should == true
|
319
366
|
end
|
320
367
|
end
|
321
368
|
|
322
|
-
|
323
|
-
|
324
|
-
|
369
|
+
it 'SW_MAXIMIZE, SW_SHOWMAXIMIZED maximize window and activate it' do
|
370
|
+
commands_should_show_window SW_MAXIMIZE, SW_SHOWMAXIMIZED,
|
371
|
+
:minimized? => false, :maximized? => true, :visible? => true, :foreground? => true
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'SW_MINIMIZE minimizes window and activates the next top-level window in the Z order' do
|
375
|
+
commands_should_show_window SW_MINIMIZE,
|
376
|
+
:minimized? => true, :maximized? => false, :visible? => true, :foreground? => false
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'SW_SHOWMINNOACTIVE, SW_SHOWMINIMIZED displays the window as a minimized foreground window' do
|
380
|
+
commands_should_show_window SW_SHOWMINNOACTIVE, SW_SHOWMINIMIZED, #!
|
381
|
+
:minimized? => true, :maximized? => false, :visible? => true, :foreground? => true
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'SW_SHOWNORMAL, SW_RESTORE, SW_SHOWNOACTIVATE activate/display a window(if min/maximized it is restored' do
|
385
|
+
commands_should_show_window SW_SHOWNORMAL, SW_RESTORE, SW_SHOWNOACTIVATE,
|
386
|
+
:minimized? => false, :maximized? => false, :visible? => true, :foreground? => true
|
387
|
+
end
|
325
388
|
|
326
|
-
|
327
|
-
|
389
|
+
# what about SW_SHOWNA, SW_SHOWDEFAULT, SW_FORCEMINIMIZE ?
|
390
|
+
end
|
391
|
+
|
392
|
+
describe '#close_window' do
|
393
|
+
spec { use { success = CloseWindow(handle = any_handle) } }
|
394
|
+
spec { use { success = close_window(handle = any_handle) } }
|
395
|
+
|
396
|
+
it 'minimizes (but does not destroy!) the specified window' do
|
397
|
+
test_app do |app|
|
398
|
+
close_window(app.handle).should == true
|
399
|
+
window_should_be app.handle,
|
400
|
+
:minimized? => true, :maximized? => false, :visible? => true, :foreground? => true
|
328
401
|
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
describe 'destroy_window' do
|
406
|
+
spec { use { success = DestroyWindow(handle = 0) } }
|
407
|
+
spec { use { success = destroy_window(handle = 0) } }
|
329
408
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
409
|
+
it 'destroys window created by current thread' do
|
410
|
+
pending
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'cannot destroy window created by other thread' do
|
414
|
+
test_app do |app|
|
415
|
+
destroy_window(app.handle).should == false
|
416
|
+
window?(app.handle).should == true
|
334
417
|
end
|
335
418
|
end
|
419
|
+
end # describe 'destroy_window'
|
336
420
|
|
337
|
-
describe '#show_window' do
|
338
|
-
spec{ use{ was_visible = ShowWindow(handle = any_handle, cmd = SW_SHOW) }}
|
339
|
-
spec{ use{ was_visible = show_window(handle = any_handle) }}
|
340
421
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
422
|
+
end # context 'ensuring test app closes'
|
423
|
+
|
424
|
+
context 'with single test app' do
|
425
|
+
before(:all) { @app = launch_test_app }
|
426
|
+
after(:all) { close_test_app }
|
427
|
+
|
428
|
+
describe "#get_parent" do
|
429
|
+
spec { use { parent = GetParent(any_handle) } }
|
430
|
+
spec { use { parent = get_parent(any_handle) } }
|
431
|
+
|
432
|
+
it "retrieves a handle to the specified window's parent or owner." do
|
433
|
+
child = find_window_ex(@app.handle, 0, nil, nil)
|
434
|
+
parent1 = GetParent(child)
|
435
|
+
parent2 = get_parent(child)
|
436
|
+
parent1.should == parent2
|
437
|
+
parent1.should == @app.handle
|
438
|
+
end
|
439
|
+
|
440
|
+
it "returns 0/nil if the specified window has no parent or owner." do
|
441
|
+
GetParent(@app.handle).should == 0
|
442
|
+
get_parent(@app.handle).should == nil
|
443
|
+
end
|
444
|
+
end # describe get_parent
|
445
|
+
|
446
|
+
describe "#get_ancestor" do
|
447
|
+
spec { use { ancestor = GetAncestor(any_handle, ga_flags=0) } }
|
448
|
+
spec { use { ancestor = get_ancestor(any_handle, ga_flags=0) } }
|
449
|
+
|
450
|
+
context 'GA_PARENT - Retrieves parent window. Unlike GetParent function, this does NOT include the owner.' do
|
451
|
+
it "retrieves a handle to the specified window's parent" do
|
452
|
+
child = find_window_ex(@app.handle, 0, nil, nil)
|
453
|
+
parent1 = GetAncestor(child, GA_PARENT)
|
454
|
+
parent2 = get_ancestor(child, GA_PARENT)
|
455
|
+
parent1.should == parent2
|
456
|
+
parent1.should == @app.handle
|
347
457
|
end
|
348
458
|
|
349
|
-
it
|
350
|
-
|
351
|
-
|
352
|
-
show_window(app.handle, SW_HIDE).should == false
|
353
|
-
end
|
459
|
+
it "returns desktop handle for top-level window" do
|
460
|
+
parent = get_ancestor(@app.handle, GA_PARENT)
|
461
|
+
class_name(parent).should == DESKTOP_CLASS
|
354
462
|
end
|
355
463
|
|
356
|
-
it
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
end
|
464
|
+
it "returns 0/nil if the specified window is a desktop (has REALLY no parent)" do
|
465
|
+
desktop = get_ancestor(@app.handle, GA_PARENT)
|
466
|
+
GetAncestor(desktop, GA_PARENT).should == 0
|
467
|
+
get_ancestor(desktop, GA_PARENT).should == nil
|
361
468
|
end
|
469
|
+
end # context GA_PARENT
|
362
470
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
471
|
+
context 'GA_ROOT - Retrieves the root window by walking the chain of parent windows' do
|
472
|
+
it "retrieves a handle to the specified window's root (top level parent)" do
|
473
|
+
child = find_window_ex(@app.handle, 0, nil, nil)
|
474
|
+
root1 = GetAncestor(child, GA_ROOT)
|
475
|
+
root2 = get_ancestor(child, GA_ROOT)
|
476
|
+
root1.should == root2
|
477
|
+
root1.should == @app.handle
|
369
478
|
end
|
479
|
+
end
|
480
|
+
# GA_ROOTOWNER - Retrieves the owned root window by walking the chain of parent and owner windows
|
481
|
+
# returned by GetParent.
|
482
|
+
end # describe get_ancestor
|
483
|
+
|
484
|
+
describe "#get_window" do
|
485
|
+
spec { use { handle = GetWindow(any_handle, command=0) } }
|
486
|
+
spec { use { handle = get_window(any_handle, command=0) } }
|
370
487
|
|
371
|
-
|
372
|
-
|
373
|
-
|
488
|
+
# GW_ENABLEDPOPUP - Windows 2000/XP: The retrieved handle identifies the enabled popup window owned by
|
489
|
+
|
490
|
+
context 'GW_HWND... works with windows of the same type' do
|
491
|
+
before(:all) do
|
492
|
+
@statusbar = find_window_ex(@app.handle, 0, STATUSBAR_CLASS, nil)
|
493
|
+
@textarea = find_window_ex(@app.handle, 0, TEXTAREA_CLASS, nil)
|
374
494
|
end
|
375
495
|
|
376
|
-
it '
|
377
|
-
|
378
|
-
|
496
|
+
it 'GW_HWNDFIRST - The retrieved handle identifies the window of the same type that is highest in Z order' do
|
497
|
+
get_window(@statusbar, GW_HWNDFIRST).should == @statusbar
|
498
|
+
end
|
499
|
+
it 'GW_HWNDLAST - The retrieved handle identifies the window of the same type that is lowest in the Z order' do
|
500
|
+
get_window(@statusbar, GW_HWNDLAST).should == @textarea
|
501
|
+
end
|
502
|
+
it 'GW_HWNDNEXT - The retrieved handle identifies the window below the specified window in the Z order' do
|
503
|
+
get_window(@statusbar, GW_HWNDNEXT).should == @textarea
|
504
|
+
end
|
505
|
+
it 'GW_HWNDPREV - The retrieved handle identifies the window above the specified window in the Z order' do
|
506
|
+
get_window(@textarea, GW_HWNDPREV).should == @statusbar
|
379
507
|
end
|
380
508
|
|
381
|
-
it '
|
382
|
-
|
383
|
-
|
509
|
+
it 'returns nil/0 in case nothing is returned' do
|
510
|
+
get_window(@textarea, GW_HWNDNEXT).should == nil
|
511
|
+
GetWindow(@textarea, GW_HWNDNEXT).should == 0
|
384
512
|
end
|
513
|
+
end # context 'GW_HWND...
|
385
514
|
|
386
|
-
|
387
|
-
|
388
|
-
|
515
|
+
context "GW_CHILD retrieves a window handle to a first (top of the Z order) child of given window" do
|
516
|
+
before(:all) do
|
517
|
+
# GW_CHILD - The retrieved handle identifies the child window at the top of the Z order, if the specified
|
518
|
+
@child1 = GetWindow(@app.handle, GW_CHILD)
|
519
|
+
@child2 = get_window(@app.handle, GW_CHILD)
|
389
520
|
end
|
390
521
|
|
391
|
-
|
392
|
-
|
522
|
+
it 'returns active window handle' do
|
523
|
+
window?(@child1).should == true
|
524
|
+
end
|
525
|
+
it 'returns the same value for original and snake case API' do
|
526
|
+
@child1.should == @child2
|
527
|
+
end
|
528
|
+
it 'returns first direct child of a given window' do
|
529
|
+
@child1.should == find_window_ex(@app.handle, 0, nil, nil)
|
530
|
+
end
|
531
|
+
it 'returns nil/0 if no children for a given window' do
|
532
|
+
GetWindow(@child1, GW_CHILD).should == 0
|
533
|
+
get_window(@child1, GW_CHILD).should == nil
|
534
|
+
end
|
535
|
+
end # context GW_CHILD
|
393
536
|
|
394
|
-
|
395
|
-
|
396
|
-
|
537
|
+
context "GW_OWNER - retrieves a handle to an owner of a given Window" do
|
538
|
+
# Ownership is a relationship between two top level windows while Parent is a relationship between a top
|
539
|
+
# level and a WS_CHILD, or a WS_CHILD and another WS_CHILD. The parent of a button is the form it is on,
|
540
|
+
# while a message box is owned by the form that showed it.
|
397
541
|
|
398
|
-
it '
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
542
|
+
it 'returns owner (but NOT parent!) of a given window' do
|
543
|
+
pending 'Need to open modal dialog, app should be it`s owner'
|
544
|
+
child = find_window_ex(@app.handle, 0, nil, nil)
|
545
|
+
p owner1 = GetWindow(child, GW_OWNER)
|
546
|
+
p owner2 = get_window(child, GW_OWNER)
|
547
|
+
owner1.should == owner2
|
548
|
+
owner1.should == @app.handle
|
549
|
+
end
|
550
|
+
|
551
|
+
it 'returns nil/0 if no owner for a given window' do
|
552
|
+
GetWindow(@app.handle, GW_OWNER).should == 0
|
553
|
+
get_window(@app.handle, GW_OWNER).should == nil
|
404
554
|
end
|
405
555
|
end
|
556
|
+
end # describe get_window
|
406
557
|
|
407
|
-
|
408
|
-
spec{ use{ success = DestroyWindow(handle = 0) }}
|
409
|
-
spec{ use{ success = destroy_window(handle = 0) }}
|
558
|
+
describe '#enum_windows' do
|
410
559
|
|
411
|
-
|
560
|
+
spec { use { handles = enum_windows(value = 13) } }
|
412
561
|
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
562
|
+
it 'iterates through all the top-level windows, passing each top level window handle and value to a given block' do
|
563
|
+
enum_windows(13) do |handle, message|
|
564
|
+
handle.should be_an Integer
|
565
|
+
handle.should be > 0
|
566
|
+
message.should == 13
|
418
567
|
end
|
419
|
-
end
|
568
|
+
end
|
420
569
|
|
570
|
+
it 'returns an array of top-level window handles if block is not given' do
|
571
|
+
enum = enum_windows(13)
|
572
|
+
enum.should be_a_kind_of Array
|
573
|
+
enum.should_not be_empty
|
574
|
+
enum.should have_at_least(5).elements # typical number of top windows in WinXP system?
|
575
|
+
enum.each do |handle|
|
576
|
+
handle.should be_an Integer
|
577
|
+
handle.should be > 0
|
578
|
+
end
|
579
|
+
enum.any? { |handle| handle == @app.handle }.should == true
|
580
|
+
end
|
421
581
|
|
422
|
-
|
582
|
+
it 'returned array that contains handle of launched test app' do
|
583
|
+
enum = enum_windows(13)
|
584
|
+
enum.any? { |handle| handle == @app.handle }.should == true
|
585
|
+
end
|
423
586
|
|
424
|
-
|
425
|
-
|
426
|
-
|
587
|
+
it 'defaults message to 0 if it is omitted from method call' do
|
588
|
+
enum_windows do |handle, message|
|
589
|
+
message.should == 0
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
427
593
|
|
428
|
-
|
429
|
-
|
430
|
-
|
594
|
+
describe '#enum_desktop_windows' do
|
595
|
+
spec { use { handles = enum_desktop_windows(0, value = 13) } }
|
596
|
+
spec { use { enum_desktop_windows(0) { |handle, message|} } }
|
431
597
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
parent1.should == parent2
|
437
|
-
parent1.should == @app.handle
|
438
|
-
end
|
598
|
+
it 'iterates through all the top-level windows for a given desktop' do
|
599
|
+
pending
|
600
|
+
end
|
601
|
+
end
|
439
602
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
context 'GA_PARENT - Retrieves parent window. Unlike GetParent function, this does NOT include the owner.' do
|
451
|
-
it "retrieves a handle to the specified window's parent" do
|
452
|
-
child = find_window_ex(@app.handle, 0, nil, nil)
|
453
|
-
parent1 = GetAncestor(child, GA_PARENT)
|
454
|
-
parent2 = get_ancestor(child, GA_PARENT)
|
455
|
-
parent1.should == parent2
|
456
|
-
parent1.should == @app.handle
|
457
|
-
end
|
458
|
-
|
459
|
-
it "returns desktop handle for top-level window" do
|
460
|
-
parent = get_ancestor(@app.handle, GA_PARENT)
|
461
|
-
class_name(parent).should == DESKTOP_CLASS
|
462
|
-
end
|
463
|
-
|
464
|
-
it "returns 0/nil if the specified window is a desktop (has REALLY no parent)" do
|
465
|
-
desktop = get_ancestor(@app.handle, GA_PARENT)
|
466
|
-
GetAncestor(desktop, GA_PARENT).should == 0
|
467
|
-
get_ancestor(desktop, GA_PARENT).should == nil
|
468
|
-
end
|
469
|
-
end # context GA_PARENT
|
470
|
-
|
471
|
-
context 'GA_ROOT - Retrieves the root window by walking the chain of parent windows' do
|
472
|
-
it "retrieves a handle to the specified window's root (top level parent)" do
|
473
|
-
child = find_window_ex(@app.handle, 0, nil, nil)
|
474
|
-
root1 = GetAncestor(child, GA_ROOT)
|
475
|
-
root2 = get_ancestor(child, GA_ROOT)
|
476
|
-
root1.should == root2
|
477
|
-
root1.should == @app.handle
|
478
|
-
end
|
479
|
-
end
|
480
|
-
# GA_ROOTOWNER - Retrieves the owned root window by walking the chain of parent and owner windows
|
481
|
-
# returned by GetParent.
|
482
|
-
end # describe get_ancestor
|
483
|
-
|
484
|
-
describe "#get_window" do
|
485
|
-
spec{ use{ handle = GetWindow(any_handle, command=0) }}
|
486
|
-
spec{ use{ handle = get_window(any_handle, command=0) }}
|
487
|
-
|
488
|
-
# GW_ENABLEDPOPUP - Windows 2000/XP: The retrieved handle identifies the enabled popup window owned by
|
489
|
-
|
490
|
-
context 'GW_HWND... works with windows of the same type' do
|
491
|
-
before(:all) do
|
492
|
-
@statusbar = find_window_ex(@app.handle, 0, STATUSBAR_CLASS, nil)
|
493
|
-
@textarea = find_window_ex(@app.handle, 0, TEXTAREA_CLASS, nil)
|
494
|
-
end
|
495
|
-
|
496
|
-
it 'GW_HWNDFIRST - The retrieved handle identifies the window of the same type that is highest in Z order' do
|
497
|
-
get_window(@statusbar, GW_HWNDFIRST).should == @statusbar
|
498
|
-
end
|
499
|
-
it 'GW_HWNDLAST - The retrieved handle identifies the window of the same type that is lowest in the Z order' do
|
500
|
-
get_window(@statusbar, GW_HWNDLAST).should == @textarea
|
501
|
-
end
|
502
|
-
it 'GW_HWNDNEXT - The retrieved handle identifies the window below the specified window in the Z order' do
|
503
|
-
get_window(@statusbar, GW_HWNDNEXT).should == @textarea
|
504
|
-
end
|
505
|
-
it 'GW_HWNDPREV - The retrieved handle identifies the window above the specified window in the Z order' do
|
506
|
-
get_window(@textarea, GW_HWNDPREV).should == @statusbar
|
507
|
-
end
|
508
|
-
|
509
|
-
it 'returns nil/0 in case nothing is returned' do
|
510
|
-
get_window(@textarea, GW_HWNDNEXT).should == nil
|
511
|
-
GetWindow(@textarea, GW_HWNDNEXT).should == 0
|
512
|
-
end
|
513
|
-
end # context 'GW_HWND...
|
514
|
-
|
515
|
-
context "GW_CHILD retrieves a window handle to a first (top of the Z order) child of given window" do
|
516
|
-
before(:all) do
|
517
|
-
# GW_CHILD - The retrieved handle identifies the child window at the top of the Z order, if the specified
|
518
|
-
@child1 = GetWindow(@app.handle, GW_CHILD)
|
519
|
-
@child2 = get_window(@app.handle, GW_CHILD)
|
520
|
-
end
|
521
|
-
|
522
|
-
it 'returns active window handle' do
|
523
|
-
window?(@child1).should == true
|
524
|
-
end
|
525
|
-
it 'returns the same value for original and snake case API' do
|
526
|
-
@child1.should == @child2
|
527
|
-
end
|
528
|
-
it 'returns first direct child of a given window' do
|
529
|
-
@child1.should == find_window_ex(@app.handle, 0, nil, nil)
|
530
|
-
end
|
531
|
-
it 'returns nil/0 if no children for a given window' do
|
532
|
-
GetWindow(@child1, GW_CHILD).should == 0
|
533
|
-
get_window(@child1, GW_CHILD).should == nil
|
534
|
-
end
|
535
|
-
end # context GW_CHILD
|
536
|
-
|
537
|
-
context "GW_OWNER - retrieves a handle to an owner of a given Window" do
|
538
|
-
# Ownership is a relationship between two top level windows while Parent is a relationship between a top
|
539
|
-
# level and a WS_CHILD, or a WS_CHILD and another WS_CHILD. The parent of a button is the form it is on,
|
540
|
-
# while a message box is owned by the form that showed it.
|
541
|
-
|
542
|
-
it 'returns owner (but NOT parent!) of a given window' do
|
543
|
-
pending 'Need to open modal dialog, app should be it`s owner'
|
544
|
-
child = find_window_ex(@app.handle, 0, nil, nil)
|
545
|
-
p owner1 = GetWindow(child, GW_OWNER)
|
546
|
-
p owner2 = get_window(child, GW_OWNER)
|
547
|
-
owner1.should == owner2
|
548
|
-
owner1.should == @app.handle
|
549
|
-
end
|
550
|
-
|
551
|
-
it 'returns nil/0 if no owner for a given window' do
|
552
|
-
GetWindow(@app.handle, GW_OWNER).should == 0
|
553
|
-
get_window(@app.handle, GW_OWNER).should == nil
|
554
|
-
end
|
555
|
-
end
|
556
|
-
end # describe get_window
|
557
|
-
|
558
|
-
describe '#enum_windows' do
|
559
|
-
|
560
|
-
spec{ use{ handles = enum_windows(value = 13) }}
|
561
|
-
|
562
|
-
it 'iterates through all the top-level windows, passing each top level window handle and value to a given block' do
|
563
|
-
enum_windows(13) do |handle, message|
|
564
|
-
handle.should be_an Integer
|
565
|
-
handle.should be > 0
|
566
|
-
message.should == 13
|
567
|
-
end
|
568
|
-
end
|
569
|
-
|
570
|
-
it 'returns an array of top-level window handles if block is not given' do
|
571
|
-
enum = enum_windows(13)
|
572
|
-
enum.should be_a_kind_of Array
|
573
|
-
enum.should_not be_empty
|
574
|
-
enum.should have_at_least(5).elements # typical number of top windows in WinXP system?
|
575
|
-
enum.each do |handle|
|
576
|
-
handle.should be_an Integer
|
577
|
-
handle.should be > 0
|
578
|
-
end
|
579
|
-
enum.any?{|handle| handle == @app.handle}.should == true
|
580
|
-
end
|
581
|
-
|
582
|
-
it 'returned array that contains handle of launched test app' do
|
583
|
-
enum = enum_windows(13)
|
584
|
-
enum.any?{|handle| handle == @app.handle}.should == true
|
585
|
-
end
|
586
|
-
|
587
|
-
it 'defaults message to 0 if it is omitted from method call' do
|
588
|
-
enum_windows do |handle, message|
|
589
|
-
message.should == 0
|
590
|
-
end
|
591
|
-
end
|
592
|
-
end
|
593
|
-
|
594
|
-
describe '#enum_desktop_windows' do
|
595
|
-
spec{ use{ handles = enum_desktop_windows(0, value = 13) }}
|
596
|
-
spec{ use{ enum_desktop_windows(0) {|handle, message|} }}
|
597
|
-
|
598
|
-
it 'iterates through all the top-level windows for a given desktop'
|
599
|
-
end
|
600
|
-
|
601
|
-
describe '#enum_child_windows' do
|
602
|
-
spec{ use{ enum_child_windows(parent = any_handle, value = 13) }}
|
603
|
-
|
604
|
-
it 'return an array of child window handles if block is not given' do
|
605
|
-
enum = enum_child_windows(@app.handle, 13)
|
606
|
-
enum.should be_a_kind_of Array
|
607
|
-
enum.should have(2).elements
|
608
|
-
class_name(enum.first).should == STATUSBAR_CLASS
|
609
|
-
class_name(enum.last).should == TEXTAREA_CLASS
|
610
|
-
end
|
603
|
+
describe '#enum_child_windows' do
|
604
|
+
spec { use { enum_child_windows(parent = any_handle, value = 13) } }
|
605
|
+
|
606
|
+
it 'return an array of child window handles if block is not given' do
|
607
|
+
enum = enum_child_windows(@app.handle, 13)
|
608
|
+
enum.should be_a_kind_of Array
|
609
|
+
enum.should have(2).elements
|
610
|
+
class_name(enum.first).should == STATUSBAR_CLASS
|
611
|
+
class_name(enum.last).should == TEXTAREA_CLASS
|
612
|
+
end
|
611
613
|
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
end
|
618
|
-
enum.should have(2).elements
|
619
|
-
class_name(enum.first).should == STATUSBAR_CLASS
|
620
|
-
class_name(enum.last).should == TEXTAREA_CLASS
|
614
|
+
it 'loops through all children of given window, passing each found window handle and a message to a given block' do
|
615
|
+
enum = []
|
616
|
+
enum_child_windows(@app.handle, 13) do |handle, message|
|
617
|
+
enum << handle
|
618
|
+
message.should == 13
|
621
619
|
end
|
620
|
+
enum.should have(2).elements
|
621
|
+
class_name(enum.first).should == STATUSBAR_CLASS
|
622
|
+
class_name(enum.last).should == TEXTAREA_CLASS
|
623
|
+
end
|
622
624
|
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
end
|
629
|
-
enum.should have(1).element
|
630
|
-
class_name(enum.first).should == STATUSBAR_CLASS
|
625
|
+
it 'breaks loop if given block returns false' do
|
626
|
+
enum = []
|
627
|
+
enum_child_windows(@app.handle) do |handle, message|
|
628
|
+
enum << handle
|
629
|
+
false
|
631
630
|
end
|
631
|
+
enum.should have(1).element
|
632
|
+
class_name(enum.first).should == STATUSBAR_CLASS
|
633
|
+
end
|
632
634
|
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
end
|
635
|
+
it 'defaults message to 0 if it is omitted from method call' do
|
636
|
+
enum_child_windows(@app.handle) do |handle, message|
|
637
|
+
message.should == 0
|
637
638
|
end
|
638
639
|
end
|
640
|
+
end
|
639
641
|
|
640
|
-
|
641
|
-
|
642
|
+
end # context 'with single test app'
|
643
|
+
end # Win::Gui::Window, ' defines a set user32 API functions related to Window manipulation'
|
642
644
|
|
643
|
-
|
644
|
-
|
645
|
+
describe Win::Gui::Window, ' defines convenience/service methods on top of Windows API' do
|
646
|
+
after(:each) { close_test_app if @launched_test_app }
|
645
647
|
|
646
|
-
|
647
|
-
|
648
|
+
describe '#foreground?' do
|
649
|
+
spec { use { foreground?(any_handle) } }
|
648
650
|
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
end
|
651
|
+
it 'tests if the given window is foreground' do
|
652
|
+
foreground?(foreground_window).should == true
|
653
|
+
foreground?(any_handle).should == false
|
653
654
|
end
|
655
|
+
end
|
654
656
|
|
655
|
-
|
656
|
-
|
657
|
+
describe '#hide_window' do
|
658
|
+
spec { use { was_visible = hide_window(any_handle) } }
|
657
659
|
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
end
|
660
|
+
it 'hides window: same as show_window(handle, SW_HIDE)' do
|
661
|
+
test_app do |app|
|
662
|
+
was_visible = hide_window(app.handle)
|
663
|
+
was_visible.should == true #!
|
664
|
+
visible?(app.handle).should == false
|
665
|
+
hide_window(app.handle).should == false
|
666
|
+
visible?(app.handle).should == false
|
666
667
|
end
|
667
668
|
end
|
669
|
+
end
|
668
670
|
|
669
|
-
|
670
|
-
|
671
|
+
describe '#shut_window' do
|
672
|
+
spec { use { success = shut_window(handle=0) } }
|
671
673
|
|
672
|
-
|
673
|
-
|
674
|
+
it 'destroys window in another thread by sending WM_SYSCOMMAND, SC_CLOSE message to it' do
|
675
|
+
app = launch_test_app
|
674
676
|
|
675
|
-
|
676
|
-
|
677
|
+
shut_window(app.handle).should == true
|
678
|
+
sleep SLEEP_DELAY
|
677
679
|
|
678
|
-
|
679
|
-
end
|
680
|
+
window?(app.handle).should == false
|
680
681
|
end
|
682
|
+
end
|
681
683
|
|
682
|
-
|
683
|
-
|
684
|
+
describe '#text' do
|
685
|
+
spec { use { text = text(any_handle, buffer_size=1024) } }
|
684
686
|
|
685
|
-
|
686
|
-
|
687
|
+
it 'returns text associated with window by sending WM_GETTEXT message to it' do
|
688
|
+
test_app do |app|
|
687
689
|
|
688
|
-
|
689
|
-
|
690
|
-
end
|
690
|
+
text(app.handle).should == WIN_TITLE
|
691
|
+
text(app.textarea).should =~ /Welcome to Steganos LockNote/
|
691
692
|
end
|
692
|
-
end
|
693
|
-
end #
|
694
|
-
end
|
693
|
+
end
|
694
|
+
end # describe '#text'
|
695
|
+
end # Win::Gui::Window, ' defines convenience/service methods on top of Windows API'
|