win 0.3.24 → 0.3.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +1,44 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'win/system/info'
3
3
 
4
- module WinSystemInfoTest
5
-
6
- include WinTestApp
7
- include Win::System::Info
8
-
9
- describe Win::System::Info do
10
- describe "#get_computer_name" do
11
- spec{ use{ success = GetComputerName(buf = buffer, pointer.write_long(buf.size)) }}
12
- spec{ use{ name = get_computer_name() }}
13
-
14
- it "original api retrieves the NetBIOS name of the local computer " do
15
- name_ptr = FFI::MemoryPointer.from_string(" " * 128)
16
- size_ptr = FFI::MemoryPointer.new(:long).write_int(name_ptr.size)
17
- success = GetComputerName(name_ptr, size_ptr)
18
- success.should_not == 0
19
- name_ptr.read_string.should == `hostname`.strip.upcase
20
- end
21
-
22
- it "snake api retrieves the NetBIOS name of the local computer" do
23
- get_computer_name.strip.should == `hostname`.strip.upcase
24
- end
25
- end # describe get_computer_name
26
-
27
- describe "#get_user_name" do
28
- spec{ use{ success = GetUserName(buf = buffer, pointer.write_long(buf.size)) }}
29
- spec{ use{ username = get_user_name() }}
30
-
31
- it "original api to retrieve the user name in a specified format. Additional information " do
32
- username = `echo %USERNAME%`.strip
33
- name_ptr = FFI::MemoryPointer.from_string(" " * 128)
34
- size_ptr = FFI::MemoryPointer.new(:long).write_int(name_ptr.size)
35
- success = GetUserName(name_ptr, size_ptr)
36
- success.should_not == 0
37
- name_ptr.read_string.strip.should == username
38
- end
39
-
40
- it "snake_case api to retrieve the user name in a specified format. Additional information " do
41
- username = `echo %USERNAME%`.strip
42
- get_user_name.strip.should == username
43
- end
44
- end # describe get_user_name
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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require 'spec_helper'
2
2
  require 'win/system/version'
3
3
 
4
- module WinSystemInfoTest
5
-
6
- include WinTestApp
7
- include Win::System::Version
8
-
9
- def should_be_correct_os(type= :info, object)
10
- case type
11
- when :info
12
- object.should be_an OSVERSIONINFOEX
13
- major = object[:dw_major_version]
14
- minor = object[:dw_minor_version]
15
- build = object[:dw_build_number]
16
- when :version
17
- object.should be_an Array
18
- major = object[0]
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
- def os_version_numbers
29
- os_ver = os.match(/Version ([\d]{1,2})\.([\d]{1,2})\.([\d]{1,5})/ )
30
- os_ver.captures.map(&:to_i)
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 Win::System::Version do
34
- before(:each) do
35
- @ver_info = OSVERSIONINFOEX.new
36
- @ver_info[:dw_os_version_info_size] = @ver_info.size
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
- describe "#get_version" do
40
- spec{ use{ success = GetVersion() }}
41
- spec{ use{ version = get_version() }}
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
- it "original api retrieves information about the current operating system (in a cryptic Integer)" do
44
- GetVersion().should be_an Integer
45
- GetVersion().should be > 0
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
- it "snake_case api returns an Array [major, minor, build] of OS version numbers" do
49
- version = get_version()
50
- version.should be_an Array
51
- version.should have_exactly(3).numbers
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
- it "original api returns success code (0/1) and fills supplied OSVERSIONINFOEX struct" do
61
- GetVersionEx(@ver_info.to_ptr).should_not == 0
62
- should_be_correct_os :info, @ver_info
63
- end
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
- it "snake_case api returns fills given OSVERSIONINFOEX struct and returns it" do
66
- info = get_version_ex(@ver_info)
67
- info.should == @ver_info
68
- should_be_correct_os :info, info
69
- end
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
- it "snake_case api returns filled OSVERSIONINFOEX struct if no arg given" do
72
- info = get_version_ex()
73
- should_be_correct_os :info, info
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
- describe "#ver_set_condition_mask" do
78
- spec{ use{ mask = VerSetConditionMask(dwl_condition_mask=0, dw_type_bit_mask=0, dw_condition_mask=0) }}
79
- spec{ use{ mask = ver_set_condition_mask(dwl_condition_mask=0, dw_type_bit_mask=0, dw_condition_mask=0) }}
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
- it "is used to build the dwlConditionMask parameter for the VerifyVersionInfo function" do
82
- mask1 = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL)
83
- mask2 = ver_set_condition_mask(0, VER_MAJORVERSION, VER_EQUAL)
84
- mask1.should be_an Integer
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
- context 'snake api accepts both single type/condition pair or an Array of type/condition pairs' do
89
- it 'with single condition' do
90
- mask1 = ver_set_condition_mask(0, VER_MAJORVERSION, VER_EQUAL)
91
- mask2 = ver_set_condition_mask(VER_MAJORVERSION, VER_EQUAL)
92
- mask3 = ver_set_condition_mask([VER_MAJORVERSION, VER_EQUAL])
93
- mask4 = ver_set_condition_mask([[VER_MAJORVERSION, VER_EQUAL]])
94
- mask1.should == mask2
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
- spec{ use{ verified = VerifyVersionInfo(@expected.to_ptr, dw_type_mask=VER_MAJORVERSION, dwl_condition_mask=@mask_equal) }}
124
- spec{ use{ verified = verify_version_info(@expected.to_ptr, dw_type_mask=VER_MAJORVERSION, dwl_condition_mask=@mask_equal) }}
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
- it "returns 1/true if current OS features are in line with expected features " do
127
- VerifyVersionInfo(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == 1
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
- it "returns 0/false if current OS features are different from expected" do
132
- @expected[:dw_major_version] = 1
133
- VerifyVersionInfo(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == 0
134
- verify_version_info(@expected.to_ptr, VER_MAJORVERSION | VER_MINORVERSION, @mask_equal).should == false
135
- end
136
- end # describe verify_version_info
137
-
138
- describe "convenience version checking methods" do
139
- it 'returns true for current OS type, false otherwise' do
140
- case
141
- when os_2000?
142
- windows_2000?.should == true
143
- windows_xp?.should == false
144
- windows_2003?.should == false
145
- windows_vista?.should == false
146
- windows_7?.should == false
147
- when os_xp?
148
- windows_2000?.should == false
149
- windows_xp?.should == true
150
- windows_2003?.should == false
151
- windows_vista?.should == false
152
- windows_7?.should == false
153
- when os_vista?
154
- windows_2000?.should == false
155
- windows_xp?.should == false
156
- windows_2003?.should == false
157
- windows_vista?.should == true
158
- windows_7?.should == false
159
- when os_7?
160
- windows_2000?.should == false
161
- windows_xp?.should == false
162
- windows_2003?.should == false
163
- windows_vista?.should == false
164
- windows_7?.should == true
165
- end
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