Skip to content

Commit

Permalink
System::Version specs added, still needs more
Browse files Browse the repository at this point in the history
  • Loading branch information
arvicco committed Jun 10, 2010
1 parent a8ebbde commit ffde21a
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 99 deletions.
4 changes: 4 additions & 0 deletions HISTORY
Expand Up @@ -50,3 +50,7 @@
== 0.3.14 / 2010-06-10

* System::Version and System::Info functions added

== 0.3.15 / 2010-06-10

* System::Version specs added
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.14
0.3.15
5 changes: 3 additions & 2 deletions lib/win/library.rb
Expand Up @@ -225,8 +225,9 @@ module Library
SHORT: :short, # A 16-bit integer. The range is –32768 through 32767 decimal.
SIZE_T: :ulong, # The maximum number of bytes to which a pointer can point. Use for a count that must span the full range of a pointer.
SSIZE_T: :long, # Signed SIZE_T.
TBYTE: :short, # A WCHAR if UNICODE is defined, a CHAR otherwise.TCHAR:
TCHAR: :short, # A WCHAR if UNICODE is defined, a CHAR otherwise.TCHAR:
TBYTE: :char, # A WCHAR if UNICODE is defined, a CHAR otherwise.TCHAR:
# http://msdn.microsoft.com/en-us/library/c426s321%28VS.80%29.aspx
TCHAR: :char, # A WCHAR if UNICODE is defined, a CHAR otherwise.TCHAR:
UCHAR: :uchar, # Unsigned CHAR (8 bit)
UHALF_PTR: :uint, # Unsigned HALF_PTR. Use within a structure that contains a pointer and two small fields.
UINT: :uint, # Unsigned INT. The range is 0 through 4294967295 decimal.
Expand Down
3 changes: 1 addition & 2 deletions lib/win/system/info.rb
Expand Up @@ -23,7 +23,7 @@ module Info

class << self
# Helper method that creates def_block returning (possibly encoded) string as a result of
# api function call or nil if api call was not successful
# api function call or nil if api call was not successful. TODO: put this into some kind of helper?
#
def return_sized_string( encode = nil ) #:nodoc:
lambda do |api, *args|
Expand All @@ -47,7 +47,6 @@ def return_sized_string( encode = nil ) #:nodoc:
private :return_sized_string
end


##
# GetComputerName Function.
# Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the
Expand Down
450 changes: 365 additions & 85 deletions lib/win/system/version.rb

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions spec/spec_helper.rb
Expand Up @@ -61,14 +61,22 @@ def os
@os_flag ||= cygwin? ? `cmd /c ver` : `ver`
end

def vista?
os =~ /Version 6/
def os_2000?
os =~ /Version 5.0/
end

def xp?
def os_xp?
os =~ /XP/
end

def os_vista?
os =~ /Version 6.0/
end

def os_7?
os =~ /Version 6.1/
end

module WinTest

KEY_DELAY = 0.001
Expand Down
4 changes: 2 additions & 2 deletions spec/win/error_spec.rb
Expand Up @@ -69,7 +69,7 @@ def sys_flags
end
end # describe set_last_error

if xp? || vista? # This function works only on XP++
if os_xp? || os_vista? # This function works only on XP++
describe "#set_last_error_ex" do
spec{ use{ SetLastErrorEx(dw_err_code=0, dw_type=0) }}
spec{ use{ set_last_error_ex(dw_err_code=0, dw_type=0) }}
Expand All @@ -86,7 +86,7 @@ def sys_flags
end # describe set_last_error_ex
end

if vista? # This function works only on Vista++
if os_vista? || os_7? # This function works only on Vista++
describe "#get_error_mode" do
spec{ use{ mode = GetErrorMode() }}
spec{ use{ mode = get_error_mode() }}
Expand Down
2 changes: 1 addition & 1 deletion spec/win/library_spec.rb
Expand Up @@ -356,7 +356,7 @@ def restore_method(*names) # restore original method if it was hidden
end

context '::try_function - possibly defines API functions that are platform-specific' do
if xp?
if os_xp?
it 'silently fails to define function not present on current platform' do
expect {MyLib.function :GetErrorMode, [], :UINT}.to raise_error /Function 'GetErrorMode' not found/
expect {MyLib.try_function :GetErrorMode, [], :UINT}.to_not raise_error
Expand Down
75 changes: 72 additions & 3 deletions spec/win/system/version_spec.rb
Expand Up @@ -4,11 +4,80 @@
module WinSystemInfoTest

include WinTestApp
# include Win::System::Version
include Win::System::Version

def should_be_correct_os(type= :info, object)
case type
when :info
object.should be_an OSVERSIONINFOEX
major = object[:dw_major_version]
when :version
object.should be_an Array
major = object.first
end
major.should == 5 if os_xp? || os_2000?
major.should == 6 if os_vista? || os_7?
end

describe Win::System::Version do
it 'should have tests' do
fail
before(:each) do
@ver_info = OSVERSIONINFOEX.new
@ver_info[:dw_os_version_info_size] = @ver_info.size
end

describe "#get_version" do
spec{ use{ success = GetVersion() }}
spec{ use{ version = get_version() }}

it "original api retrieves information about the current operating system (in a cryptic Integer)" do
GetVersion().should be_an Integer
GetVersion().should be > 0
end

it "snake_case api returns an Array [major, minor, build] of OS version numbers" do
version = get_version()
version.should be_an Array
version.should have_exactly(3).numbers
should_be_correct_os :version, version
end
end # describe get_version

describe "#get_version_ex" do
spec{ use{ success = GetVersionEx(@ver_info.to_ptr) }}
spec{ use{ ver_info = get_version_ex() }}

it "original api returns success code (0/1) and fills supplied OSVERSIONINFOEX struct" do
GetVersionEx(@ver_info.to_ptr).should_not == 0
should_be_correct_os :info, @ver_info
end

it "snake_case api returns fills given OSVERSIONINFOEX struct and returns it" do
info = get_version_ex(@ver_info)
info.should == @ver_info
should_be_correct_os :info, info
end

it "snake_case api returns filled OSVERSIONINFOEX struct if no arg given" do
info = get_version_ex()
should_be_correct_os :info, info
end
end # describe get_version_ex

describe "#verify_version_info" do
spec{ pending; use{ success = VerifyVersionInfo(@ver_info.to_ptr, dw_type_mask=0, dwl_condition_mask=0) }}
spec{ pending; use{ success = verify_version_info(@ver_info.to_ptr, dw_type_mask=0, dwl_condition_mask=0) }}

it "original api ignores structure " do
pending
success = VerifyVersionInfo(lp_version_info=0, dw_type_mask=0, dwl_condition_mask=0)
end

it "snake_case api ignores structure " do
pending
success = verify_version_info(lp_version_info=0, dw_type_mask=0, dwl_condition_mask=0)
end
end # describe verify_version_info


end
end

0 comments on commit ffde21a

Please sign in to comment.