win 0.3.11 → 0.3.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ require 'win/system/info'
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
@@ -0,0 +1,169 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ require 'win/system/version'
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
26
+ 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)
31
+ end
32
+
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
+ end
38
+
39
+ describe "#get_version" do
40
+ spec{ use{ success = GetVersion() }}
41
+ spec{ use{ version = get_version() }}
42
+
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
47
+
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() }}
59
+
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
64
+
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
70
+
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
76
+
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) }}
80
+
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
85
+ mask1.should == mask2
86
+ 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]
121
+ end
122
+
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) }}
125
+
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
130
+
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
166
+ end
167
+ end
168
+ end
169
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 11
9
- version: 0.3.11
8
+ - 16
9
+ version: 0.3.16
10
10
  platform: ruby
11
11
  authors:
12
12
  - arvicco
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-03 00:00:00 +04:00
17
+ date: 2010-06-11 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,8 @@ files:
78
78
  - lib/win/gui/window.rb
79
79
  - lib/win/gui.rb
80
80
  - lib/win/library.rb
81
+ - lib/win/system/info.rb
82
+ - lib/win/system/version.rb
81
83
  - lib/win.rb
82
84
  - spec/extension_spec.rb
83
85
  - spec/spec.opts
@@ -90,6 +92,8 @@ files:
90
92
  - spec/win/gui/message_spec.rb
91
93
  - spec/win/gui/window_spec.rb
92
94
  - spec/win/library_spec.rb
95
+ - spec/win/system/info_spec.rb
96
+ - spec/win/system/version_spec.rb
93
97
  - features/step_definitions/win_steps.rb
94
98
  - features/support/env.rb
95
99
  - features/win.feature
@@ -152,3 +156,5 @@ test_files:
152
156
  - spec/win/gui/message_spec.rb
153
157
  - spec/win/gui/window_spec.rb
154
158
  - spec/win/library_spec.rb
159
+ - spec/win/system/info_spec.rb
160
+ - spec/win/system/version_spec.rb