sys-filesystem 1.3.3 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +44 -24
- data/Gemfile +3 -0
- data/LICENSE +177 -0
- data/{MANIFEST.rdoc → MANIFEST.md} +3 -1
- data/README.md +89 -0
- data/Rakefile +14 -24
- data/examples/example_mount.rb +3 -2
- data/lib/sys/filesystem.rb +1 -1
- data/lib/sys/unix/sys/filesystem.rb +53 -33
- data/lib/sys/unix/sys/filesystem/constants.rb +2 -4
- data/lib/sys/unix/sys/filesystem/functions.rb +16 -10
- data/lib/sys/unix/sys/filesystem/structs.rb +47 -14
- data/lib/sys/windows/sys/filesystem.rb +43 -29
- data/lib/sys/windows/sys/filesystem/functions.rb +10 -10
- data/lib/sys/windows/sys/filesystem/helper.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/sys_filesystem_unix_spec.rb +392 -0
- data/spec/sys_filesystem_windows_spec.rb +344 -0
- data/sys-filesystem.gemspec +6 -8
- metadata +38 -51
- metadata.gz.sig +0 -0
- data/README.rdoc +0 -77
- data/test/test_sys_filesystem.rb +0 -7
- data/test/test_sys_filesystem_unix.rb +0 -329
- data/test/test_sys_filesystem_windows.rb +0 -303
@@ -1,303 +0,0 @@
|
|
1
|
-
####################################################################
|
2
|
-
# test_sys_filesystem_windows.rb
|
3
|
-
#
|
4
|
-
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
-
# This should be run via the 'rake test' task.
|
6
|
-
####################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'sys/filesystem'
|
9
|
-
require 'rbconfig'
|
10
|
-
require 'pathname'
|
11
|
-
include Sys
|
12
|
-
|
13
|
-
class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@dir = 'C:/'
|
16
|
-
@stat = Filesystem.stat(@dir)
|
17
|
-
@mount = Filesystem.mounts[0]
|
18
|
-
@size = 58720256
|
19
|
-
@array = []
|
20
|
-
end
|
21
|
-
|
22
|
-
test "version number is set to the expected value" do
|
23
|
-
assert_equal('1.3.2', Filesystem::VERSION)
|
24
|
-
assert_true(Filesystem::VERSION.frozen?)
|
25
|
-
end
|
26
|
-
|
27
|
-
test "stat path works as expected" do
|
28
|
-
assert_respond_to(@stat, :path)
|
29
|
-
assert_equal("C:/", @stat.path)
|
30
|
-
end
|
31
|
-
|
32
|
-
test "stat block_size works as expected" do
|
33
|
-
assert_respond_to(@stat, :block_size)
|
34
|
-
assert_kind_of(Numeric, @stat.block_size)
|
35
|
-
end
|
36
|
-
|
37
|
-
test "stat works with or without trailing slash on standard paths" do
|
38
|
-
assert_equal("C:/", Filesystem.stat("C:/").path)
|
39
|
-
assert_equal("C:/Users", Filesystem.stat("C:/Users").path)
|
40
|
-
assert_equal("C:/Users/", Filesystem.stat("C:/Users/").path)
|
41
|
-
assert_equal("C:/Users/", Filesystem.stat("C:/Users/").path)
|
42
|
-
end
|
43
|
-
|
44
|
-
test "stat works with or without trailing slash on UNC paths" do
|
45
|
-
assert_equal("//127.0.0.1/C$", Filesystem.stat("//127.0.0.1/C$").path)
|
46
|
-
assert_equal("//127.0.0.1/C$/", Filesystem.stat("//127.0.0.1/C$/").path)
|
47
|
-
assert_equal("\\\\127.0.0.1\\C$", Filesystem.stat("\\\\127.0.0.1\\C$").path)
|
48
|
-
assert_equal("\\\\127.0.0.1\\C$\\", Filesystem.stat("\\\\127.0.0.1\\C$\\").path)
|
49
|
-
end
|
50
|
-
|
51
|
-
test "stat fragment_size works as expected" do
|
52
|
-
assert_respond_to(@stat, :fragment_size)
|
53
|
-
assert_nil(@stat.fragment_size)
|
54
|
-
end
|
55
|
-
|
56
|
-
test "stat blocks works as expected" do
|
57
|
-
assert_respond_to(@stat, :blocks)
|
58
|
-
assert_kind_of(Numeric, @stat.blocks)
|
59
|
-
end
|
60
|
-
|
61
|
-
test "stat blocks_free works as expected" do
|
62
|
-
assert_respond_to(@stat, :blocks_free)
|
63
|
-
assert_kind_of(Numeric, @stat.blocks_free)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "stat blocks_available works as expected" do
|
67
|
-
assert_respond_to(@stat, :blocks_available)
|
68
|
-
assert_kind_of(Numeric, @stat.blocks_available)
|
69
|
-
end
|
70
|
-
|
71
|
-
test "block stats return expected relative values" do
|
72
|
-
assert_true(@stat.blocks >= @stat.blocks_free)
|
73
|
-
assert_true(@stat.blocks_free >= @stat.blocks_available)
|
74
|
-
end
|
75
|
-
|
76
|
-
test "stat files works as expected" do
|
77
|
-
assert_respond_to(@stat, :files)
|
78
|
-
assert_nil(@stat.files)
|
79
|
-
end
|
80
|
-
|
81
|
-
test "stat inodes is an alias for files" do
|
82
|
-
assert_alias_method(@stat, :inodes, :files)
|
83
|
-
end
|
84
|
-
|
85
|
-
test "stat files_free works as expected" do
|
86
|
-
assert_respond_to(@stat, :files_free)
|
87
|
-
assert_nil(@stat.files_free)
|
88
|
-
end
|
89
|
-
|
90
|
-
test "stat inodes_free is an alias for files_free" do
|
91
|
-
assert_respond_to(@stat, :inodes_free)
|
92
|
-
end
|
93
|
-
|
94
|
-
test "stat files available works as expected" do
|
95
|
-
assert_respond_to(@stat, :files_available)
|
96
|
-
assert_nil(@stat.files_available)
|
97
|
-
end
|
98
|
-
|
99
|
-
test "stat inodes_available is an alias for files_available" do
|
100
|
-
assert_alias_method(@stat, :inodes_available, :files_available)
|
101
|
-
end
|
102
|
-
|
103
|
-
test "stat filesystem_id works as expected" do
|
104
|
-
assert_respond_to(@stat, :filesystem_id)
|
105
|
-
assert_kind_of(Integer, @stat.filesystem_id)
|
106
|
-
end
|
107
|
-
|
108
|
-
test "stat flags works as expected" do
|
109
|
-
assert_respond_to(@stat, :flags)
|
110
|
-
assert_kind_of(Numeric, @stat.flags)
|
111
|
-
end
|
112
|
-
|
113
|
-
test "stat name_max works as expected" do
|
114
|
-
assert_respond_to(@stat, :name_max)
|
115
|
-
assert_kind_of(Numeric, @stat.name_max)
|
116
|
-
end
|
117
|
-
|
118
|
-
test "stat base_type works as expected" do
|
119
|
-
assert_respond_to(@stat, :base_type)
|
120
|
-
assert_kind_of(String, @stat.base_type)
|
121
|
-
end
|
122
|
-
|
123
|
-
test "stat bytes_total basic functionality" do
|
124
|
-
assert_respond_to(@stat, :bytes_total)
|
125
|
-
assert_kind_of(Numeric, @stat.bytes_total)
|
126
|
-
end
|
127
|
-
|
128
|
-
test "stat bytes_free basic functionality" do
|
129
|
-
assert_respond_to(@stat, :bytes_free)
|
130
|
-
assert_kind_of(Numeric, @stat.bytes_free)
|
131
|
-
assert_equal(@stat.bytes_free, @stat.blocks_free * @stat.block_size)
|
132
|
-
end
|
133
|
-
|
134
|
-
test "stat bytes_available basic functionality" do
|
135
|
-
assert_respond_to(@stat, :bytes_available)
|
136
|
-
assert_kind_of(Numeric, @stat.bytes_available)
|
137
|
-
assert_equal(@stat.bytes_available, @stat.blocks_available * @stat.block_size)
|
138
|
-
end
|
139
|
-
|
140
|
-
test "stat bytes_used basic functionality" do
|
141
|
-
assert_respond_to(@stat, :bytes_used)
|
142
|
-
assert_kind_of(Numeric, @stat.bytes_used)
|
143
|
-
end
|
144
|
-
|
145
|
-
test "stat percent_used basic functionality" do
|
146
|
-
assert_respond_to(@stat, :percent_used)
|
147
|
-
assert_kind_of(Float, @stat.percent_used)
|
148
|
-
end
|
149
|
-
|
150
|
-
test "case_insensitive returns expected result" do
|
151
|
-
assert_respond_to(@stat, :case_insensitive?)
|
152
|
-
assert_true(@stat.case_insensitive?)
|
153
|
-
end
|
154
|
-
|
155
|
-
test "mount_point singleton method basic functionality" do
|
156
|
-
assert_respond_to(Filesystem, :mount_point)
|
157
|
-
assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
|
158
|
-
assert_kind_of(String, Filesystem.mount_point(Dir.pwd))
|
159
|
-
end
|
160
|
-
|
161
|
-
test "mount_point singleton method returns expected value" do
|
162
|
-
assert_equal("C:\\", Filesystem.mount_point("C:\\Users\\foo"))
|
163
|
-
assert_equal("\\\\foo\\bar", Filesystem.mount_point("//foo/bar/baz"))
|
164
|
-
end
|
165
|
-
|
166
|
-
test "mount_point works with Pathname object" do
|
167
|
-
assert_nothing_raised{ Filesystem.mount_point(Pathname.new("C:/Users/foo")) }
|
168
|
-
assert_equal("C:\\", Filesystem.mount_point("C:\\Users\\foo"))
|
169
|
-
assert_equal("\\\\foo\\bar", Filesystem.mount_point("//foo/bar/baz"))
|
170
|
-
end
|
171
|
-
|
172
|
-
test "filesystem constants are defined" do
|
173
|
-
assert_not_nil(Filesystem::CASE_SENSITIVE_SEARCH)
|
174
|
-
assert_not_nil(Filesystem::CASE_PRESERVED_NAMES)
|
175
|
-
assert_not_nil(Filesystem::UNICODE_ON_DISK)
|
176
|
-
assert_not_nil(Filesystem::PERSISTENT_ACLS)
|
177
|
-
assert_not_nil(Filesystem::FILE_COMPRESSION)
|
178
|
-
assert_not_nil(Filesystem::VOLUME_QUOTAS)
|
179
|
-
assert_not_nil(Filesystem::SUPPORTS_SPARSE_FILES)
|
180
|
-
assert_not_nil(Filesystem::SUPPORTS_REPARSE_POINTS)
|
181
|
-
assert_not_nil(Filesystem::SUPPORTS_REMOTE_STORAGE)
|
182
|
-
assert_not_nil(Filesystem::VOLUME_IS_COMPRESSED)
|
183
|
-
assert_not_nil(Filesystem::SUPPORTS_OBJECT_IDS)
|
184
|
-
assert_not_nil(Filesystem::SUPPORTS_ENCRYPTION)
|
185
|
-
assert_not_nil(Filesystem::NAMED_STREAMS)
|
186
|
-
assert_not_nil(Filesystem::READ_ONLY_VOLUME)
|
187
|
-
end
|
188
|
-
|
189
|
-
test "stat singleton method defaults to root path if proviced" do
|
190
|
-
assert_nothing_raised{ Filesystem.stat("C://Program Files") }
|
191
|
-
end
|
192
|
-
|
193
|
-
test "stat singleton method accepts a Pathname object" do
|
194
|
-
assert_nothing_raised{ Filesystem.stat(Pathname.new("C://Program Files")) }
|
195
|
-
end
|
196
|
-
|
197
|
-
test "stat singleton method requires a single argument" do
|
198
|
-
assert_raise(ArgumentError){ Filesystem.stat }
|
199
|
-
assert_raise(ArgumentError){ Filesystem.stat(Dir.pwd, Dir.pwd) }
|
200
|
-
end
|
201
|
-
|
202
|
-
test "stat singleton method raises an error if path is not found" do
|
203
|
-
assert_raise(Errno::ESRCH){ Filesystem.stat("C://Bogus//Dir") }
|
204
|
-
end
|
205
|
-
|
206
|
-
# Filesystem.mounts
|
207
|
-
|
208
|
-
test "mounts singleton method basic functionality" do
|
209
|
-
assert_respond_to(Filesystem, :mounts)
|
210
|
-
assert_nothing_raised{ Filesystem.mounts }
|
211
|
-
assert_nothing_raised{ Filesystem.mounts{} }
|
212
|
-
end
|
213
|
-
|
214
|
-
test "mounts singleton method returns the expected value" do
|
215
|
-
assert_kind_of(Array, Filesystem.mounts)
|
216
|
-
assert_kind_of(Filesystem::Mount, Filesystem.mounts[0])
|
217
|
-
end
|
218
|
-
|
219
|
-
test "mounts singleton method works as expected when a block is provided" do
|
220
|
-
assert_nil(Filesystem.mounts{})
|
221
|
-
assert_nothing_raised{ Filesystem.mounts{ |mt| @array << mt }}
|
222
|
-
assert_kind_of(Filesystem::Mount, @array[0])
|
223
|
-
end
|
224
|
-
|
225
|
-
test "mount name works as expected" do
|
226
|
-
assert_respond_to(@mount, :name)
|
227
|
-
assert_kind_of(String, @mount.name)
|
228
|
-
end
|
229
|
-
|
230
|
-
test "mount time works as expected" do
|
231
|
-
assert_respond_to(@mount, :mount_time)
|
232
|
-
assert_kind_of(Time, @mount.mount_time)
|
233
|
-
end
|
234
|
-
|
235
|
-
test "mount type works as expected" do
|
236
|
-
assert_respond_to(@mount, :mount_type)
|
237
|
-
assert_kind_of(String, @mount.mount_type)
|
238
|
-
end
|
239
|
-
|
240
|
-
test "mount point works as expected" do
|
241
|
-
assert_respond_to(@mount, :mount_point)
|
242
|
-
assert_kind_of(String, @mount.mount_point)
|
243
|
-
end
|
244
|
-
|
245
|
-
test "mount options works as expected" do
|
246
|
-
assert_respond_to(@mount, :options)
|
247
|
-
assert_kind_of(String, @mount.options)
|
248
|
-
end
|
249
|
-
|
250
|
-
test "mount pass_number works as expected" do
|
251
|
-
assert_respond_to(@mount, :pass_number)
|
252
|
-
assert_nil(@mount.pass_number)
|
253
|
-
end
|
254
|
-
|
255
|
-
test "mount frequency works as expected" do
|
256
|
-
assert_respond_to(@mount, :frequency)
|
257
|
-
assert_nil(@mount.frequency)
|
258
|
-
end
|
259
|
-
|
260
|
-
test "mounts singleton method does not accept any arguments" do
|
261
|
-
assert_raise(ArgumentError){ Filesystem.mounts("C:\\") }
|
262
|
-
end
|
263
|
-
|
264
|
-
test "custom Numeric#to_kb method works as expected" do
|
265
|
-
assert_respond_to(@size, :to_kb)
|
266
|
-
assert_equal(57344, @size.to_kb)
|
267
|
-
end
|
268
|
-
|
269
|
-
test "custom Numeric#to_mb method works as expected" do
|
270
|
-
assert_respond_to(@size, :to_mb)
|
271
|
-
assert_equal(56, @size.to_mb)
|
272
|
-
end
|
273
|
-
|
274
|
-
test "custom Numeric#to_gb method works as expected" do
|
275
|
-
assert_respond_to(@size, :to_gb)
|
276
|
-
assert_equal(0, @size.to_gb)
|
277
|
-
end
|
278
|
-
|
279
|
-
# Mount and Unmount
|
280
|
-
|
281
|
-
test "mount singleton method exists" do
|
282
|
-
assert_respond_to(Sys::Filesystem, :mount)
|
283
|
-
end
|
284
|
-
|
285
|
-
test "umount singleton method exists" do
|
286
|
-
assert_respond_to(Sys::Filesystem, :umount)
|
287
|
-
end
|
288
|
-
|
289
|
-
# FFI
|
290
|
-
|
291
|
-
test "internal ffi functions are not public" do
|
292
|
-
assert_false(Filesystem.methods.include?(:GetVolumeInformationA))
|
293
|
-
assert_false(Filesystem.instance_methods.include?(:GetVolumeInformationA))
|
294
|
-
end
|
295
|
-
|
296
|
-
def teardown
|
297
|
-
@array = nil
|
298
|
-
@dir = nil
|
299
|
-
@stat = nil
|
300
|
-
@size = nil
|
301
|
-
@mount = nil
|
302
|
-
end
|
303
|
-
end
|