windows-pr 0.2.0 → 0.5.3

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.
@@ -0,0 +1,70 @@
1
+ require 'Win32API'
2
+
3
+ module Windows
4
+ module SystemInfo
5
+ # Obsolete processor info constants
6
+ PROCESSOR_INTEL_386 = 386
7
+ PROCESSOR_INTEL_486 = 486
8
+ PROCESSOR_INTEL_PENTIUM = 586
9
+ PROCESSOR_INTEL_IA64 = 2200
10
+ PROCESSOR_AMD_X8664 = 8664
11
+
12
+ # Enum COMPUTER_NAME_FORMAT
13
+ ComputerNameNetBIOS = 0
14
+ ComputerNameDnsHostname = 1
15
+ ComputerNameDnsDomain = 2
16
+ ComputerNameDnsFullyQualified = 3
17
+ ComputerNamePhysicalNetBIOS = 4
18
+ ComputerNamePhysicalDnsHostname = 5
19
+ ComputerNamePhysicalDnsDomain = 6
20
+ ComputerNamePhysicalDnsFullyQualified = 7
21
+ ComputerNameMax = 8
22
+
23
+ ExpandEnvironmentStrings = Win32API.new('kernel32', 'ExpandEnvironmentStrings', 'PPL', 'L')
24
+
25
+ GetComputerName = Win32API.new('kernel32', 'GetComputerName', 'PP', 'I')
26
+ GetComputerNameEx = Win32API.new('kernel32', 'GetComputerNameEx', 'PPP', 'I')
27
+ GetSystemInfo = Win32API.new('kernel32', 'GetSystemInfo', 'P', 'V')
28
+ GetUserName = Win32API.new('advapi32', 'GetUserName', 'LL', 'I')
29
+ GetUserNameEx = Win32API.new('secur32', 'GetUserNameEx', 'LPL', 'I')
30
+ GetVersion = Win32API.new('kernel32', 'GetVersion', 'V', 'L')
31
+ GetVersionEx = Win32API.new('kernel32', 'GetVersionEx', 'P', 'I')
32
+ GetWindowsDirectory = Win32API.new('kernel32', 'GetWindowsDirectory', 'LI', 'I')
33
+
34
+ def ExpandEnvironmentStrings(src, dest, size)
35
+ ExpandEnvironmentStrings.call(src, dest, size)
36
+ end
37
+
38
+ def GetComputerName(buffer, size)
39
+ GetComputerNameEx.call(buffer, size) != 0
40
+ end
41
+
42
+ def GetComputerNameEx(name, buffer, size)
43
+ GetComputerNameEx.call(name, buffer, size) != 0
44
+ end
45
+
46
+ def GetSystemInfo(info)
47
+ GetSystemInfo.call(info)
48
+ end
49
+
50
+ def GetUserName(buf, size)
51
+ GetUserName.call(buf, size) != 0
52
+ end
53
+
54
+ def GetUserNameEx(format, buf, size)
55
+ GetUserNameEx.call(format, buf, size) != 0
56
+ end
57
+
58
+ def GetVersion()
59
+ GetVersion.call
60
+ end
61
+
62
+ def GetVersionEx(info)
63
+ GetVersionEx.call(info) != 0
64
+ end
65
+
66
+ def GetWindowsDirectory(buf, size)
67
+ GetWindowsDirectory.call(buf, size)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,138 @@
1
+ require 'Win32API'
2
+
3
+ module Windows
4
+ module Unicode
5
+ CP_ACP = 0
6
+ CP_OEMCP = 1
7
+ CP_MACCP = 2
8
+ CP_THREAD_ACP = 3
9
+ CP_SYMBOL = 42
10
+ CP_UTF7 = 65000
11
+ CP_UTF8 = 65001
12
+
13
+ MB_PRECOMPOSED = 0x00000001
14
+ MB_COMPOSITE = 0x00000002
15
+ MB_USEGLYPHCHARS = 0x00000004
16
+ MB_ERR_INVALID_CHARS = 0x00000008
17
+
18
+ WC_COMPOSITECHECK = 0x00000200
19
+ WC_DISCARDNS = 0x00000010
20
+ WC_SEPCHARS = 0x00000020
21
+ WC_DEFAULTCHAR = 0x00000040
22
+ WC_NO_BEST_FIT_CHARS = 0x00000400
23
+
24
+ ANSI_CHARSET = 0
25
+ DEFAULT_CHARSET = 1
26
+ SYMBOL_CHARSET = 2
27
+ SHIFTJIS_CHARSET = 128
28
+ HANGEUL_CHARSET = 129
29
+ HANGUL_CHARSET = 129
30
+ GB2312_CHARSET = 134
31
+ CHINESEBIG5_CHARSET = 136
32
+ OEM_CHARSET = 255
33
+ JOHAB_CHARSET = 130
34
+ HEBREW_CHARSET = 177
35
+ ARABIC_CHARSET = 178
36
+ GREEK_CHARSET = 161
37
+ TURKISH_CHARSET = 162
38
+ VIETNAMESE_CHARSET = 163
39
+ THAI_CHARSET = 222
40
+ EASTEUROPE_CHARSET = 238
41
+ RUSSIAN_CHARSET = 204
42
+
43
+ IS_TEXT_UNICODE_ASCII16 = 0x0001
44
+ IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
45
+ IS_TEXT_UNICODE_STATISTICS = 0x0002
46
+ IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
47
+ IS_TEXT_UNICODE_CONTROLS = 0x0004
48
+ IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
49
+ IS_TEXT_UNICODE_SIGNATURE = 0x0008
50
+ IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
51
+ IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
52
+ IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
53
+ IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
54
+ IS_TEXT_UNICODE_NULL_BYTES = 0x1000
55
+ IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
56
+ IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
57
+ IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
58
+ IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
59
+
60
+ TCI_SRCCHARSET = 1
61
+ TCI_SRCCODEPAGE = 2
62
+ TCI_SRCFONTSIG = 3
63
+ TCI_SRCLOCALE = 0x100
64
+
65
+ GetTextCharset = Win32API.new('gdi32', 'GetTextCharset', 'L', 'I')
66
+ GetTextCharsetInfo = Win32API.new('gdi32', 'GetTextCharsetInfo', 'LPL', 'I')
67
+ IsDBCSLeadByte = Win32API.new('kernel32', 'IsDBCSLeadByte', 'P', 'I')
68
+ IsDBCSLeadByteEx = Win32API.new('kernel32', 'IsDBCSLeadByteEx', 'IP', 'I')
69
+ IsTextUnicode = Win32API.new('advapi32', 'IsTextUnicode', 'PIP', 'I')
70
+ MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ILPIPI', 'I')
71
+ TranslateCharsetInfo = Win32API.new('gdi32', 'TranslateCharsetInfo', 'PPL', 'I')
72
+ WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ILPIPIPP', 'I')
73
+
74
+ def GetTextCharset(hdc)
75
+ GetTextCharset.call(hdc)
76
+ end
77
+
78
+ def GetTextCharsetInfo(hdc, sig, flags)
79
+ GetTextCharsetInfo.call(hdc, sig, flags)
80
+ end
81
+
82
+ def IsDBCSLeadByte(char)
83
+ IsDBCSLeadByte.call(char) != 0
84
+ end
85
+
86
+ def IsDBCSLeadByteEx(code_page, char)
87
+ IsDBCSLeadByteEx.call(code_pag, char) != 0
88
+ end
89
+
90
+ def IsTextUnicode(buf, size = buf.size, options = 0)
91
+ IsTextUnicode.call(buf, size, options) != 0
92
+ end
93
+
94
+ def MultiByteToWideChar(page, flags, str, str_size, buf, buf_size)
95
+ MultiByteToWideChar.call(page, flags, str, str_size, buf, buf_size)
96
+ end
97
+
98
+ def TranslateCharsetInfo(src, cs, flags)
99
+ TranslateCharsetInfo.call(src, cs, flags) != 0
100
+ end
101
+
102
+ def WideCharToMultiByte(page, flags, str, str_size, buf, buf_size, defchar, used_def)
103
+ WideCharToMultiByte.call(page, flags, str, str_size, buf, buf_size, defchar, used_def)
104
+ end
105
+
106
+ # Convenient wrapper methods
107
+
108
+ # Maps a string to a wide (unicode) string using UTF8. If the function
109
+ # fails it just returns the string as is.
110
+ #
111
+ def multi_to_wide(str)
112
+ cp = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
113
+ buf = 0.chr * str.size * 2 # sizeof(WCHAR)
114
+ int = MultiByteToWideChar(cp, 0, str, str.size, buf, buf.size)
115
+
116
+ if int > 0
117
+ buf[0, int*2]
118
+ else
119
+ str
120
+ end
121
+ end
122
+
123
+ # Maps a wide character string to a new character string. If the
124
+ # function fails it just returns the string as is.
125
+ #
126
+ def wide_to_multi(str)
127
+ cp = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
128
+ buf = 0.chr * str.size
129
+ int = WideCharToMultiByte(cp, 0, str, str.size/2, buf, buf.size, 0, 0)
130
+
131
+ if int > 0
132
+ buf[0, int]
133
+ else
134
+ str
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,22 @@
1
+ require 'Win32API'
2
+
3
+ module Windows
4
+ module Window
5
+ # ShowWindow() constants
6
+ SW_HIDE = 0
7
+ SW_SHOWNORMAL = 1
8
+ SW_NORMAL = 1
9
+ SW_SHOWMINIMIZED = 2
10
+ SW_SHOWMAXIMIZED = 3
11
+ SW_MAXIMIZE = 3
12
+ SW_SHOWNOACTIVATE = 4
13
+ SW_SHOW = 5
14
+ SW_MINIMIZE = 6
15
+ SW_SHOWMINNOACTIVE = 7
16
+ SW_SHOWNA = 8
17
+ SW_RESTORE = 9
18
+ SW_SHOWDEFAULT = 10
19
+ SW_FORCEMINIMIZE = 11
20
+ SW_MAX = 11
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ #####################################################################
2
+ # tc_clipboard.rb
3
+ #
4
+ # Test case for the Windows::Clipboard module.
5
+ #####################################################################
6
+ base = File.basename(Dir.pwd)
7
+ if base == 'test' || base =~ /windows-pr/
8
+ Dir.chdir '..' if base == 'test'
9
+ $LOAD_PATH.unshift Dir.pwd + '/lib'
10
+ Dir.chdir 'test' rescue nil
11
+ end
12
+
13
+ require "windows/clipboard"
14
+ require "test/unit"
15
+
16
+ class Foo
17
+ include Windows::Clipboard
18
+ end
19
+
20
+ class TC_Windows_Clipboard < Test::Unit::TestCase
21
+ def setup
22
+ @foo = Foo.new
23
+ end
24
+
25
+ def test_numeric_constants
26
+ assert_equal(1, Foo::CF_TEXT)
27
+ assert_equal(2, Foo::CF_BITMAP)
28
+ assert_equal(3, Foo::CF_METAFILEPICT)
29
+ assert_equal(4, Foo::CF_SYLK)
30
+ assert_equal(5, Foo::CF_DIF)
31
+ assert_equal(6, Foo::CF_TIFF)
32
+ assert_equal(7, Foo::CF_OEMTEXT)
33
+ assert_equal(8, Foo::CF_DIB)
34
+ assert_equal(9, Foo::CF_PALETTE)
35
+ assert_equal(10, Foo::CF_PENDATA)
36
+ assert_equal(11, Foo::CF_RIFF)
37
+ assert_equal(12, Foo::CF_WAVE)
38
+ assert_equal(13, Foo::CF_UNICODETEXT)
39
+ assert_equal(14, Foo::CF_ENHMETAFILE)
40
+ end
41
+
42
+ def test_method_constants
43
+ assert_not_nil(Foo::OpenClipboard)
44
+ assert_not_nil(Foo::CloseClipboard)
45
+ assert_not_nil(Foo::GetClipboardData)
46
+ assert_not_nil(Foo::EmptyClipboard)
47
+ assert_not_nil(Foo::SetClipboardData)
48
+ assert_not_nil(Foo::CountClipboardFormats)
49
+ assert_not_nil(Foo::IsClipboardFormatAvailable)
50
+ assert_not_nil(Foo::GetClipboardFormatName)
51
+ assert_not_nil(Foo::EnumClipboardFormats)
52
+ assert_not_nil(Foo::RegisterClipboardFormat)
53
+ end
54
+
55
+ def teardown
56
+ @foo = nil
57
+ end
58
+ end
@@ -0,0 +1,107 @@
1
+ ######################################################################
2
+ # tc_console.rb
3
+ #
4
+ # Test case for the Windows::Console module.
5
+ ######################################################################
6
+ base = File.basename(Dir.pwd)
7
+ if base == 'test' || base =~ /windows-pr/
8
+ Dir.chdir '..' if base == 'test'
9
+ $LOAD_PATH.unshift Dir.pwd + '/lib'
10
+ Dir.chdir 'test' rescue nil
11
+ end
12
+
13
+ require 'windows/console'
14
+ require 'test/unit'
15
+
16
+ class Foo
17
+ include Windows::Console
18
+ end
19
+
20
+ class TC_Windows_Console < Test::Unit::TestCase
21
+ def setup
22
+ @foo = Foo.new
23
+ end
24
+
25
+ def test_numeric_constants
26
+ assert_equal(0, Foo::CTRL_C_EVENT)
27
+ assert_equal(1, Foo::CTRL_BREAK_EVENT)
28
+ assert_equal(5, Foo::CTRL_LOGOFF_EVENT)
29
+ assert_equal(6, Foo::CTRL_SHUTDOWN_EVENT)
30
+
31
+ assert_equal(0x0001, Foo::ENABLE_PROCESSED_INPUT)
32
+ assert_equal(0x0002, Foo::ENABLE_LINE_INPUT)
33
+ assert_equal(0x0002, Foo::ENABLE_WRAP_AT_EOL_OUTPUT)
34
+ assert_equal(0x0004, Foo::ENABLE_ECHO_INPUT)
35
+ assert_equal(0x0008, Foo::ENABLE_WINDOW_INPUT)
36
+ assert_equal(0x0010, Foo::ENABLE_MOUSE_INPUT)
37
+ assert_equal(0x0020, Foo::ENABLE_INSERT_MODE)
38
+ assert_equal(0x0040, Foo::ENABLE_QUICK_EDIT_MODE)
39
+
40
+ assert_equal(-10, Foo::STD_INPUT_HANDLE)
41
+ assert_equal(-11, Foo::STD_OUTPUT_HANDLE)
42
+ assert_equal(-12, Foo::STD_ERROR_HANDLE)
43
+ end
44
+
45
+ def test_method_constants
46
+ assert_not_nil(Foo::AddConsoleAlias)
47
+ assert_not_nil(Foo::AllocConsole)
48
+ assert_not_nil(Foo::AttachConsole)
49
+ assert_not_nil(Foo::CreateConsoleScreenBuffer)
50
+ assert_not_nil(Foo::FillConsoleOutputAttribute)
51
+ assert_not_nil(Foo::FillConsoleOutputCharacter)
52
+ assert_not_nil(Foo::FlushConsoleInputBuffer)
53
+ assert_not_nil(Foo::FreeConsole)
54
+ assert_not_nil(Foo::GenerateConsoleCtrlEvent)
55
+ assert_not_nil(Foo::GetConsoleAlias)
56
+ assert_not_nil(Foo::GetConsoleAliases)
57
+ assert_not_nil(Foo::GetConsoleAliasesLength)
58
+ assert_not_nil(Foo::GetConsoleAliasExes)
59
+ assert_not_nil(Foo::GetConsoleAliasExesLength)
60
+ assert_not_nil(Foo::GetConsoleCP)
61
+ assert_not_nil(Foo::GetConsoleCursorInfo)
62
+ assert_not_nil(Foo::GetConsoleDisplayMode)
63
+ assert_not_nil(Foo::GetConsoleFontSize)
64
+ assert_not_nil(Foo::GetConsoleMode)
65
+ assert_not_nil(Foo::GetConsoleOutputCP)
66
+ assert_not_nil(Foo::GetConsoleProcessList)
67
+ assert_not_nil(Foo::GetConsoleScreenBufferInfo)
68
+ assert_not_nil(Foo::GetConsoleSelectionInfo)
69
+ assert_not_nil(Foo::GetConsoleTitle)
70
+ assert_not_nil(Foo::GetConsoleWindow)
71
+ assert_not_nil(Foo::GetCurrentConsoleFont)
72
+ assert_not_nil(Foo::GetLargestConsoleWindowSize)
73
+ assert_not_nil(Foo::GetNumberOfConsoleInputEvents)
74
+ assert_not_nil(Foo::GetNumberOfConsoleMouseButtons)
75
+ assert_not_nil(Foo::GetStdHandle)
76
+ assert_not_nil(Foo::PeekConsoleInput)
77
+ assert_not_nil(Foo::ReadConsole)
78
+ assert_not_nil(Foo::ReadConsoleInput)
79
+ assert_not_nil(Foo::ReadConsoleOutput)
80
+ assert_not_nil(Foo::ReadConsoleOutputAttribute)
81
+ assert_not_nil(Foo::ReadConsoleOutputCharacter)
82
+ assert_not_nil(Foo::ScrollConsoleScreenBuffer)
83
+ assert_not_nil(Foo::SetConsoleActiveScreenBuffer)
84
+ assert_not_nil(Foo::SetConsoleCommandHistoryMode)
85
+ assert_not_nil(Foo::SetConsoleCP)
86
+ assert_not_nil(Foo::SetConsoleCtrlHandler)
87
+ assert_not_nil(Foo::SetConsoleCursorInfo)
88
+ assert_not_nil(Foo::SetConsoleCursorPosition)
89
+ assert_not_nil(Foo::SetConsoleDisplayMode)
90
+ assert_not_nil(Foo::SetConsoleMode)
91
+ assert_not_nil(Foo::SetConsoleOutputCP)
92
+ assert_not_nil(Foo::SetConsoleScreenBufferSize)
93
+ assert_not_nil(Foo::SetConsoleTextAttribute)
94
+ assert_not_nil(Foo::SetConsoleTitle)
95
+ assert_not_nil(Foo::SetConsoleWindowInfo)
96
+ assert_not_nil(Foo::SetStdHandle)
97
+ assert_not_nil(Foo::WriteConsole)
98
+ assert_not_nil(Foo::WriteConsoleInput)
99
+ assert_not_nil(Foo::WriteConsoleOutput)
100
+ assert_not_nil(Foo::WriteConsoleOutputAttribute)
101
+ assert_not_nil(Foo::WriteConsoleOutputCharacter)
102
+ end
103
+
104
+ def teardown
105
+ @foo = nil
106
+ end
107
+ end
@@ -0,0 +1,65 @@
1
+ #####################################################################
2
+ # tc_eventlog.rb
3
+ #
4
+ # Test case for the Windows::EventLog module.
5
+ #####################################################################
6
+ base = File.basename(Dir.pwd)
7
+ if base == 'test' || base =~ /windows-pr/
8
+ Dir.chdir '..' if base == 'test'
9
+ $LOAD_PATH.unshift Dir.pwd + '/lib'
10
+ Dir.chdir 'test' rescue nil
11
+ end
12
+
13
+ require 'windows/eventlog'
14
+ require 'test/unit'
15
+
16
+ class Foo
17
+ include Windows::EventLog
18
+ end
19
+
20
+ class TC_Windows_EventLog < Test::Unit::TestCase
21
+ def setup
22
+ @foo = Foo.new
23
+ end
24
+
25
+ def test_numeric_constants
26
+ assert_equal(1, Foo::EVENTLOG_SEQUENTIAL_READ)
27
+ assert_equal(2, Foo::EVENTLOG_SEEK_READ)
28
+ assert_equal(4, Foo::EVENTLOG_FORWARDS_READ)
29
+ assert_equal(8, Foo::EVENTLOG_BACKWARDS_READ)
30
+ assert_equal(0, Foo::EVENTLOG_SUCCESS)
31
+ assert_equal(1, Foo::EVENTLOG_ERROR_TYPE)
32
+ assert_equal(2, Foo::EVENTLOG_WARNING_TYPE)
33
+ assert_equal(4, Foo::EVENTLOG_INFORMATION_TYPE)
34
+ assert_equal(8, Foo::EVENTLOG_AUDIT_SUCCESS)
35
+ assert_equal(16, Foo::EVENTLOG_AUDIT_FAILURE)
36
+ assert_equal(0, Foo::EVENTLOG_FULL_INFO)
37
+ end
38
+
39
+ def test_method_constants
40
+ assert_not_nil(Foo::BackupEventLog)
41
+ assert_not_nil(Foo::BackupEventLogW)
42
+ assert_not_nil(Foo::ClearEventLog)
43
+ assert_not_nil(Foo::ClearEventLogW)
44
+ assert_not_nil(Foo::CloseEventLog)
45
+ assert_not_nil(Foo::DeregisterEventSource)
46
+ assert_not_nil(Foo::GetEventLogInformation)
47
+ assert_not_nil(Foo::GetNumberOfEventLogRecords)
48
+ assert_not_nil(Foo::GetOldestEventLogRecord)
49
+ assert_not_nil(Foo::NotifyChangeEventLog)
50
+ assert_not_nil(Foo::OpenBackupEventLog)
51
+ assert_not_nil(Foo::OpenBackupEventLogW)
52
+ assert_not_nil(Foo::OpenEventLog)
53
+ assert_not_nil(Foo::OpenEventLogW)
54
+ assert_not_nil(Foo::ReadEventLog)
55
+ assert_not_nil(Foo::ReadEventLogW)
56
+ assert_not_nil(Foo::RegisterEventSource)
57
+ assert_not_nil(Foo::RegisterEventSourceW)
58
+ assert_not_nil(Foo::ReportEvent)
59
+ assert_not_nil(Foo::ReportEventW)
60
+ end
61
+
62
+ def teardown
63
+ @foo = nil
64
+ end
65
+ end