win 0.3.24 → 0.3.25
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,269 +1,268 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'win/gui/input'
|
3
3
|
require 'win/error'
|
4
4
|
|
5
|
-
|
5
|
+
include WinTestApp
|
6
|
+
include Win::Gui::Message
|
7
|
+
include Win::Gui::Window
|
8
|
+
include Win::Gui::Input
|
9
|
+
include Win::Error
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
include Win::Gui::Input
|
11
|
-
include Win::Error
|
12
|
-
|
13
|
-
def buffer
|
14
|
-
@buffer ||= FFI::MemoryPointer.new :char, 1024
|
15
|
-
end
|
11
|
+
def buffer
|
12
|
+
@buffer ||= FFI::MemoryPointer.new :char, 1024
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def msg
|
16
|
+
@msg ||= Win::Gui::Message::Msg.new
|
17
|
+
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def msg_callback
|
20
|
+
lambda { |handle, message, data, result| @handle = handle; @message = message; @data = data; @result = result }
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
23
|
+
def should_have msg, members
|
24
|
+
members.each do |member, value|
|
25
|
+
case member
|
26
|
+
when :l_param
|
27
|
+
msg[member].address.should == value
|
28
|
+
when :time
|
29
|
+
msg[member].should be > value
|
30
|
+
else
|
31
|
+
msg[member].should == value
|
35
32
|
end
|
36
33
|
end
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def clear_thread_queue
|
37
|
+
get_message while peek_message
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
describe '#post_message' do
|
46
|
-
before(:each){clear_thread_queue}
|
47
|
-
after(:all){close_test_app if @launched_test_app}
|
48
|
-
|
49
|
-
spec{ use{ success = PostMessage(handle = 0, msg = 0, w_param = 0, l_param = nil) }}
|
50
|
-
spec{ use{ success = post_message(handle = 0, msg = 0, w_param = 0, l_param = nil) }}
|
51
|
-
|
52
|
-
context 'places (posts) a message in the message queue associated with the thread that created the specified window' do
|
53
|
-
it 'with nil as last argument(lParam)' do
|
54
|
-
app = launch_test_app
|
55
|
-
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, nil).should == true
|
56
|
-
sleep SLEEP_DELAY
|
57
|
-
window?(app.handle).should == false
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'with pointer as last argument(lParam)' do
|
61
|
-
app = launch_test_app
|
62
|
-
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, FFI::MemoryPointer.new(:long)).should == true
|
63
|
-
sleep SLEEP_DELAY
|
64
|
-
window?(app.handle).should == false
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'with Fixnum as last argument(lParam)' do
|
68
|
-
app = launch_test_app
|
69
|
-
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, 0).should == true
|
70
|
-
sleep SLEEP_DELAY
|
71
|
-
window?(app.handle).should == false
|
72
|
-
end
|
73
|
-
end
|
40
|
+
describe Win::Gui::Message, ' defines a set of API functions related to Window messaging' do
|
41
|
+
before(:all) { clear_thread_queue }
|
74
42
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
43
|
+
describe '#post_message' do
|
44
|
+
before(:each) { clear_thread_queue }
|
45
|
+
after(:all) { close_test_app if @launched_test_app }
|
46
|
+
|
47
|
+
spec { use { success = PostMessage(handle = 0, msg = 0, w_param = 0, l_param = nil) } }
|
48
|
+
spec { use { success = post_message(handle = 0, msg = 0, w_param = 0, l_param = nil) } }
|
49
|
+
|
50
|
+
context 'places (posts) a message in the message queue associated with the thread that created the specified window' do
|
51
|
+
it 'with nil as last argument(lParam)' do
|
52
|
+
app = launch_test_app
|
53
|
+
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, nil).should == true
|
54
|
+
sleep SLEEP_DELAY
|
55
|
+
window?(app.handle).should == false
|
79
56
|
end
|
80
57
|
|
81
|
-
it '
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
after(:all){close_test_app if @launched_test_app}
|
87
|
-
|
88
|
-
spec{ use{ success = SendMessage(handle = 0, msg = 0, w_param = 0, l_param = nil) }}
|
89
|
-
spec{ use{ success = send_message(handle = 0, msg = 0, w_param = 0, l_param = nil) }}
|
90
|
-
|
91
|
-
context 'sends a message to the specified window' do
|
92
|
-
it 'with nil as last argument(lParam)' do
|
93
|
-
app = launch_test_app
|
94
|
-
send_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, nil)
|
95
|
-
sleep SLEEP_DELAY
|
96
|
-
window?(app.handle).should == false
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'with pointer as last argument(lParam)' do
|
100
|
-
app = launch_test_app
|
101
|
-
send_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, FFI::MemoryPointer.new(:long))
|
102
|
-
sleep SLEEP_DELAY
|
103
|
-
window?(app.handle).should == false
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'with Fixnum as last argument(lParam)' do
|
107
|
-
app = launch_test_app
|
108
|
-
send_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, 0)
|
109
|
-
sleep SLEEP_DELAY
|
110
|
-
window?(app.handle).should == false
|
111
|
-
end
|
58
|
+
it 'with pointer as last argument(lParam)' do
|
59
|
+
app = launch_test_app
|
60
|
+
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, FFI::MemoryPointer.new(:long)).should == true
|
61
|
+
sleep SLEEP_DELAY
|
62
|
+
window?(app.handle).should == false
|
112
63
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
spec{ use{ success = SendMessageCallback(h_wnd=0, msg=0, w_param=0, l_param=nil, msg_callback, data=0) }}
|
120
|
-
spec{ use{ success = send_message_callback(h_wnd=0, msg=0, w_param=0, l_param=nil, data=0, &msg_callback) }}
|
121
|
-
|
122
|
-
it "sends message to window and returns, specifying callback to be called by system after message is processed" do
|
123
|
-
sent = SendMessageCallback(@app.handle, WM_USER, 0, nil, msg_callback, data=13)
|
124
|
-
sent.should == 1
|
125
|
-
@handle.should == nil # Callback did not fire just yet
|
126
|
-
@message.should == nil
|
127
|
-
@data.should == nil
|
128
|
-
@result.should == nil
|
129
|
-
|
130
|
-
sleep SLEEP_DELAY # Small delay to allow message delivery
|
131
|
-
peek_message # Dispatching sent message (even though there is nothing in queue)
|
132
|
-
|
133
|
-
@handle.should == @app.handle
|
134
|
-
@message.should == WM_USER
|
135
|
-
@data.should == 13
|
136
|
-
@result.should == 0
|
64
|
+
|
65
|
+
it 'with Fixnum as last argument(lParam)' do
|
66
|
+
app = launch_test_app
|
67
|
+
post_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, 0).should == true
|
68
|
+
sleep SLEEP_DELAY
|
69
|
+
window?(app.handle).should == false
|
137
70
|
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'places (posts) a message into current thread`s queue if first arg is 0' do
|
74
|
+
post_message(0, WM_USER, 33, nil).should == true
|
75
|
+
msg = get_message()
|
76
|
+
should_have msg, hwnd: 0, message: WM_USER, w_param: 33, l_param: 0
|
77
|
+
end
|
138
78
|
|
139
|
-
|
140
|
-
sent = send_message_callback(@app.handle, WM_USER, 0, nil){|*args| @data=args[2]}
|
141
|
-
sent.should == true
|
142
|
-
@data.should == nil # Callback did not fire just yet
|
79
|
+
it 'returns without waiting for the thread to process the message'
|
143
80
|
|
144
|
-
|
145
|
-
peek_message # Dispatching sent message (even though there is nothing in queue)
|
81
|
+
end # describe '#post_message'
|
146
82
|
|
147
|
-
|
148
|
-
|
83
|
+
describe '#send_message' do
|
84
|
+
after(:all) { close_test_app if @launched_test_app }
|
149
85
|
|
150
|
-
|
151
|
-
|
152
|
-
|
86
|
+
spec { use { success = SendMessage(handle = 0, msg = 0, w_param = 0, l_param = nil) } }
|
87
|
+
spec { use { success = send_message(handle = 0, msg = 0, w_param = 0, l_param = nil) } }
|
88
|
+
|
89
|
+
context 'sends a message to the specified window' do
|
90
|
+
it 'with nil as last argument(lParam)' do
|
91
|
+
app = launch_test_app
|
92
|
+
send_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, nil)
|
93
|
+
sleep SLEEP_DELAY
|
94
|
+
window?(app.handle).should == false
|
153
95
|
end
|
154
96
|
|
155
|
-
it
|
156
|
-
|
157
|
-
|
97
|
+
it 'with pointer as last argument(lParam)' do
|
98
|
+
app = launch_test_app
|
99
|
+
send_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, FFI::MemoryPointer.new(:long))
|
100
|
+
sleep SLEEP_DELAY
|
101
|
+
window?(app.handle).should == false
|
158
102
|
end
|
159
103
|
|
160
|
-
it
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
get_last_error.should == "Invalid window handle."
|
104
|
+
it 'with Fixnum as last argument(lParam)' do
|
105
|
+
app = launch_test_app
|
106
|
+
send_message(app.handle, WM_SYSCOMMAND, SC_CLOSE, 0)
|
107
|
+
sleep SLEEP_DELAY
|
108
|
+
window?(app.handle).should == false
|
166
109
|
end
|
167
|
-
end
|
110
|
+
end
|
111
|
+
end # describe '#send_message'
|
112
|
+
|
113
|
+
describe "#send_message_callback" do
|
114
|
+
before(:all) { @app=launch_test_app }
|
115
|
+
after(:all) { close_test_app if @launched_test_app }
|
116
|
+
|
117
|
+
spec { use { success = SendMessageCallback(h_wnd=0, msg=0, w_param=0, l_param=nil, msg_callback, data=0) } }
|
118
|
+
spec { use { success = send_message_callback(h_wnd=0, msg=0, w_param=0, l_param=nil, data=0, &msg_callback) } }
|
119
|
+
|
120
|
+
it "sends message to window and returns, specifying callback to be called by system after message is processed" do
|
121
|
+
sent = SendMessageCallback(@app.handle, WM_USER, 0, nil, msg_callback, data=13)
|
122
|
+
sent.should == 1
|
123
|
+
@handle.should == nil # Callback did not fire just yet
|
124
|
+
@message.should == nil
|
125
|
+
@data.should == nil
|
126
|
+
@result.should == nil
|
127
|
+
|
128
|
+
sleep SLEEP_DELAY # Small delay to allow message delivery
|
129
|
+
peek_message # Dispatching sent message (even though there is nothing in queue)
|
130
|
+
|
131
|
+
@handle.should == @app.handle
|
132
|
+
@message.should == WM_USER
|
133
|
+
@data.should == 13
|
134
|
+
@result.should == 0
|
135
|
+
end
|
168
136
|
|
169
|
-
|
170
|
-
|
137
|
+
it "snake_case api defaults data to 0, converts block into callback and returns true/false" do
|
138
|
+
sent = send_message_callback(@app.handle, WM_USER, 0, nil) { |*args| @data=args[2] }
|
139
|
+
sent.should == true
|
140
|
+
@data.should == nil # Callback did not fire just yet
|
171
141
|
|
172
|
-
|
173
|
-
|
142
|
+
sleep SLEEP_DELAY # Small delay to allow message delivery
|
143
|
+
peek_message # Dispatching sent message (even though there is nothing in queue)
|
174
144
|
|
175
|
-
|
176
|
-
|
177
|
-
post_message(0, WM_USER+1, 33, nil)
|
178
|
-
res = GetMessage(msg, handle=0, msg_filter_min=0, msg_filter_max=0)
|
179
|
-
res.should == 1
|
180
|
-
# p msg[:hwnd], msg[:message], msg[:w_param], msg[:l_param], msg[:time], msg[:x], msg[:y]
|
181
|
-
should_have msg, hwnd: 0, message: WM_USER+1, w_param: 33, x: 0, y: 0, l_param: 0, time: 1000000
|
182
|
-
end
|
145
|
+
@data.should == 0
|
146
|
+
end
|
183
147
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
148
|
+
it "can be used with :pointer as a 4th arg" do
|
149
|
+
sent = send_message_callback(@app.handle, WM_USER, 0, FFI::MemoryPointer.new(:long)) { |*args|}
|
150
|
+
sent.should == true
|
151
|
+
end
|
188
152
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
153
|
+
it "can be used with :long as a 4th arg" do
|
154
|
+
sent = send_message_callback(@app.handle, WM_USER, 0, 0) { |*args|}
|
155
|
+
sent.should == true
|
156
|
+
end
|
194
157
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
158
|
+
it "fails if unable to send message" do
|
159
|
+
sent = SendMessageCallback(not_a_handle, WM_USER, 0, nil, msg_callback, 0)
|
160
|
+
sent.should == 0
|
161
|
+
send_message_callback(not_a_handle, WM_USER, 0, nil) { |*args| @data=args[2] }
|
162
|
+
sent.should == 0
|
163
|
+
get_last_error.should == "Invalid window handle."
|
164
|
+
end
|
165
|
+
end # describe send_message_callback
|
201
166
|
|
202
|
-
|
203
|
-
|
204
|
-
end
|
167
|
+
describe "#get_message" do
|
168
|
+
before(:all) { clear_thread_queue; 2.times { post_message 0, 0, 0, nil } }
|
205
169
|
|
206
|
-
|
207
|
-
|
208
|
-
get_message.should == false
|
209
|
-
end
|
210
|
-
end # describe get_message
|
170
|
+
spec { use { res = GetMessage(msg, handle=0, msg_filter_min=0, msg_filter_max=0) } }
|
171
|
+
spec { use { message = get_message(msg, handle=0, msg_filter_min=0, msg_filter_max=0) } }
|
211
172
|
|
173
|
+
it "original api retrieves a message from the calling thread's message queue" do
|
174
|
+
set_cursor_pos(x=0, y=0)
|
175
|
+
post_message(0, WM_USER+1, 33, nil)
|
176
|
+
res = GetMessage(msg, handle=0, msg_filter_min=0, msg_filter_max=0)
|
177
|
+
res.should == 1
|
178
|
+
# p msg[:hwnd], msg[:message], msg[:w_param], msg[:l_param], msg[:time], msg[:x], msg[:y]
|
179
|
+
should_have msg, hwnd: 0, message: WM_USER+1, w_param: 33, x: 0, y: 0, l_param: 0, time: 1000000
|
180
|
+
end
|
212
181
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
182
|
+
it "original api returns -1 if there is an error (wrong handle, in this case)" do
|
183
|
+
res = GetMessage(msg, not_a_handle, msg_filter_min=0, msg_filter_max=0)
|
184
|
+
res.should == -1
|
185
|
+
end
|
217
186
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
187
|
+
it "original api returns 0 if WM_QUIT was posted to thread`s message queue" do
|
188
|
+
post_message(0, WM_QUIT, 13, nil)
|
189
|
+
res = GetMessage(msg, 0, msg_filter_min=0, msg_filter_max=0)
|
190
|
+
res.should == 0
|
191
|
+
end
|
192
|
+
|
193
|
+
it "snake_case api returns a message struct retrieved from the calling thread's message queue " do
|
194
|
+
set_cursor_pos(x=99, y=99)
|
195
|
+
post_message(0, WM_USER+2, 33, nil)
|
196
|
+
msg = get_message()
|
197
|
+
should_have msg, hwnd: 0, message: WM_USER+2, w_param: 33, x: 99, y: 99, l_param: 0, time: 1000000
|
198
|
+
end
|
199
|
+
|
200
|
+
it "snake_case api returns nil if there is an error (wrong handle, in this case)" do
|
201
|
+
get_message(msg, not_a_handle).should == nil
|
202
|
+
end
|
203
|
+
|
204
|
+
it "snake_case api returns false if WM_QUIT was posted to thread`s message queue" do
|
205
|
+
post_message(0, WM_QUIT, 13, nil)
|
206
|
+
get_message.should == false
|
207
|
+
end
|
208
|
+
end # describe get_message
|
225
209
|
|
226
|
-
it "snake_case api checks the thread message queue for a posted message, returns it without removing" do
|
227
|
-
10.times do
|
228
|
-
msg = peek_message()
|
229
|
-
should_have msg, hwnd: 0, message: WM_USER+2, w_param: 13, x: 0, y: 0, l_param: 0, time: 1000000
|
230
|
-
end
|
231
|
-
end
|
232
210
|
|
233
|
-
|
234
|
-
|
235
|
-
|
211
|
+
describe "#peek_message" do
|
212
|
+
before(:all) { set_cursor_pos(x=0, y=0); post_message(0, WM_USER+2, 13, nil) }
|
213
|
+
spec { use { success = PeekMessage(msg, h_wnd=0, filter_min=0, filter_max=0, remove_msg=0) } }
|
214
|
+
spec { use { success = peek_message(msg, h_wnd=0, filter_min=0, filter_max=0, remove_msg=0) } }
|
215
|
+
|
216
|
+
it "original api checks the thread message queue for a posted message, retrieves it without removing" do
|
217
|
+
10.times do
|
218
|
+
res = PeekMessage(msg, h_wnd=0, filter_min=0, filter_max=0, remove_msg=0)
|
219
|
+
res.should == 1
|
220
|
+
should_have msg, hwnd: 0, message: WM_USER+2, w_param: 13, x: 0, y: 0, l_param: 0, time: 1000000
|
236
221
|
end
|
222
|
+
end
|
237
223
|
|
238
|
-
|
239
|
-
|
224
|
+
it "snake_case api checks the thread message queue for a posted message, returns it without removing" do
|
225
|
+
10.times do
|
226
|
+
msg = peek_message()
|
227
|
+
should_have msg, hwnd: 0, message: WM_USER+2, w_param: 13, x: 0, y: 0, l_param: 0, time: 1000000
|
240
228
|
end
|
241
|
-
end
|
229
|
+
end
|
242
230
|
|
243
|
-
|
244
|
-
|
245
|
-
|
231
|
+
it "original api returns 0 if no message in queue" do
|
232
|
+
get_message
|
233
|
+
PeekMessage(msg, h_wnd=0, filter_min=0, filter_max=0, remove_msg=0).should == 0
|
234
|
+
end
|
246
235
|
|
247
|
-
|
236
|
+
it "snake_case api returns nil if no message in queue" do
|
237
|
+
peek_message.should == nil
|
238
|
+
end
|
239
|
+
end # describe peek_message
|
248
240
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
end
|
253
|
-
end # describe translate_message
|
241
|
+
describe "#translate_message" do
|
242
|
+
spec { use { success = TranslateMessage(msg) } }
|
243
|
+
spec { use { success = translate_message(msg) } }
|
254
244
|
|
255
|
-
|
256
|
-
|
257
|
-
|
245
|
+
it "translates virtual-key message into character message which is then posted to the thread's message queue" do
|
246
|
+
pending
|
247
|
+
end
|
258
248
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
249
|
+
it "returns zero/false if no translation took place" do
|
250
|
+
TranslateMessage(msg).should == 0
|
251
|
+
translate_message(msg).should == false
|
252
|
+
end
|
253
|
+
end # describe translate_message
|
263
254
|
|
264
|
-
|
255
|
+
describe "#dispatch_message" do
|
256
|
+
spec { use { res = DispatchMessage(msg) } } #return value is normally ignored
|
257
|
+
spec { use { res = dispatch_message(msg) } } #return value is normally ignored
|
265
258
|
|
266
|
-
|
267
|
-
|
259
|
+
it "dispatches a message to a window procedure. Typically used to dispatch a message retrieved by GetMessage" do
|
260
|
+
pending
|
261
|
+
res = DispatchMessage(msg)
|
262
|
+
end
|
263
|
+
|
264
|
+
end # describe dispatch_message
|
265
|
+
|
266
|
+
end # Win::Gui::Message, ' defines a set of API functions related to Window messaging'
|
268
267
|
|
269
268
|
|