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
@@ -1,47 +1,44 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'win/system/info'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
4
|
+
include WinTestApp
|
5
|
+
include Win::System::Info
|
6
|
+
|
7
|
+
describe Win::System::Info do
|
8
|
+
describe "#get_computer_name" do
|
9
|
+
spec { use { success = GetComputerName(buf = buffer, pointer.write_long(buf.size)) } }
|
10
|
+
spec { use { name = get_computer_name() } }
|
11
|
+
|
12
|
+
it "original api retrieves the NetBIOS name of the local computer " do
|
13
|
+
name_ptr = FFI::MemoryPointer.from_string(" " * 128)
|
14
|
+
size_ptr = FFI::MemoryPointer.new(:long).write_int(name_ptr.size)
|
15
|
+
success = GetComputerName(name_ptr, size_ptr)
|
16
|
+
success.should_not == 0
|
17
|
+
name_ptr.read_string.should == `hostname`.strip.upcase
|
18
|
+
end
|
19
|
+
|
20
|
+
it "snake api retrieves the NetBIOS name of the local computer" do
|
21
|
+
get_computer_name.strip.should == `hostname`.strip.upcase
|
22
|
+
end
|
23
|
+
end # describe get_computer_name
|
24
|
+
|
25
|
+
describe "#get_user_name" do
|
26
|
+
spec { use { success = GetUserName(buf = buffer, pointer.write_long(buf.size)) } }
|
27
|
+
spec { use { username = get_user_name() } }
|
28
|
+
|
29
|
+
it "original api to retrieve the user name in a specified format. Additional information " do
|
30
|
+
username = ENV['USERNAME'].strip
|
31
|
+
name_ptr = FFI::MemoryPointer.from_string(" " * 128)
|
32
|
+
size_ptr = FFI::MemoryPointer.new(:long).write_int(name_ptr.size)
|
33
|
+
success = GetUserName(name_ptr, size_ptr)
|
34
|
+
success.should_not == 0
|
35
|
+
name_ptr.read_string.strip.should == username
|
36
|
+
end
|
37
|
+
|
38
|
+
it "snake_case api to retrieve the user name in a specified format. Additional information " do
|
39
|
+
username = ENV['USERNAME'].strip
|
40
|
+
get_user_name.strip.should == username
|
41
|
+
end
|
42
|
+
end # describe get_user_name
|
43
|
+
|
44
|
+
end
|
@@ -1,169 +1,166 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'win/system/version'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
minor = object[1]
|
20
|
-
build = object[2]
|
21
|
-
end
|
22
|
-
os_major, os_minor, os_build = os_version_numbers
|
23
|
-
major.should == os_major
|
24
|
-
minor.should == os_minor
|
25
|
-
build.should == os_build
|
4
|
+
include WinTestApp
|
5
|
+
include Win::System::Version
|
6
|
+
|
7
|
+
def should_be_correct_os(type= :info, object)
|
8
|
+
case type
|
9
|
+
when :info
|
10
|
+
object.should be_an OSVERSIONINFOEX
|
11
|
+
major = object[:dw_major_version]
|
12
|
+
minor = object[:dw_minor_version]
|
13
|
+
build = object[:dw_build_number]
|
14
|
+
when :version
|
15
|
+
object.should be_an Array
|
16
|
+
major = object[0]
|
17
|
+
minor = object[1]
|
18
|
+
build = object[2]
|
26
19
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
os_major, os_minor, os_build = os_version_numbers
|
21
|
+
major.should == os_major
|
22
|
+
minor.should == os_minor
|
23
|
+
build.should == os_build
|
24
|
+
end
|
25
|
+
|
26
|
+
def os_version_numbers
|
27
|
+
os_ver = os.match(/Version ([\d]{1,2})\.([\d]{1,2})\.([\d]{1,5})/)
|
28
|
+
os_ver.captures.map(&:to_i)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Win::System::Version do
|
32
|
+
before(:each) do
|
33
|
+
@ver_info = OSVERSIONINFOEX.new
|
34
|
+
@ver_info[:dw_os_version_info_size] = @ver_info.size
|
31
35
|
end
|
32
36
|
|
33
|
-
describe
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
describe "#get_version" do
|
38
|
+
spec { use { success = GetVersion() } }
|
39
|
+
spec { use { version = get_version() } }
|
40
|
+
|
41
|
+
it "original api retrieves information about the current operating system (in a cryptic Integer)" do
|
42
|
+
GetVersion().should be_an Integer
|
43
|
+
GetVersion().should be > 0
|
37
44
|
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
it "snake_case api returns an Array [major, minor, build] of OS version numbers" do
|
47
|
+
version = get_version()
|
48
|
+
version.should be_an Array
|
49
|
+
version.should have_exactly(3).numbers
|
50
|
+
should_be_correct_os :version, version
|
51
|
+
end
|
52
|
+
end # describe get_version
|
42
53
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
54
|
+
describe "#get_version_ex" do
|
55
|
+
spec { use { success = GetVersionEx(@ver_info.to_ptr) } }
|
56
|
+
spec { use { ver_info = get_version_ex() } }
|
47
57
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
should_be_correct_os :version, version
|
53
|
-
end
|
54
|
-
end # describe get_version
|
55
|
-
|
56
|
-
describe "#get_version_ex" do
|
57
|
-
spec{ use{ success = GetVersionEx(@ver_info.to_ptr) }}
|
58
|
-
spec{ use{ ver_info = get_version_ex() }}
|
58
|
+
it "original api returns success code (0/1) and fills supplied OSVERSIONINFOEX struct" do
|
59
|
+
GetVersionEx(@ver_info.to_ptr).should_not == 0
|
60
|
+
should_be_correct_os :info, @ver_info
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
it "snake_case api returns fills given OSVERSIONINFOEX struct and returns it" do
|
64
|
+
info = get_version_ex(@ver_info)
|
65
|
+
info.should == @ver_info
|
66
|
+
should_be_correct_os :info, info
|
67
|
+
end
|
64
68
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
it "snake_case api returns filled OSVERSIONINFOEX struct if no arg given" do
|
70
|
+
info = get_version_ex()
|
71
|
+
should_be_correct_os :info, info
|
72
|
+
end
|
73
|
+
end # describe get_version_ex
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
end # describe get_version_ex
|
75
|
+
describe "#ver_set_condition_mask" do
|
76
|
+
spec { use { mask = VerSetConditionMask(dwl_condition_mask=0, dw_type_bit_mask=0, dw_condition_mask=0) } }
|
77
|
+
spec { use { mask = ver_set_condition_mask(dwl_condition_mask=0, dw_type_bit_mask=0, dw_condition_mask=0) } }
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
it "is used to build the dwlConditionMask parameter for the VerifyVersionInfo function" do
|
80
|
+
mask1 = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL)
|
81
|
+
mask2 = ver_set_condition_mask(0, VER_MAJORVERSION, VER_EQUAL)
|
82
|
+
mask1.should be_an Integer
|
83
|
+
mask1.should == mask2
|
84
|
+
end
|
80
85
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
context 'snake api accepts both single type/condition pair or an Array of type/condition pairs' do
|
87
|
+
it 'with single condition' do
|
88
|
+
mask1 = ver_set_condition_mask(0, VER_MAJORVERSION, VER_EQUAL)
|
89
|
+
mask2 = ver_set_condition_mask(VER_MAJORVERSION, VER_EQUAL)
|
90
|
+
mask3 = ver_set_condition_mask([VER_MAJORVERSION, VER_EQUAL])
|
91
|
+
mask4 = ver_set_condition_mask([[VER_MAJORVERSION, VER_EQUAL]])
|
85
92
|
mask1.should == mask2
|
93
|
+
mask1.should == mask4
|
94
|
+
mask1.should == mask3
|
86
95
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
mask1.should == mask4
|
96
|
-
mask1.should == mask3
|
97
|
-
end
|
98
|
-
it 'with multiple conditions' do
|
99
|
-
mask1 = ver_set_condition_mask(0, [[VER_MAJORVERSION, VER_EQUAL], [VER_MINORVERSION, VER_EQUAL]])
|
100
|
-
mask2 = ver_set_condition_mask([[VER_MAJORVERSION, VER_EQUAL], [VER_MINORVERSION, VER_EQUAL]])
|
101
|
-
mask3 = ver_set_condition_mask(0, [VER_MAJORVERSION, VER_EQUAL, VER_MINORVERSION, VER_EQUAL])
|
102
|
-
mask4 = ver_set_condition_mask([VER_MAJORVERSION, VER_EQUAL, VER_MINORVERSION, VER_EQUAL])
|
103
|
-
mask1.should == mask2
|
104
|
-
mask1.should == mask3
|
105
|
-
mask1.should == mask4
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end # describe ver_set_condition_mask
|
109
|
-
|
110
|
-
describe "#verify_version_info" do
|
111
|
-
before(:each) do
|
112
|
-
# Preparing condition mask
|
113
|
-
@mask_equal = ver_set_condition_mask(0, VER_MAJORVERSION, VER_EQUAL)
|
114
|
-
@mask_equal = ver_set_condition_mask(@mask_equal, VER_MINORVERSION, VER_EQUAL)
|
115
|
-
|
116
|
-
# Preparing expected version info
|
117
|
-
@expected = OSVERSIONINFOEX.new
|
118
|
-
@expected[:dw_os_version_info_size] = @expected.size
|
119
|
-
@expected[:dw_major_version] = os_version_numbers[0]
|
120
|
-
@expected[:dw_minor_version] = os_version_numbers[1]
|
96
|
+
it 'with multiple conditions' do
|
97
|
+
mask1 = ver_set_condition_mask(0, [[VER_MAJORVERSION, VER_EQUAL], [VER_MINORVERSION, VER_EQUAL]])
|
98
|
+
mask2 = ver_set_condition_mask([[VER_MAJORVERSION, VER_EQUAL], [VER_MINORVERSION, VER_EQUAL]])
|
99
|
+
mask3 = ver_set_condition_mask(0, [VER_MAJORVERSION, VER_EQUAL, VER_MINORVERSION, VER_EQUAL])
|
100
|
+
mask4 = ver_set_condition_mask([VER_MAJORVERSION, VER_EQUAL, VER_MINORVERSION, VER_EQUAL])
|
101
|
+
mask1.should == mask2
|
102
|
+
mask1.should == mask3
|
103
|
+
mask1.should == mask4
|
121
104
|
end
|
105
|
+
end
|
106
|
+
end # describe ver_set_condition_mask
|
122
107
|
|
123
|
-
|
124
|
-
|
108
|
+
describe "#verify_version_info" do
|
109
|
+
before(:each) do
|
110
|
+
# Preparing condition mask
|
111
|
+
@mask_equal = ver_set_condition_mask(0, VER_MAJORVERSION, VER_EQUAL)
|
112
|
+
@mask_equal = ver_set_condition_mask(@mask_equal, VER_MINORVERSION, VER_EQUAL)
|
113
|
+
|
114
|
+
# Preparing expected version info
|
115
|
+
@expected = OSVERSIONINFOEX.new
|
116
|
+
@expected[:dw_os_version_info_size] = @expected.size
|
117
|
+
@expected[:dw_major_version] = os_version_numbers[0]
|
118
|
+
@expected[:dw_minor_version] = os_version_numbers[1]
|
119
|
+
end
|
125
120
|
|
126
|
-
|
127
|
-
|
128
|
-
verify_version_info(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == true
|
129
|
-
end
|
121
|
+
spec { use { verified = VerifyVersionInfo(@expected.to_ptr, dw_type_mask=VER_MAJORVERSION, dwl_condition_mask=@mask_equal) } }
|
122
|
+
spec { use { verified = verify_version_info(@expected.to_ptr, dw_type_mask=VER_MAJORVERSION, dwl_condition_mask=@mask_equal) } }
|
130
123
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
124
|
+
it "returns 1/true if current OS features are in line with expected features " do
|
125
|
+
VerifyVersionInfo(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == 1
|
126
|
+
verify_version_info(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns 0/false if current OS features are different from expected" do
|
130
|
+
@expected[:dw_major_version] = 1
|
131
|
+
VerifyVersionInfo(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == 0
|
132
|
+
verify_version_info(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == false
|
133
|
+
end
|
134
|
+
end # describe verify_version_info
|
135
|
+
|
136
|
+
describe "convenience version checking methods" do
|
137
|
+
it 'returns true for current OS type, false otherwise' do
|
138
|
+
case
|
139
|
+
when os_2000?
|
140
|
+
windows_2000?.should == true
|
141
|
+
windows_xp?.should == false
|
142
|
+
windows_2003?.should == false
|
143
|
+
windows_vista?.should == false
|
144
|
+
windows_7?.should == false
|
145
|
+
when os_xp?
|
146
|
+
windows_2000?.should == false
|
147
|
+
windows_xp?.should == true
|
148
|
+
windows_2003?.should == false
|
149
|
+
windows_vista?.should == false
|
150
|
+
windows_7?.should == false
|
151
|
+
when os_vista?
|
152
|
+
windows_2000?.should == false
|
153
|
+
windows_xp?.should == false
|
154
|
+
windows_2003?.should == false
|
155
|
+
windows_vista?.should == true
|
156
|
+
windows_7?.should == false
|
157
|
+
when os_7?
|
158
|
+
windows_2000?.should == false
|
159
|
+
windows_xp?.should == false
|
160
|
+
windows_2003?.should == false
|
161
|
+
windows_vista?.should == false
|
162
|
+
windows_7?.should == true
|
166
163
|
end
|
167
164
|
end
|
168
165
|
end
|
169
|
-
end
|
166
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'win/time'
|
3
|
+
|
4
|
+
include Win::Time
|
5
|
+
|
6
|
+
describe Win::Time do
|
7
|
+
|
8
|
+
describe "#query_performance_frequency" do
|
9
|
+
spec { use { success = QueryPerformanceFrequency(freq = FFI::MemoryPointer.new(:int64)) } }
|
10
|
+
spec { use { freq = query_performance_frequency() } }
|
11
|
+
|
12
|
+
it "original api returns non-zero and high-res performance counter frequency it a pointer" do
|
13
|
+
QueryPerformanceFrequency(freq = FFI::MemoryPointer.new(:int64)).should be > 0
|
14
|
+
freq.get_int64(0).should be > 500000
|
15
|
+
end
|
16
|
+
|
17
|
+
it "snake_case api returns high-res performance counter frequency or nil if counter not available. " do
|
18
|
+
query_performance_frequency().should be > 500000
|
19
|
+
end
|
20
|
+
|
21
|
+
end # describe query_performance_frequency
|
22
|
+
|
23
|
+
describe "#query_performance_counter" do
|
24
|
+
spec { use { success = QueryPerformanceCounter(count = FFI::MemoryPointer.new(:int64)) } }
|
25
|
+
spec { use { success = query_performance_counter() } }
|
26
|
+
|
27
|
+
it "original api succeeds, the return value is nonzero, counter value returned at given pointer." do
|
28
|
+
QueryPerformanceCounter(count = FFI::MemoryPointer.new(:int64)).should be > 0
|
29
|
+
count.get_int64(0).should be > 500000000000
|
30
|
+
end
|
31
|
+
|
32
|
+
it "snake_case api succeeds, the return value is counter value (in counts)" do
|
33
|
+
count = query_performance_counter()
|
34
|
+
count.should be > 500000000000
|
35
|
+
end
|
36
|
+
|
37
|
+
it "successive function calls return (slightly) incremented counter values" do
|
38
|
+
100.times do
|
39
|
+
count1 = query_performance_counter()
|
40
|
+
count2 = query_performance_counter()
|
41
|
+
diff = count2 - count1
|
42
|
+
diff.should be > 10
|
43
|
+
diff.should be < 50000 # GC calls make it hard to guarantee uniform measurements?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end # describe query_performance_counter
|
47
|
+
|
48
|
+
end # describe Win::Time
|