win 0.1.27 → 0.3.1

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.
@@ -1,112 +1,112 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'win/error'
3
- require 'win/gui/window'
4
-
5
- module WinErrorTest
6
- include WinTest
7
- include Win::Error
8
- include Win::GUI::Window
9
-
10
- def buffer
11
- FFI::MemoryPointer.new(:char, 260)
12
- end
13
-
14
- def sys_flags
15
- FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
16
- end
17
-
18
- describe Win::Error, ' contains a set of pre-defined Windows API functions' do
19
- describe "#get_last_error" do
20
- spec{ use{ err_code = GetLastError() }}
21
- spec{ use{ err_message = get_last_error() }}
22
-
23
- it "original api retrieves the calling thread's last-error code value" do
24
- find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
25
- GetLastError().should == ERROR_FILE_NOT_FOUND
26
- window_text(0)
27
- GetLastError().should == ERROR_INVALID_WINDOW_HANDLE
28
- end
29
-
30
- it "enhanced api retrieves the message corresponding to last error code" do
31
- find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
32
- get_last_error.should == "The system cannot find the file specified."
33
- window_text(0)
34
- get_last_error.should == "Invalid window handle."
35
- end
36
- end # describe "#get_last_error"
37
-
38
- describe "#format_message" do
39
- spec{ use{ num_chars = FormatMessage(sys_flags, source=nil, message_id=0, language_id=0, buffer, buffer.size, :int, 0) }}
40
- spec{ use{ message = format_message(sys_flags, source=nil, message_id=0, language_id=0, :int, 0) }}
41
-
42
- it "original api formats a message string - system message" do
43
- find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
44
- message_id = GetLastError()
45
- buf = buffer()
46
- num_chars = FormatMessage(sys_flags, nil, message_id, dw_language_id=0, buf, buf.size, :int, 0)
47
- buf.get_bytes(0, num_chars).strip.should == "The system cannot find the file specified."
48
- end
49
-
50
- it "snake_case api Formats a message string - system message" do
51
- find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
52
- message = format_message(sys_flags, nil, dw_message_id=GetLastError())
53
- message.should == "The system cannot find the file specified."
54
- end
55
- end # describe format_message
56
-
57
- describe "#set_last_error" do
58
- spec{ use{ SetLastError(err_code=0) }}
59
- spec{ use{ set_last_error(err_code=0) }}
60
-
61
- it "original api sets the last-error code for the calling thread." do
62
- SetLastError(dw_err_code=0xF000)
63
- GetLastError().should == ERROR_USER_DEFINED_BASE
64
- end
65
-
66
- it "snake_case api also sets the last-error code for the calling thread." do
67
- set_last_error(3000)
68
- get_last_error.should == "The specified print monitor is unknown."
69
- end
70
- end # describe set_last_error
71
-
72
- if xp? || vista? # This function works only on XP++
73
- describe "#set_last_error_ex" do
74
- spec{ use{ SetLastErrorEx(dw_err_code=0, dw_type=0) }}
75
- spec{ use{ set_last_error_ex(dw_err_code=0, dw_type=0) }}
76
-
77
- it "original api sets the last-error code for the calling thread." do
78
- SetLastErrorEx(dw_err_code=0xF000, dw_type=0)
79
- GetLastError().should == ERROR_USER_DEFINED_BASE
80
- end
81
-
82
- it "snake_case api also sets the last-error code for the calling thread." do
83
- set_last_error_ex(3000,0)
84
- get_last_error.should == "The specified print monitor is unknown."
85
- end
86
- end # describe set_last_error_ex
87
- end
88
-
89
- if vista? # This function works only on Vista++
90
- describe "#get_error_mode" do
91
- spec{ use{ mode = GetErrorMode() }}
92
- spec{ use{ mode = get_error_mode() }}
93
-
94
- it "original api retrieves the error mode for the current process." do
95
- p mode = GetErrorMode()
96
- end
97
-
98
- it "snake_case api also retrieves the error mode for the current process." do
99
- p mode = get_error_mode()
100
- end
101
- end # describe get_error_mode
102
- end
103
-
104
- describe "#set_error_mode" do
105
- spec{ use{ success = SetErrorMode(u_mode=0) }}
106
- spec{ use{ success = set_error_mode(u_mode=0) }}
107
-
108
- it "controls whether the system OR process will handle the specified types of serious errors"
109
- end # describe set_error_mode
110
-
111
- end # describe Win::Error
112
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'win/error'
3
+ require 'win/gui/window'
4
+
5
+ module WinErrorTest
6
+ include WinTest
7
+ include Win::Error
8
+ include Win::Gui::Window
9
+
10
+ def buffer
11
+ FFI::MemoryPointer.new(:char, 260)
12
+ end
13
+
14
+ def sys_flags
15
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
16
+ end
17
+
18
+ describe Win::Error, ' contains a set of pre-defined Windows API functions' do
19
+ describe "#get_last_error" do
20
+ spec{ use{ err_code = GetLastError() }}
21
+ spec{ use{ err_message = get_last_error() }}
22
+
23
+ it "original api retrieves the calling thread's last-error code value" do
24
+ find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
25
+ GetLastError().should == ERROR_FILE_NOT_FOUND
26
+ window_text(0)
27
+ GetLastError().should == ERROR_INVALID_WINDOW_HANDLE
28
+ end
29
+
30
+ it "enhanced api retrieves the message corresponding to last error code" do
31
+ find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
32
+ get_last_error.should == "The system cannot find the file specified."
33
+ window_text(0)
34
+ get_last_error.should == "Invalid window handle."
35
+ end
36
+ end # describe "#get_last_error"
37
+
38
+ describe "#format_message" do
39
+ spec{ use{ num_chars = FormatMessage(sys_flags, source=nil, message_id=0, language_id=0, buffer, buffer.size, :int, 0) }}
40
+ spec{ use{ message = format_message(sys_flags, source=nil, message_id=0, language_id=0, :int, 0) }}
41
+
42
+ it "original api formats a message string - system message" do
43
+ find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
44
+ message_id = GetLastError()
45
+ buf = buffer()
46
+ num_chars = FormatMessage(sys_flags, nil, message_id, dw_language_id=0, buf, buf.size, :int, 0)
47
+ buf.get_bytes(0, num_chars).strip.should == "The system cannot find the file specified."
48
+ end
49
+
50
+ it "snake_case api Formats a message string - system message" do
51
+ find_window(TEST_IMPOSSIBLE, TEST_IMPOSSIBLE)
52
+ message = format_message(sys_flags, nil, dw_message_id=GetLastError())
53
+ message.should == "The system cannot find the file specified."
54
+ end
55
+ end # describe format_message
56
+
57
+ describe "#set_last_error" do
58
+ spec{ use{ SetLastError(err_code=0) }}
59
+ spec{ use{ set_last_error(err_code=0) }}
60
+
61
+ it "original api sets the last-error code for the calling thread." do
62
+ SetLastError(dw_err_code=0xF000)
63
+ GetLastError().should == ERROR_USER_DEFINED_BASE
64
+ end
65
+
66
+ it "snake_case api also sets the last-error code for the calling thread." do
67
+ set_last_error(3000)
68
+ get_last_error.should == "The specified print monitor is unknown."
69
+ end
70
+ end # describe set_last_error
71
+
72
+ if xp? || vista? # This function works only on XP++
73
+ describe "#set_last_error_ex" do
74
+ spec{ use{ SetLastErrorEx(dw_err_code=0, dw_type=0) }}
75
+ spec{ use{ set_last_error_ex(dw_err_code=0, dw_type=0) }}
76
+
77
+ it "original api sets the last-error code for the calling thread." do
78
+ SetLastErrorEx(dw_err_code=0xF000, dw_type=0)
79
+ GetLastError().should == ERROR_USER_DEFINED_BASE
80
+ end
81
+
82
+ it "snake_case api also sets the last-error code for the calling thread." do
83
+ set_last_error_ex(3000,0)
84
+ get_last_error.should == "The specified print monitor is unknown."
85
+ end
86
+ end # describe set_last_error_ex
87
+ end
88
+
89
+ if vista? # This function works only on Vista++
90
+ describe "#get_error_mode" do
91
+ spec{ use{ mode = GetErrorMode() }}
92
+ spec{ use{ mode = get_error_mode() }}
93
+
94
+ it "original api retrieves the error mode for the current process." do
95
+ p mode = GetErrorMode()
96
+ end
97
+
98
+ it "snake_case api also retrieves the error mode for the current process." do
99
+ p mode = get_error_mode()
100
+ end
101
+ end # describe get_error_mode
102
+ end
103
+
104
+ describe "#set_error_mode" do
105
+ spec{ use{ success = SetErrorMode(u_mode=0) }}
106
+ spec{ use{ success = set_error_mode(u_mode=0) }}
107
+
108
+ it "controls whether the system OR process will handle the specified types of serious errors"
109
+ end # describe set_error_mode
110
+
111
+ end # describe Win::Error
112
+ end
@@ -1,73 +1,73 @@
1
- require File.join(File.dirname(__FILE__), ".." , "spec_helper" )
2
- require 'win/extensions'
3
-
4
- module WinTest
5
-
6
- describe String do
7
- context '#snake_case' do
8
- it 'transforms CamelCase strings' do
9
- 'GetCharWidth32'.snake_case.should == 'get_char_width_32'
10
- end
11
-
12
- it 'leaves snake_case strings intact' do
13
- 'keybd_event'.snake_case.should == 'keybd_event'
14
- end
15
- end
16
-
17
- context '#camel_case' do
18
- it 'transforms snake_case strings' do
19
- 'get_char_width_32'.camel_case.should == 'GetCharWidth32'
20
- end
21
-
22
- it 'leaves CamelCase strings intact' do
23
- 'GetCharWidth32'.camel_case.should == 'GetCharWidth32'
24
- end
25
- end
26
-
27
- context '#to_w' do
28
- it 'transcodes string to utf-16LE' do
29
- 'GetCharWidth32'.to_w.encoding.name.should == 'UTF-16LE'
30
- end
31
-
32
- it 'ensures that encoded string is null-terminated' do
33
- 'GetCharWidth32'.to_w.bytes.to_a[-2..-1].should == [0, 0]
34
- end
35
- end
36
-
37
- context '#to_vkeys' do
38
- it 'transforms number char into [equivalent key code]' do
39
- ('0'..'9').each {|char| char.to_vkeys.should == char.unpack('C')}
40
- end
41
-
42
- it 'transforms uppercase letters into [shift, equivalent key code]' do
43
- ('A'..'Z').each {|char| char.to_vkeys.should == [0x10, *char.unpack('C')]}
44
- # Win.const_get(:VK_SHIFT) = 0x10 Bad coupling
45
- end
46
-
47
- it 'transforms lowercase letters into [(upcase) key code]' do
48
- ('a'..'z').each {|char| char.to_vkeys.should == char.upcase.unpack('C')}
49
- end
50
-
51
- it 'transforms space into [equivalent key code]' do
52
- " ".to_vkeys.should == " ".unpack('C')
53
- end
54
-
55
- it 'raises error if char is not implemented punctuation' do
56
- ('!'..'/').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
57
- (':'..'@').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
58
- ('['..'`').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
59
- ('{'..'~').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
60
- end
61
-
62
- it 'raises error if char is non-printable or non-ascii' do
63
- lambda {1.chr.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
64
- lambda {230.chr.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
65
- end
66
-
67
- it 'raises error if string is multi-char' do
68
- lambda {'hello'.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
69
- lambda {'23'.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
70
- end
71
- end
72
- end
73
- end
1
+ require File.join(File.dirname(__FILE__), ".." , "spec_helper" )
2
+ require 'win/extensions'
3
+
4
+ module WinTest
5
+
6
+ describe String do
7
+ context '#snake_case' do
8
+ it 'transforms CamelCase strings' do
9
+ 'GetCharWidth32'.snake_case.should == 'get_char_width_32'
10
+ end
11
+
12
+ it 'leaves snake_case strings intact' do
13
+ 'keybd_event'.snake_case.should == 'keybd_event'
14
+ end
15
+ end
16
+
17
+ context '#camel_case' do
18
+ it 'transforms snake_case strings' do
19
+ 'get_char_width_32'.camel_case.should == 'GetCharWidth32'
20
+ end
21
+
22
+ it 'leaves CamelCase strings intact' do
23
+ 'GetCharWidth32'.camel_case.should == 'GetCharWidth32'
24
+ end
25
+ end
26
+
27
+ context '#to_w' do
28
+ it 'transcodes string to utf-16LE' do
29
+ 'GetCharWidth32'.to_w.encoding.name.should == 'UTF-16LE'
30
+ end
31
+
32
+ it 'ensures that encoded string is null-terminated' do
33
+ 'GetCharWidth32'.to_w.bytes.to_a[-2..-1].should == [0, 0]
34
+ end
35
+ end
36
+
37
+ context '#to_vkeys' do
38
+ it 'transforms number char into [equivalent key code]' do
39
+ ('0'..'9').each {|char| char.to_vkeys.should == char.unpack('C')}
40
+ end
41
+
42
+ it 'transforms uppercase letters into [shift, equivalent key code]' do
43
+ ('A'..'Z').each {|char| char.to_vkeys.should == [0x10, *char.unpack('C')]}
44
+ # Win.const_get(:VK_SHIFT) = 0x10 Bad coupling
45
+ end
46
+
47
+ it 'transforms lowercase letters into [(upcase) key code]' do
48
+ ('a'..'z').each {|char| char.to_vkeys.should == char.upcase.unpack('C')}
49
+ end
50
+
51
+ it 'transforms space into [equivalent key code]' do
52
+ " ".to_vkeys.should == " ".unpack('C')
53
+ end
54
+
55
+ it 'raises error if char is not implemented punctuation' do
56
+ ('!'..'/').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
57
+ (':'..'@').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
58
+ ('['..'`').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
59
+ ('{'..'~').each {|char| lambda {char.to_vkeys}.should raise_error TEST_CONVERSION_ERROR }
60
+ end
61
+
62
+ it 'raises error if char is non-printable or non-ascii' do
63
+ lambda {1.chr.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
64
+ lambda {230.chr.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
65
+ end
66
+
67
+ it 'raises error if string is multi-char' do
68
+ lambda {'hello'.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
69
+ lambda {'23'.to_vkeys}.should raise_error TEST_CONVERSION_ERROR
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,43 +1,43 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
- require 'win/gui/input'
3
- #require 'win/gui/window'
4
-
5
- module WinWindowTest
6
-
7
- include WinTestApp
8
- include Win::GUI::Dialog
9
-
10
- describe Win::GUI::Dialog do
11
-
12
- describe '#get_dlg_item' do
13
- spec{ use{ control_handle = get_dlg_item(handle = 0, item_id = 1) }}
14
-
15
- it 'returns handle to correctly specified control'
16
-
17
- end
18
-
19
- describe Win::GUI::Dialog, ' defines convenience/service methods on top of Windows API' do
20
- # describe 'dialog' do
21
- # spec{ use{ dialog( title ='Dialog Title', timeout_sec = 0.001, &any_block) }}
22
- #
23
- # it 'finds top-level dialog window by title' do
24
- # pending 'Some problems (?with timeouts?) leave window open ~half of the runs'
25
- # test_app do |app|
26
- # keystroke(VK_ALT, 'F'.ord, 'A'.ord)
27
- # @found = false
28
- # dialog('Save As', 0.5) do |dialog_window|
29
- # @found = true
30
- # keystroke(VK_ESCAPE)
31
- # dialog_window
32
- # end
33
- # @found.should == true
34
- # end
35
- # end
36
- #
37
- # it 'yields found dialog window to a given block'
38
- #
39
- # end
40
- end
41
- end
42
- end
43
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ require 'win/gui/input'
3
+ #require 'win/gui/window'
4
+
5
+ module WinWindowTest
6
+
7
+ include WinTestApp
8
+ include Win::Gui::Dialog
9
+
10
+ describe Win::Gui::Dialog do
11
+
12
+ describe '#get_dlg_item' do
13
+ spec{ use{ control_handle = get_dlg_item(handle = 0, item_id = 1) }}
14
+
15
+ it 'returns handle to correctly specified control'
16
+
17
+ end
18
+
19
+ describe Win::Gui::Dialog, ' defines convenience/service methods on top of Windows API' do
20
+ # describe 'dialog' do
21
+ # spec{ use{ dialog( title ='Dialog Title', timeout_sec = 0.001, &any_block) }}
22
+ #
23
+ # it 'finds top-level dialog window by title' do
24
+ # pending 'Some problems (?with timeouts?) leave window open ~half of the runs'
25
+ # test_app do |app|
26
+ # keystroke(VK_ALT, 'F'.ord, 'A'.ord)
27
+ # @found = false
28
+ # dialog('Save As', 0.5) do |dialog_window|
29
+ # @found = true
30
+ # keystroke(VK_ESCAPE)
31
+ # dialog_window
32
+ # end
33
+ # @found.should == true
34
+ # end
35
+ # end
36
+ #
37
+ # it 'yields found dialog window to a given block'
38
+ #
39
+ # end
40
+ end
41
+ end
42
+ end
43
+