win32-file 0.6.8 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +202 -197
- data/MANIFEST +12 -12
- data/README +108 -97
- data/Rakefile +70 -65
- data/lib/win32/file.rb +1296 -1296
- data/test/test_win32_file_attributes.rb +285 -285
- data/test/test_win32_file_constants.rb +45 -45
- data/test/test_win32_file_encryption.rb +44 -44
- data/test/test_win32_file_path.rb +256 -256
- data/test/test_win32_file_security.rb +66 -66
- data/test/test_win32_file_stat.rb +114 -114
- data/win32-file.gemspec +31 -30
- metadata +64 -33
@@ -1,46 +1,46 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# test_win32_file_constants.rb
|
3
|
-
#
|
4
|
-
# Test case for the path related methods of win32-file. Run this test via
|
5
|
-
# the 'rake test' or 'rake test_constants' task.
|
6
|
-
#############################################################################
|
7
|
-
require 'test/unit'
|
8
|
-
require 'win32/file'
|
9
|
-
|
10
|
-
class TC_Win32_File_Constants < Test::Unit::TestCase
|
11
|
-
def test_file_attribute_constants
|
12
|
-
assert_not_nil(File::ARCHIVE)
|
13
|
-
assert_not_nil(File::HIDDEN)
|
14
|
-
assert_not_nil(File::NORMAL)
|
15
|
-
assert_not_nil(File::INDEXED)
|
16
|
-
assert_not_nil(File::OFFLINE)
|
17
|
-
assert_not_nil(File::READONLY)
|
18
|
-
assert_not_nil(File::SYSTEM)
|
19
|
-
assert_not_nil(File::TEMPORARY)
|
20
|
-
assert_not_nil(File::CONTENT_INDEXED) # alias for INDEXED
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_security_rights_constants
|
24
|
-
assert_not_nil(File::FULL)
|
25
|
-
assert_not_nil(File::DELETE)
|
26
|
-
assert_not_nil(File::READ_CONTROL)
|
27
|
-
assert_not_nil(File::WRITE_DAC)
|
28
|
-
assert_not_nil(File::WRITE_OWNER)
|
29
|
-
assert_not_nil(File::SYNCHRONIZE)
|
30
|
-
assert_not_nil(File::STANDARD_RIGHTS_REQUIRED)
|
31
|
-
assert_not_nil(File::STANDARD_RIGHTS_READ)
|
32
|
-
assert_not_nil(File::STANDARD_RIGHTS_WRITE)
|
33
|
-
assert_not_nil(File::STANDARD_RIGHTS_EXECUTE)
|
34
|
-
assert_not_nil(File::STANDARD_RIGHTS_ALL)
|
35
|
-
assert_not_nil(File::SPECIFIC_RIGHTS_ALL)
|
36
|
-
assert_not_nil(File::ACCESS_SYSTEM_SECURITY)
|
37
|
-
assert_not_nil(File::MAXIMUM_ALLOWED)
|
38
|
-
assert_not_nil(File::GENERIC_READ)
|
39
|
-
assert_not_nil(File::GENERIC_WRITE)
|
40
|
-
assert_not_nil(File::GENERIC_EXECUTE)
|
41
|
-
assert_not_nil(File::GENERIC_ALL)
|
42
|
-
assert_not_nil(File::READ)
|
43
|
-
assert_not_nil(File::CHANGE)
|
44
|
-
assert_not_nil(File::ADD)
|
45
|
-
end
|
1
|
+
#############################################################################
|
2
|
+
# test_win32_file_constants.rb
|
3
|
+
#
|
4
|
+
# Test case for the path related methods of win32-file. Run this test via
|
5
|
+
# the 'rake test' or 'rake test_constants' task.
|
6
|
+
#############################################################################
|
7
|
+
require 'test/unit'
|
8
|
+
require 'win32/file'
|
9
|
+
|
10
|
+
class TC_Win32_File_Constants < Test::Unit::TestCase
|
11
|
+
def test_file_attribute_constants
|
12
|
+
assert_not_nil(File::ARCHIVE)
|
13
|
+
assert_not_nil(File::HIDDEN)
|
14
|
+
assert_not_nil(File::NORMAL)
|
15
|
+
assert_not_nil(File::INDEXED)
|
16
|
+
assert_not_nil(File::OFFLINE)
|
17
|
+
assert_not_nil(File::READONLY)
|
18
|
+
assert_not_nil(File::SYSTEM)
|
19
|
+
assert_not_nil(File::TEMPORARY)
|
20
|
+
assert_not_nil(File::CONTENT_INDEXED) # alias for INDEXED
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_security_rights_constants
|
24
|
+
assert_not_nil(File::FULL)
|
25
|
+
assert_not_nil(File::DELETE)
|
26
|
+
assert_not_nil(File::READ_CONTROL)
|
27
|
+
assert_not_nil(File::WRITE_DAC)
|
28
|
+
assert_not_nil(File::WRITE_OWNER)
|
29
|
+
assert_not_nil(File::SYNCHRONIZE)
|
30
|
+
assert_not_nil(File::STANDARD_RIGHTS_REQUIRED)
|
31
|
+
assert_not_nil(File::STANDARD_RIGHTS_READ)
|
32
|
+
assert_not_nil(File::STANDARD_RIGHTS_WRITE)
|
33
|
+
assert_not_nil(File::STANDARD_RIGHTS_EXECUTE)
|
34
|
+
assert_not_nil(File::STANDARD_RIGHTS_ALL)
|
35
|
+
assert_not_nil(File::SPECIFIC_RIGHTS_ALL)
|
36
|
+
assert_not_nil(File::ACCESS_SYSTEM_SECURITY)
|
37
|
+
assert_not_nil(File::MAXIMUM_ALLOWED)
|
38
|
+
assert_not_nil(File::GENERIC_READ)
|
39
|
+
assert_not_nil(File::GENERIC_WRITE)
|
40
|
+
assert_not_nil(File::GENERIC_EXECUTE)
|
41
|
+
assert_not_nil(File::GENERIC_ALL)
|
42
|
+
assert_not_nil(File::READ)
|
43
|
+
assert_not_nil(File::CHANGE)
|
44
|
+
assert_not_nil(File::ADD)
|
45
|
+
end
|
46
46
|
end
|
@@ -1,44 +1,44 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# test_win32_file_encryption.rb
|
3
|
-
#
|
4
|
-
# Test case for the encryption related methods of win32-file. You should
|
5
|
-
# run this test via the 'rake test' or 'rake test_encryption' task.
|
6
|
-
#
|
7
|
-
# Note: These tests may fail based on the security setup of your system.
|
8
|
-
#############################################################################
|
9
|
-
require 'rubygems'
|
10
|
-
gem 'test-unit'
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
require 'win32/file'
|
14
|
-
|
15
|
-
class TC_Win32_File_Encryption < Test::Unit::TestCase
|
16
|
-
def self.startup
|
17
|
-
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
18
|
-
@@file = File.join(Dir.pwd, 'encryption_test.txt')
|
19
|
-
File.open(@@file, 'w'){ |fh| fh.puts "This is an encryption test." }
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
@msg = '=> Ignore. May not work due to security setup of your system.'
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_encrypt
|
27
|
-
assert_respond_to(File, :encrypt)
|
28
|
-
assert_nothing_raised(@msg){ File.encrypt(@@file) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_decrypt
|
32
|
-
assert_respond_to(File, :decrypt)
|
33
|
-
assert_nothing_raised(@msg){ File.decrypt(@@file) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def teardown
|
37
|
-
@msg = nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.shutdown
|
41
|
-
File.delete(@@file) if File.exists?(@@file)
|
42
|
-
@@file = nil
|
43
|
-
end
|
44
|
-
end
|
1
|
+
#############################################################################
|
2
|
+
# test_win32_file_encryption.rb
|
3
|
+
#
|
4
|
+
# Test case for the encryption related methods of win32-file. You should
|
5
|
+
# run this test via the 'rake test' or 'rake test_encryption' task.
|
6
|
+
#
|
7
|
+
# Note: These tests may fail based on the security setup of your system.
|
8
|
+
#############################################################################
|
9
|
+
require 'rubygems'
|
10
|
+
gem 'test-unit'
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
require 'win32/file'
|
14
|
+
|
15
|
+
class TC_Win32_File_Encryption < Test::Unit::TestCase
|
16
|
+
def self.startup
|
17
|
+
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
18
|
+
@@file = File.join(Dir.pwd, 'encryption_test.txt')
|
19
|
+
File.open(@@file, 'w'){ |fh| fh.puts "This is an encryption test." }
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@msg = '=> Ignore. May not work due to security setup of your system.'
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_encrypt
|
27
|
+
assert_respond_to(File, :encrypt)
|
28
|
+
assert_nothing_raised(@msg){ File.encrypt(@@file) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_decrypt
|
32
|
+
assert_respond_to(File, :decrypt)
|
33
|
+
assert_nothing_raised(@msg){ File.decrypt(@@file) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
@msg = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.shutdown
|
41
|
+
File.delete(@@file) if File.exists?(@@file)
|
42
|
+
@@file = nil
|
43
|
+
end
|
44
|
+
end
|
@@ -1,256 +1,256 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# test_win32_file_path.rb
|
3
|
-
#
|
4
|
-
# Test case for the path related methods of win32-file. You should run this
|
5
|
-
# test via the 'rake test' or 'rake test_path' task.
|
6
|
-
#############################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'win32/file'
|
12
|
-
|
13
|
-
class TC_Win32_File_Path < Test::Unit::TestCase
|
14
|
-
def self.startup
|
15
|
-
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
16
|
-
@@file = File.join(Dir.pwd, 'path_test.txt')
|
17
|
-
File.open(@@file, 'w'){ |fh| fh.puts "This is a path test." }
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup
|
21
|
-
@long_file = File.join(Dir.pwd, 'path_test.txt')
|
22
|
-
@short_file = File.join(Dir.pwd, 'PATH_T~1.TXT')
|
23
|
-
end
|
24
|
-
|
25
|
-
test "basename method basic functionality" do
|
26
|
-
assert_respond_to(File, :basename)
|
27
|
-
assert_nothing_raised{ File.basename("C:\\foo") }
|
28
|
-
assert_kind_of(String, File.basename("C:\\foo"))
|
29
|
-
end
|
30
|
-
|
31
|
-
test "basename method handles standard paths" do
|
32
|
-
assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt"))
|
33
|
-
assert_equal("baz", File.basename("C:\\foo\\bar\\baz.txt", ".txt"))
|
34
|
-
assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt", ".zip"))
|
35
|
-
assert_equal("bar", File.basename("C:\\foo\\bar"))
|
36
|
-
assert_equal("bar", File.basename("C:\\foo\\bar\\"))
|
37
|
-
assert_equal("foo", File.basename("C:\\foo"))
|
38
|
-
assert_equal("C:\\", File.basename("C:\\"))
|
39
|
-
end
|
40
|
-
|
41
|
-
test "basename method handles unc paths" do
|
42
|
-
assert_equal("baz.txt", File.basename("\\\\foo\\bar\\baz.txt"))
|
43
|
-
assert_equal("baz", File.basename("\\\\foo\\bar\\baz"))
|
44
|
-
assert_equal("\\\\foo", File.basename("\\\\foo"))
|
45
|
-
assert_equal("\\\\foo\\bar", File.basename("\\\\foo\\bar"))
|
46
|
-
end
|
47
|
-
|
48
|
-
test "basename method handles forward slashes in standard unix paths" do
|
49
|
-
assert_equal("bar", File.basename("/foo/bar"))
|
50
|
-
assert_equal("bar.txt", File.basename("/foo/bar.txt"))
|
51
|
-
assert_equal("bar.txt", File.basename("bar.txt"))
|
52
|
-
assert_equal("bar", File.basename("/bar"))
|
53
|
-
assert_equal("bar", File.basename("/bar/"))
|
54
|
-
assert_equal("baz", File.basename("//foo/bar/baz"))
|
55
|
-
end
|
56
|
-
|
57
|
-
test "basename method handles forward slashes in unc unix paths" do
|
58
|
-
assert_equal("\\\\foo", File.basename("//foo"))
|
59
|
-
assert_equal("\\\\foo\\bar", File.basename("//foo/bar"))
|
60
|
-
end
|
61
|
-
|
62
|
-
test "basename method handles forward slashes in windows paths" do
|
63
|
-
assert_equal("bar", File.basename("C:/foo/bar"))
|
64
|
-
assert_equal("bar", File.basename("C:/foo/bar/"))
|
65
|
-
assert_equal("foo", File.basename("C:/foo"))
|
66
|
-
assert_equal("C:\\", File.basename("C:/"))
|
67
|
-
assert_equal("bar", File.basename("C:/foo/bar//"))
|
68
|
-
end
|
69
|
-
|
70
|
-
test "basename handles edge cases as expected" do
|
71
|
-
assert_equal("", File.basename(""))
|
72
|
-
assert_equal(".", File.basename("."))
|
73
|
-
assert_equal("..", File.basename(".."))
|
74
|
-
assert_equal("foo", File.basename("//foo/"))
|
75
|
-
end
|
76
|
-
|
77
|
-
test "basename handles path names with suffixes" do
|
78
|
-
assert_equal("bar", File.basename("bar.txt", ".txt"))
|
79
|
-
assert_equal("bar", File.basename("/foo/bar.txt", ".txt"))
|
80
|
-
assert_equal("bar.txt", File.basename("bar.txt", ".exe"))
|
81
|
-
assert_equal("bar.txt", File.basename("bar.txt.exe", ".exe"))
|
82
|
-
assert_equal("bar.txt.exe", File.basename("bar.txt.exe", ".txt"))
|
83
|
-
assert_equal("bar", File.basename("bar.txt", ".*"))
|
84
|
-
assert_equal("bar.txt", File.basename("bar.txt.exe", ".*"))
|
85
|
-
end
|
86
|
-
|
87
|
-
test "basename method does not modify its argument" do
|
88
|
-
path = "C:\\foo\\bar"
|
89
|
-
assert_nothing_raised{ File.basename(path) }
|
90
|
-
assert_equal("C:\\foo\\bar", path)
|
91
|
-
end
|
92
|
-
|
93
|
-
test "basename removes all trailing slashes" do
|
94
|
-
assert_equal("foo.txt", File.basename("C:/foo.txt/"))
|
95
|
-
assert_equal("foo.txt", File.basename("C:/foo.txt//"))
|
96
|
-
assert_equal("foo.txt", File.basename("C:/foo.txt///"))
|
97
|
-
assert_equal("foo.txt", File.basename("C:\\foo.txt\\"))
|
98
|
-
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\"))
|
99
|
-
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\\\"))
|
100
|
-
assert_equal("foo.txt", File.basename("foo.txt\\\\\\"))
|
101
|
-
end
|
102
|
-
|
103
|
-
test "dirname basic functionality" do
|
104
|
-
assert_respond_to(File, :dirname)
|
105
|
-
assert_nothing_raised{ File.dirname("C:\\foo") }
|
106
|
-
assert_kind_of(String, File.dirname("C:\\foo"))
|
107
|
-
end
|
108
|
-
|
109
|
-
test "dirname handles standard windows paths as expected" do
|
110
|
-
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
|
111
|
-
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
|
112
|
-
assert_equal("C:\\", File.dirname("C:\\foo"))
|
113
|
-
assert_equal("C:\\", File.dirname("C:\\"))
|
114
|
-
assert_equal(".", File.dirname("foo"))
|
115
|
-
end
|
116
|
-
|
117
|
-
test "dirname handles unc windows paths as expected" do
|
118
|
-
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
|
119
|
-
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
|
120
|
-
assert_equal("\\\\foo", File.dirname("\\\\foo"))
|
121
|
-
assert_equal("\\\\", File.dirname("\\\\"))
|
122
|
-
end
|
123
|
-
|
124
|
-
test "dirname handles forward slashes in standard windows path names" do
|
125
|
-
assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
|
126
|
-
assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
|
127
|
-
assert_equal("C:\\", File.dirname("C:/foo"))
|
128
|
-
assert_equal("C:\\", File.dirname("C:/"))
|
129
|
-
end
|
130
|
-
|
131
|
-
test "dirname handles forward slashes in unc windows path names" do
|
132
|
-
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
|
133
|
-
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
|
134
|
-
assert_equal("\\\\foo", File.dirname("//foo"))
|
135
|
-
assert_equal("\\\\", File.dirname("//"))
|
136
|
-
end
|
137
|
-
|
138
|
-
test "dirname handles forward slashes in relative path names" do
|
139
|
-
assert_equal(".", File.dirname("./foo"))
|
140
|
-
assert_equal(".\\foo", File.dirname("./foo/bar"))
|
141
|
-
end
|
142
|
-
|
143
|
-
test "dirname handles various edge cases as expected" do
|
144
|
-
assert_equal(".", File.dirname(""))
|
145
|
-
assert_equal(".", File.dirname("."))
|
146
|
-
assert_equal(".", File.dirname(".."))
|
147
|
-
assert_equal(".", File.dirname("./"))
|
148
|
-
end
|
149
|
-
|
150
|
-
test "dirname method does not modify its argument" do
|
151
|
-
path = "C:\\foo\\bar"
|
152
|
-
assert_nothing_raised{ File.dirname(path) }
|
153
|
-
assert_equal("C:\\foo\\bar", path)
|
154
|
-
end
|
155
|
-
|
156
|
-
test "dirname method ignores trailing slashes" do
|
157
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
|
158
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
|
159
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
|
160
|
-
assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
|
161
|
-
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
|
162
|
-
end
|
163
|
-
|
164
|
-
test "argument to dirname must be a string" do
|
165
|
-
assert_raises(TypeError){ File.dirname(nil) }
|
166
|
-
assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
|
167
|
-
end
|
168
|
-
|
169
|
-
test "split method basic functionality" do
|
170
|
-
assert_respond_to(File, :split)
|
171
|
-
assert_nothing_raised{ File.split("C:\\foo\\bar") }
|
172
|
-
assert_kind_of(Array, File.split("C:\\foo\\bar"))
|
173
|
-
end
|
174
|
-
|
175
|
-
test "split method handles standard windows path names" do
|
176
|
-
assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
|
177
|
-
assert_equal([".", "foo"], File.split("foo"))
|
178
|
-
end
|
179
|
-
|
180
|
-
test "split method handles windows paths with forward slashes" do
|
181
|
-
assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
|
182
|
-
assert_equal([".", "foo"], File.split("foo"))
|
183
|
-
end
|
184
|
-
|
185
|
-
test "split method handles standard unix paths as expected" do
|
186
|
-
assert_equal(["\\foo","bar"], File.split("/foo/bar"))
|
187
|
-
assert_equal(["\\", "foo"], File.split("/foo"))
|
188
|
-
assert_equal([".", "foo"], File.split("foo"))
|
189
|
-
end
|
190
|
-
|
191
|
-
test "split method handles unc paths as expected" do
|
192
|
-
assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
|
193
|
-
assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
|
194
|
-
assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
|
195
|
-
assert_equal(["\\\\", ""], File.split("\\\\"))
|
196
|
-
end
|
197
|
-
|
198
|
-
test "split method handles various edge cases as expected" do
|
199
|
-
assert_equal(["C:\\", ""], File.split("C:\\"))
|
200
|
-
assert_equal(["", ""], File.split(""))
|
201
|
-
end
|
202
|
-
|
203
|
-
test "split method does not modify its arguments" do
|
204
|
-
path = "C:\\foo\\bar"
|
205
|
-
assert_nothing_raised{ File.split(path) }
|
206
|
-
assert_equal("C:\\foo\\bar", path)
|
207
|
-
end
|
208
|
-
|
209
|
-
test "long_path method works as expected" do
|
210
|
-
assert_respond_to(File, :long_path)
|
211
|
-
assert_equal(@long_file, File.long_path(@short_file))
|
212
|
-
assert_equal('PATH_T~1.TXT', File.basename(@short_file))
|
213
|
-
end
|
214
|
-
|
215
|
-
test "short_path method works as expected" do
|
216
|
-
assert_respond_to(File, :short_path)
|
217
|
-
assert_equal('path_test.txt', File.basename(@long_file))
|
218
|
-
end
|
219
|
-
|
220
|
-
test "join method works as expected" do
|
221
|
-
assert_respond_to(File, :join)
|
222
|
-
end
|
223
|
-
|
224
|
-
test "join handles multiple arguments as expected" do
|
225
|
-
assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
|
226
|
-
assert_equal("foo\\bar", File.join("foo", "bar"))
|
227
|
-
end
|
228
|
-
|
229
|
-
test "join handles multiple arguments as expected with unc paths" do
|
230
|
-
assert_equal("\\\\foo", File.join("\\\\foo"))
|
231
|
-
assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
|
232
|
-
end
|
233
|
-
|
234
|
-
test "join does not normalize paths" do
|
235
|
-
assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
|
236
|
-
end
|
237
|
-
|
238
|
-
test "join with no arguments returns an empty string" do
|
239
|
-
assert_equal('', File.join)
|
240
|
-
end
|
241
|
-
|
242
|
-
test "join with one argument returns the argument" do
|
243
|
-
assert_equal('foo', File.join('foo'))
|
244
|
-
assert_equal('c:', File.join('c:'))
|
245
|
-
end
|
246
|
-
|
247
|
-
def teardown
|
248
|
-
@short_file = nil
|
249
|
-
@long_file = nil
|
250
|
-
end
|
251
|
-
|
252
|
-
def self.shutdown
|
253
|
-
File.delete(@@file) if File.exists?(@@file)
|
254
|
-
@@file = nil
|
255
|
-
end
|
256
|
-
end
|
1
|
+
#############################################################################
|
2
|
+
# test_win32_file_path.rb
|
3
|
+
#
|
4
|
+
# Test case for the path related methods of win32-file. You should run this
|
5
|
+
# test via the 'rake test' or 'rake test_path' task.
|
6
|
+
#############################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'win32/file'
|
12
|
+
|
13
|
+
class TC_Win32_File_Path < Test::Unit::TestCase
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
16
|
+
@@file = File.join(Dir.pwd, 'path_test.txt')
|
17
|
+
File.open(@@file, 'w'){ |fh| fh.puts "This is a path test." }
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@long_file = File.join(Dir.pwd, 'path_test.txt')
|
22
|
+
@short_file = File.join(Dir.pwd, 'PATH_T~1.TXT')
|
23
|
+
end
|
24
|
+
|
25
|
+
test "basename method basic functionality" do
|
26
|
+
assert_respond_to(File, :basename)
|
27
|
+
assert_nothing_raised{ File.basename("C:\\foo") }
|
28
|
+
assert_kind_of(String, File.basename("C:\\foo"))
|
29
|
+
end
|
30
|
+
|
31
|
+
test "basename method handles standard paths" do
|
32
|
+
assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt"))
|
33
|
+
assert_equal("baz", File.basename("C:\\foo\\bar\\baz.txt", ".txt"))
|
34
|
+
assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt", ".zip"))
|
35
|
+
assert_equal("bar", File.basename("C:\\foo\\bar"))
|
36
|
+
assert_equal("bar", File.basename("C:\\foo\\bar\\"))
|
37
|
+
assert_equal("foo", File.basename("C:\\foo"))
|
38
|
+
assert_equal("C:\\", File.basename("C:\\"))
|
39
|
+
end
|
40
|
+
|
41
|
+
test "basename method handles unc paths" do
|
42
|
+
assert_equal("baz.txt", File.basename("\\\\foo\\bar\\baz.txt"))
|
43
|
+
assert_equal("baz", File.basename("\\\\foo\\bar\\baz"))
|
44
|
+
assert_equal("\\\\foo", File.basename("\\\\foo"))
|
45
|
+
assert_equal("\\\\foo\\bar", File.basename("\\\\foo\\bar"))
|
46
|
+
end
|
47
|
+
|
48
|
+
test "basename method handles forward slashes in standard unix paths" do
|
49
|
+
assert_equal("bar", File.basename("/foo/bar"))
|
50
|
+
assert_equal("bar.txt", File.basename("/foo/bar.txt"))
|
51
|
+
assert_equal("bar.txt", File.basename("bar.txt"))
|
52
|
+
assert_equal("bar", File.basename("/bar"))
|
53
|
+
assert_equal("bar", File.basename("/bar/"))
|
54
|
+
assert_equal("baz", File.basename("//foo/bar/baz"))
|
55
|
+
end
|
56
|
+
|
57
|
+
test "basename method handles forward slashes in unc unix paths" do
|
58
|
+
assert_equal("\\\\foo", File.basename("//foo"))
|
59
|
+
assert_equal("\\\\foo\\bar", File.basename("//foo/bar"))
|
60
|
+
end
|
61
|
+
|
62
|
+
test "basename method handles forward slashes in windows paths" do
|
63
|
+
assert_equal("bar", File.basename("C:/foo/bar"))
|
64
|
+
assert_equal("bar", File.basename("C:/foo/bar/"))
|
65
|
+
assert_equal("foo", File.basename("C:/foo"))
|
66
|
+
assert_equal("C:\\", File.basename("C:/"))
|
67
|
+
assert_equal("bar", File.basename("C:/foo/bar//"))
|
68
|
+
end
|
69
|
+
|
70
|
+
test "basename handles edge cases as expected" do
|
71
|
+
assert_equal("", File.basename(""))
|
72
|
+
assert_equal(".", File.basename("."))
|
73
|
+
assert_equal("..", File.basename(".."))
|
74
|
+
assert_equal("foo", File.basename("//foo/"))
|
75
|
+
end
|
76
|
+
|
77
|
+
test "basename handles path names with suffixes" do
|
78
|
+
assert_equal("bar", File.basename("bar.txt", ".txt"))
|
79
|
+
assert_equal("bar", File.basename("/foo/bar.txt", ".txt"))
|
80
|
+
assert_equal("bar.txt", File.basename("bar.txt", ".exe"))
|
81
|
+
assert_equal("bar.txt", File.basename("bar.txt.exe", ".exe"))
|
82
|
+
assert_equal("bar.txt.exe", File.basename("bar.txt.exe", ".txt"))
|
83
|
+
assert_equal("bar", File.basename("bar.txt", ".*"))
|
84
|
+
assert_equal("bar.txt", File.basename("bar.txt.exe", ".*"))
|
85
|
+
end
|
86
|
+
|
87
|
+
test "basename method does not modify its argument" do
|
88
|
+
path = "C:\\foo\\bar"
|
89
|
+
assert_nothing_raised{ File.basename(path) }
|
90
|
+
assert_equal("C:\\foo\\bar", path)
|
91
|
+
end
|
92
|
+
|
93
|
+
test "basename removes all trailing slashes" do
|
94
|
+
assert_equal("foo.txt", File.basename("C:/foo.txt/"))
|
95
|
+
assert_equal("foo.txt", File.basename("C:/foo.txt//"))
|
96
|
+
assert_equal("foo.txt", File.basename("C:/foo.txt///"))
|
97
|
+
assert_equal("foo.txt", File.basename("C:\\foo.txt\\"))
|
98
|
+
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\"))
|
99
|
+
assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\\\"))
|
100
|
+
assert_equal("foo.txt", File.basename("foo.txt\\\\\\"))
|
101
|
+
end
|
102
|
+
|
103
|
+
test "dirname basic functionality" do
|
104
|
+
assert_respond_to(File, :dirname)
|
105
|
+
assert_nothing_raised{ File.dirname("C:\\foo") }
|
106
|
+
assert_kind_of(String, File.dirname("C:\\foo"))
|
107
|
+
end
|
108
|
+
|
109
|
+
test "dirname handles standard windows paths as expected" do
|
110
|
+
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
|
111
|
+
assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
|
112
|
+
assert_equal("C:\\", File.dirname("C:\\foo"))
|
113
|
+
assert_equal("C:\\", File.dirname("C:\\"))
|
114
|
+
assert_equal(".", File.dirname("foo"))
|
115
|
+
end
|
116
|
+
|
117
|
+
test "dirname handles unc windows paths as expected" do
|
118
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
|
119
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
|
120
|
+
assert_equal("\\\\foo", File.dirname("\\\\foo"))
|
121
|
+
assert_equal("\\\\", File.dirname("\\\\"))
|
122
|
+
end
|
123
|
+
|
124
|
+
test "dirname handles forward slashes in standard windows path names" do
|
125
|
+
assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
|
126
|
+
assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
|
127
|
+
assert_equal("C:\\", File.dirname("C:/foo"))
|
128
|
+
assert_equal("C:\\", File.dirname("C:/"))
|
129
|
+
end
|
130
|
+
|
131
|
+
test "dirname handles forward slashes in unc windows path names" do
|
132
|
+
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
|
133
|
+
assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
|
134
|
+
assert_equal("\\\\foo", File.dirname("//foo"))
|
135
|
+
assert_equal("\\\\", File.dirname("//"))
|
136
|
+
end
|
137
|
+
|
138
|
+
test "dirname handles forward slashes in relative path names" do
|
139
|
+
assert_equal(".", File.dirname("./foo"))
|
140
|
+
assert_equal(".\\foo", File.dirname("./foo/bar"))
|
141
|
+
end
|
142
|
+
|
143
|
+
test "dirname handles various edge cases as expected" do
|
144
|
+
assert_equal(".", File.dirname(""))
|
145
|
+
assert_equal(".", File.dirname("."))
|
146
|
+
assert_equal(".", File.dirname(".."))
|
147
|
+
assert_equal(".", File.dirname("./"))
|
148
|
+
end
|
149
|
+
|
150
|
+
test "dirname method does not modify its argument" do
|
151
|
+
path = "C:\\foo\\bar"
|
152
|
+
assert_nothing_raised{ File.dirname(path) }
|
153
|
+
assert_equal("C:\\foo\\bar", path)
|
154
|
+
end
|
155
|
+
|
156
|
+
test "dirname method ignores trailing slashes" do
|
157
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
|
158
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
|
159
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
|
160
|
+
assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
|
161
|
+
assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
|
162
|
+
end
|
163
|
+
|
164
|
+
test "argument to dirname must be a string" do
|
165
|
+
assert_raises(TypeError){ File.dirname(nil) }
|
166
|
+
assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
|
167
|
+
end
|
168
|
+
|
169
|
+
test "split method basic functionality" do
|
170
|
+
assert_respond_to(File, :split)
|
171
|
+
assert_nothing_raised{ File.split("C:\\foo\\bar") }
|
172
|
+
assert_kind_of(Array, File.split("C:\\foo\\bar"))
|
173
|
+
end
|
174
|
+
|
175
|
+
test "split method handles standard windows path names" do
|
176
|
+
assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
|
177
|
+
assert_equal([".", "foo"], File.split("foo"))
|
178
|
+
end
|
179
|
+
|
180
|
+
test "split method handles windows paths with forward slashes" do
|
181
|
+
assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
|
182
|
+
assert_equal([".", "foo"], File.split("foo"))
|
183
|
+
end
|
184
|
+
|
185
|
+
test "split method handles standard unix paths as expected" do
|
186
|
+
assert_equal(["\\foo","bar"], File.split("/foo/bar"))
|
187
|
+
assert_equal(["\\", "foo"], File.split("/foo"))
|
188
|
+
assert_equal([".", "foo"], File.split("foo"))
|
189
|
+
end
|
190
|
+
|
191
|
+
test "split method handles unc paths as expected" do
|
192
|
+
assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
|
193
|
+
assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
|
194
|
+
assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
|
195
|
+
assert_equal(["\\\\", ""], File.split("\\\\"))
|
196
|
+
end
|
197
|
+
|
198
|
+
test "split method handles various edge cases as expected" do
|
199
|
+
assert_equal(["C:\\", ""], File.split("C:\\"))
|
200
|
+
assert_equal(["", ""], File.split(""))
|
201
|
+
end
|
202
|
+
|
203
|
+
test "split method does not modify its arguments" do
|
204
|
+
path = "C:\\foo\\bar"
|
205
|
+
assert_nothing_raised{ File.split(path) }
|
206
|
+
assert_equal("C:\\foo\\bar", path)
|
207
|
+
end
|
208
|
+
|
209
|
+
test "long_path method works as expected" do
|
210
|
+
assert_respond_to(File, :long_path)
|
211
|
+
assert_equal(@long_file, File.long_path(@short_file))
|
212
|
+
assert_equal('PATH_T~1.TXT', File.basename(@short_file))
|
213
|
+
end
|
214
|
+
|
215
|
+
test "short_path method works as expected" do
|
216
|
+
assert_respond_to(File, :short_path)
|
217
|
+
assert_equal('path_test.txt', File.basename(@long_file))
|
218
|
+
end
|
219
|
+
|
220
|
+
test "join method works as expected" do
|
221
|
+
assert_respond_to(File, :join)
|
222
|
+
end
|
223
|
+
|
224
|
+
test "join handles multiple arguments as expected" do
|
225
|
+
assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
|
226
|
+
assert_equal("foo\\bar", File.join("foo", "bar"))
|
227
|
+
end
|
228
|
+
|
229
|
+
test "join handles multiple arguments as expected with unc paths" do
|
230
|
+
assert_equal("\\\\foo", File.join("\\\\foo"))
|
231
|
+
assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
|
232
|
+
end
|
233
|
+
|
234
|
+
test "join does not normalize paths" do
|
235
|
+
assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
|
236
|
+
end
|
237
|
+
|
238
|
+
test "join with no arguments returns an empty string" do
|
239
|
+
assert_equal('', File.join)
|
240
|
+
end
|
241
|
+
|
242
|
+
test "join with one argument returns the argument" do
|
243
|
+
assert_equal('foo', File.join('foo'))
|
244
|
+
assert_equal('c:', File.join('c:'))
|
245
|
+
end
|
246
|
+
|
247
|
+
def teardown
|
248
|
+
@short_file = nil
|
249
|
+
@long_file = nil
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.shutdown
|
253
|
+
File.delete(@@file) if File.exists?(@@file)
|
254
|
+
@@file = nil
|
255
|
+
end
|
256
|
+
end
|