windows-pr 0.7.2 → 0.7.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.
- data/CHANGES +15 -0
- data/Rakefile +1 -2
- data/lib/windows/device_io.rb +2 -0
- data/lib/windows/error.rb +3 -0
- data/lib/windows/msvcrt/io.rb +5 -0
- data/lib/windows/msvcrt/string.rb +56 -13
- data/lib/windows/path.rb +1 -1
- data/lib/windows/process.rb +0 -4
- data/lib/windows/security.rb +32 -0
- data/lib/windows/service.rb +5 -2
- data/lib/windows/shell.rb +75 -0
- data/lib/windows/synchronize.rb +21 -0
- data/lib/windows/thread.rb +64 -0
- data/lib/windows/unicode.rb +18 -17
- data/test/tc_device_io.rb +29 -0
- data/test/tc_directory.rb +25 -0
- data/test/tc_file_mapping.rb +38 -0
- data/test/tc_filesystem.rb +27 -0
- data/test/tc_handle.rb +36 -0
- data/test/tc_limits.rb +34 -0
- data/test/tc_national.rb +38 -0
- data/test/tc_network_management.rb +32 -0
- data/test/tc_nio.rb +32 -0
- data/test/tc_service.rb +57 -0
- data/test/tc_shell.rb +34 -0
- data/test/tc_sound.rb +37 -0
- data/test/tc_synchronize.rb +6 -1
- data/test/tc_system_info.rb +36 -0
- data/test/tc_thread.rb +29 -0
- data/test/tc_time.rb +32 -0
- data/windows-pr.gemspec +1 -1
- metadata +83 -52
data/lib/windows/unicode.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'windows/api'
|
2
|
+
require 'windows/msvcrt/string'
|
2
3
|
include Windows
|
3
4
|
|
4
5
|
module Windows
|
5
6
|
module Unicode
|
7
|
+
include Windows::MSVCRT::String
|
8
|
+
|
6
9
|
API.auto_namespace = 'Windows::Unicode'
|
7
10
|
API.auto_constant = true
|
8
11
|
API.auto_method = true
|
@@ -78,37 +81,33 @@ module Windows
|
|
78
81
|
API.new('WideCharToMultiByte', 'ILPIPIPP', 'I')
|
79
82
|
|
80
83
|
# Convenient wrapper methods
|
81
|
-
|
84
|
+
|
82
85
|
# Maps a wide character string to a new character string using the
|
83
86
|
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
84
87
|
# iss used if $KCODE is set to UTF8. Otherwise, CP_ACP is used.
|
85
88
|
#
|
86
89
|
# If the function fails it simply returns the string as-is.
|
87
90
|
#
|
88
|
-
# Maps a string to a wide (unicode) string using +encoding+. If no
|
89
|
-
# encoding is specified, then CP_UTF8 is used if $KCODE is set to UTF8.
|
90
|
-
# Otherwise, CP_ACP is used.
|
91
|
-
#
|
92
|
-
# If the function fails it simply returns the string as-is.
|
93
|
-
#
|
94
91
|
def multi_to_wide(string, encoding=nil)
|
95
92
|
unless encoding
|
96
93
|
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
97
94
|
end
|
98
95
|
|
99
|
-
buf =
|
100
|
-
|
96
|
+
buf = ' ' * strlen(string) * 2
|
97
|
+
|
101
98
|
int = MultiByteToWideChar(
|
102
99
|
encoding,
|
103
100
|
0,
|
104
101
|
string,
|
105
|
-
string
|
102
|
+
strlen(string),
|
106
103
|
buf,
|
107
|
-
buf
|
104
|
+
strlen(buf)
|
108
105
|
)
|
109
106
|
|
110
107
|
if int > 0
|
111
|
-
|
108
|
+
dest = ' ' * int * 2
|
109
|
+
wcsncpy(dest, buf, int)
|
110
|
+
dest
|
112
111
|
else
|
113
112
|
string
|
114
113
|
end
|
@@ -125,21 +124,23 @@ module Windows
|
|
125
124
|
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
126
125
|
end
|
127
126
|
|
128
|
-
buf =
|
129
|
-
|
127
|
+
buf = ' ' * wcslen(string)
|
128
|
+
|
130
129
|
int = WideCharToMultiByte(
|
131
130
|
encoding,
|
132
131
|
0,
|
133
132
|
string,
|
134
|
-
string
|
133
|
+
wcslen(string),
|
135
134
|
buf,
|
136
|
-
buf
|
135
|
+
strlen(buf),
|
137
136
|
0,
|
138
137
|
0
|
139
138
|
)
|
140
139
|
|
141
140
|
if int > 0
|
142
|
-
|
141
|
+
dest = ' ' * int
|
142
|
+
strncpy(dest, buf, int)
|
143
|
+
dest
|
143
144
|
else
|
144
145
|
string
|
145
146
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_device_io.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::DeviceIO module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/device_io'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class DeviceIOFoo
|
10
|
+
include Windows::DeviceIO
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_DeviceIO < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@foo = DeviceIOFoo.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_numeric_constants
|
19
|
+
assert_equal(0x00000001, DeviceIOFoo::FILE_DEVICE_BEEP)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_method_constants
|
23
|
+
assert_not_nil(DeviceIOFoo::DeviceIoControl)
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
@foo = nil
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_directory.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::Directory module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/directory'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class DirectoryFoo
|
10
|
+
include Windows::Directory
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_Directory < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@foo = DirectoryFoo.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_method_constants
|
19
|
+
assert_not_nil(DirectoryFoo::CreateDirectory)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
@foo = nil
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_file_mapping.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::FileMapping module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/file_mapping'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class FileMappingFoo
|
10
|
+
include Windows::FileMapping
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_FileMapping < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@foo = FileMappingFoo.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_numeric_constants
|
20
|
+
assert_equal(0x00000001, FileMappingFoo::FILE_MAP_COPY)
|
21
|
+
assert_equal(0x00000002, FileMappingFoo::FILE_MAP_WRITE)
|
22
|
+
assert_equal(0x00000004, FileMappingFoo::FILE_MAP_READ)
|
23
|
+
assert_equal(983071, FileMappingFoo::FILE_MAP_ALL_ACCESS)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_method_constants
|
27
|
+
assert_not_nil(FileMappingFoo::CreateFileMapping)
|
28
|
+
assert_not_nil(FileMappingFoo::FlushViewOfFile)
|
29
|
+
assert_not_nil(FileMappingFoo::MapViewOfFile)
|
30
|
+
assert_not_nil(FileMappingFoo::MapViewOfFileEx)
|
31
|
+
assert_not_nil(FileMappingFoo::OpenFileMapping)
|
32
|
+
assert_not_nil(FileMappingFoo::UnmapViewOfFile)
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown
|
36
|
+
@foo = nil
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_filesystem.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::FileSystem module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/filesystem'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class FileSystemFoo
|
10
|
+
include Windows::FileSystem
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_FileSystem < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@foo = FileSystemFoo.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_method_constants
|
20
|
+
assert_not_nil(FileSystemFoo::GetDiskFreeSpace)
|
21
|
+
assert_not_nil(FileSystemFoo::GetDiskFreeSpaceEx)
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
@foo = nil
|
26
|
+
end
|
27
|
+
end
|
data/test/tc_handle.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_handle.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::Handle module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/handle'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class HandleFoo
|
10
|
+
include Windows::Handle
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_Handle < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@foo = HandleFoo.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_numeric_constants
|
20
|
+
assert_equal(-1, HandleFoo::INVALID_HANDLE_VALUE)
|
21
|
+
assert_equal(0x00000001, HandleFoo::HANDLE_FLAG_INHERIT)
|
22
|
+
assert_equal(0x00000002, HandleFoo::HANDLE_FLAG_PROTECT_FROM_CLOSE)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_method_constants
|
26
|
+
assert_not_nil(HandleFoo::CloseHandle)
|
27
|
+
assert_not_nil(HandleFoo::DuplicateHandle)
|
28
|
+
assert_not_nil(HandleFoo::GetHandleInformation)
|
29
|
+
assert_not_nil(HandleFoo::GetOSFHandle)
|
30
|
+
assert_not_nil(HandleFoo::OpenOSFHandle)
|
31
|
+
end
|
32
|
+
|
33
|
+
def teardown
|
34
|
+
@foo = nil
|
35
|
+
end
|
36
|
+
end
|
data/test/tc_limits.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_limits.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::Limits module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/limits'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class LimitsFoo
|
10
|
+
include Windows::Limits
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_Limits < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@foo = LimitsFoo.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_numeric_constants
|
20
|
+
assert_equal(0x80, LimitsFoo::MINCHAR)
|
21
|
+
assert_equal(0x7f, LimitsFoo::MAXCHAR)
|
22
|
+
assert_equal(0x8000, LimitsFoo::MINSHORT)
|
23
|
+
assert_equal(0x7fff, LimitsFoo::MAXSHORT)
|
24
|
+
assert_equal(0x80000000, LimitsFoo::MINLONG)
|
25
|
+
assert_equal(0x7fffffff, LimitsFoo::MAXLONG)
|
26
|
+
assert_equal(0xff, LimitsFoo::MAXBYTE)
|
27
|
+
assert_equal(0xffff, LimitsFoo::MAXWORD)
|
28
|
+
assert_equal(0xffffffff, LimitsFoo::MAXDWORD)
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
@foo = nil
|
33
|
+
end
|
34
|
+
end
|
data/test/tc_national.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_national.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::National module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/national'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class NationalFoo
|
10
|
+
include Windows::National
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_National < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@foo = NationalFoo.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_numeric_constants
|
19
|
+
assert_equal(2048, NationalFoo::LANG_SYSTEM_DEFAULT)
|
20
|
+
assert_equal(1024, NationalFoo::LANG_USER_DEFAULT)
|
21
|
+
assert_equal(2048, NationalFoo::LOCALE_SYSTEM_DEFAULT)
|
22
|
+
assert_equal(1024, NationalFoo::LOCALE_USER_DEFAULT)
|
23
|
+
assert_equal(8323072, NationalFoo::LOCALE_INVARIANT)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_method_constants
|
27
|
+
assert_not_nil(NationalFoo::GetACP)
|
28
|
+
assert_not_nil(NationalFoo::GetDateFormat)
|
29
|
+
assert_not_nil(NationalFoo::GetLocaleInfo)
|
30
|
+
assert_not_nil(NationalFoo::GetSystemDefaultLangID)
|
31
|
+
assert_not_nil(NationalFoo::GetUserDefaultLangID)
|
32
|
+
assert_not_nil(NationalFoo::GetUserDefaultLCID)
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown
|
36
|
+
@foo = nil
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_network_management.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::NetworkManagement module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/network_management'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class NetworkManagementFoo
|
10
|
+
include Windows::NetworkManagement
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_NetworkManagement < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@foo = NetworkManagementFoo.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_numeric_constants
|
19
|
+
assert_equal(0, NetworkManagementFoo::NERR_Success)
|
20
|
+
assert_equal(-1, NetworkManagementFoo::MAX_PREFERRED_LENGTH)
|
21
|
+
assert_equal(0x00000001, NetworkManagementFoo::SV_TYPE_WORKSTATION)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_method_constants
|
25
|
+
assert_not_nil(NetworkManagementFoo::NetAlertRaise)
|
26
|
+
assert_not_nil(NetworkManagementFoo::NetAlertRaiseEx)
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
@foo = nil
|
31
|
+
end
|
32
|
+
end
|
data/test/tc_nio.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_nio.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::NIO module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/nio'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class NIOFoo
|
10
|
+
include Windows::NIO
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_NIO < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@foo = NIOFoo.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_numeric_constants
|
19
|
+
assert_equal(0, NIOFoo::OF_READ)
|
20
|
+
assert_equal(1, NIOFoo::OF_WRITE)
|
21
|
+
assert_equal(2, NIOFoo::OF_READWRITE)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_method_constants
|
25
|
+
assert_not_nil(NIOFoo::CancelIo)
|
26
|
+
assert_not_nil(NIOFoo::ReadFileScatter)
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
@foo = nil
|
31
|
+
end
|
32
|
+
end
|
data/test/tc_service.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# tc_service.rb
|
3
|
+
#
|
4
|
+
# Test case for the Windows::Service module.
|
5
|
+
#####################################################################
|
6
|
+
require 'windows/service'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class ServiceFoo
|
10
|
+
include Windows::Service
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_Windows_Service < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@foo = ServiceFoo.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_numeric_constants
|
19
|
+
assert_equal(0, ServiceFoo::SC_ACTION_NONE)
|
20
|
+
assert_equal(1, ServiceFoo::SC_ACTION_RESTART)
|
21
|
+
assert_equal(2, ServiceFoo::SC_ACTION_REBOOT)
|
22
|
+
assert_equal(3, ServiceFoo::SC_ACTION_RUN_COMMAND)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_method_constants
|
26
|
+
assert_not_nil(ServiceFoo::ChangeServiceConfig)
|
27
|
+
assert_not_nil(ServiceFoo::ChangeServiceConfig2)
|
28
|
+
assert_not_nil(ServiceFoo::CloseServiceHandle)
|
29
|
+
assert_not_nil(ServiceFoo::ControlService)
|
30
|
+
assert_not_nil(ServiceFoo::CreateService)
|
31
|
+
assert_not_nil(ServiceFoo::DeleteService)
|
32
|
+
assert_not_nil(ServiceFoo::EnumDependentServices)
|
33
|
+
assert_not_nil(ServiceFoo::EnumServicesStatus)
|
34
|
+
assert_not_nil(ServiceFoo::EnumServicesStatusEx)
|
35
|
+
assert_not_nil(ServiceFoo::GetServiceDisplayName)
|
36
|
+
assert_not_nil(ServiceFoo::GetServiceKeyName)
|
37
|
+
assert_not_nil(ServiceFoo::LockServiceDatabase)
|
38
|
+
assert_not_nil(ServiceFoo::NotifyBootConfigStatus)
|
39
|
+
assert_not_nil(ServiceFoo::OpenSCManager)
|
40
|
+
assert_not_nil(ServiceFoo::OpenService)
|
41
|
+
assert_not_nil(ServiceFoo::QueryServiceConfig)
|
42
|
+
assert_not_nil(ServiceFoo::QueryServiceConfig2)
|
43
|
+
assert_not_nil(ServiceFoo::QueryServiceStatus)
|
44
|
+
assert_not_nil(ServiceFoo::QueryServiceStatusEx)
|
45
|
+
assert_not_nil(ServiceFoo::RegisterServiceCtrlHandler)
|
46
|
+
assert_not_nil(ServiceFoo::RegisterServiceCtrlHandlerEx)
|
47
|
+
assert_not_nil(ServiceFoo::SetServiceBits)
|
48
|
+
assert_not_nil(ServiceFoo::SetServiceStatus)
|
49
|
+
assert_not_nil(ServiceFoo::StartService)
|
50
|
+
assert_not_nil(ServiceFoo::StartServiceCtrlDispatcher)
|
51
|
+
assert_not_nil(ServiceFoo::UnlockServiceDatabase)
|
52
|
+
end
|
53
|
+
|
54
|
+
def teardown
|
55
|
+
@foo = nil
|
56
|
+
end
|
57
|
+
end
|