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.
@@ -15,21 +15,21 @@ module Sys
15
15
  end
16
16
 
17
17
  attach_pfunc :DeleteVolumeMountPointA, [:string], :bool
18
- attach_pfunc :GetDiskFreeSpaceW, [:buffer_in, :pointer, :pointer, :pointer, :pointer], :bool
19
- attach_pfunc :GetDiskFreeSpaceExW, [:buffer_in, :pointer, :pointer, :pointer], :bool
20
- attach_pfunc :GetLogicalDriveStringsA, [:ulong, :pointer], :ulong
18
+ attach_pfunc :GetDiskFreeSpaceW, %i[buffer_in pointer pointer pointer pointer], :bool
19
+ attach_pfunc :GetDiskFreeSpaceExW, %i[buffer_in pointer pointer pointer], :bool
20
+ attach_pfunc :GetLogicalDriveStringsA, %i[ulong pointer], :ulong
21
21
 
22
22
  attach_pfunc :GetVolumeInformationA,
23
- [:buffer_in, :pointer, :ulong, :pointer, :pointer, :pointer, :pointer, :ulong],
24
- :bool
23
+ %i[buffer_in pointer ulong pointer pointer pointer pointer ulong],
24
+ :bool
25
25
 
26
26
  attach_pfunc :GetVolumeInformationW,
27
- [:buffer_in, :pointer, :ulong, :pointer, :pointer, :pointer, :pointer, :ulong],
28
- :bool
27
+ %i[buffer_in pointer ulong pointer pointer pointer pointer ulong],
28
+ :bool
29
29
 
30
- attach_pfunc :GetVolumeNameForVolumeMountPointW, [:buffer_in, :buffer_in, :ulong], :bool
31
- attach_pfunc :QueryDosDeviceA, [:buffer_in, :buffer_out, :ulong], :ulong
32
- attach_pfunc :SetVolumeMountPointW, [:buffer_in, :buffer_in], :bool
30
+ attach_pfunc :GetVolumeNameForVolumeMountPointW, %i[buffer_in buffer_in ulong], :bool
31
+ attach_pfunc :QueryDosDeviceA, %i[buffer_in buffer_out ulong], :ulong
32
+ attach_pfunc :SetVolumeMountPointW, %i[buffer_in buffer_in], :bool
33
33
 
34
34
  ffi_lib :shlwapi
35
35
 
@@ -2,6 +2,6 @@ class String
2
2
  # Convenience method for converting strings to UTF-16LE for wide character
3
3
  # functions that require it.
4
4
  def wincode
5
- (self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
5
+ (tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
6
6
  end
7
7
  end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run_excluding(:windows) unless Gem.win_platform?
5
+ config.filter_run_excluding(:unix) if Gem.win_platform?
6
+ end
@@ -0,0 +1,392 @@
1
+ ####################################################################
2
+ # sys_filesystem_unix_spec.rb
3
+ #
4
+ # Specs for the Sys::Filesystem.stat method and related stuff.
5
+ # This test suite should be run via the 'rake spec' task.
6
+ ####################################################################
7
+ require 'spec_helper'
8
+ require 'sys-filesystem'
9
+ require 'pathname'
10
+
11
+ RSpec.describe Sys::Filesystem, :unix => true do
12
+ let(:solaris) { RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i }
13
+ let(:linux) { RbConfig::CONFIG['host_os'] =~ /linux/i }
14
+ let(:bsd) { RbConfig::CONFIG['host_os'] =~ /bsd/i }
15
+ let(:darwin) { RbConfig::CONFIG['host_os'] =~ /mac|darwin/i }
16
+ let(:root) { '/' }
17
+
18
+ before do
19
+ @stat = Sys::Filesystem.stat(root)
20
+ @size = 58720256
21
+ end
22
+
23
+ example "version number is set to the expected value" do
24
+ expect(Sys::Filesystem::VERSION).to eq('1.4.2')
25
+ expect(Sys::Filesystem::VERSION).to be_frozen
26
+ end
27
+
28
+ example "stat path works as expected" do
29
+ expect(@stat).to respond_to(:path)
30
+ expect(@stat.path).to eq(root)
31
+ end
32
+
33
+ example "stat block_size works as expected" do
34
+ expect(@stat).to respond_to(:block_size)
35
+ expect(@stat.block_size).to be_kind_of(Numeric)
36
+ end
37
+
38
+ example "stat fragment_size works as expected" do
39
+ expect(@stat).to respond_to(:fragment_size)
40
+ expect(@stat.fragment_size).to be_kind_of(Numeric)
41
+ end
42
+
43
+ example "stat fragment_size is a plausible value" do
44
+ expect(@stat.fragment_size).to be >= 512
45
+ expect(@stat.fragment_size).to be <= 16384
46
+ end
47
+
48
+ example "stat blocks works as expected" do
49
+ expect(@stat).to respond_to(:blocks)
50
+ expect(@stat.blocks).to be_kind_of(Numeric)
51
+ end
52
+
53
+ example "stat blocks_free works as expected" do
54
+ expect(@stat).to respond_to(:blocks_free)
55
+ expect(@stat.blocks_free).to be_kind_of(Numeric)
56
+ end
57
+
58
+ example "stat blocks_available works as expected" do
59
+ expect(@stat).to respond_to(:blocks_available)
60
+ expect(@stat.blocks_available).to be_kind_of(Numeric)
61
+ end
62
+
63
+ example "stat files works as expected" do
64
+ expect(@stat).to respond_to(:files)
65
+ expect(@stat.files).to be_kind_of(Numeric)
66
+ end
67
+
68
+ example "stat inodes is an alias for files" do
69
+ expect(@stat).to respond_to(:inodes)
70
+ expect(@stat.method(:inodes)).to eq(@stat.method(:files))
71
+ end
72
+
73
+ example "stat files tree works as expected" do
74
+ expect(@stat).to respond_to(:files_free)
75
+ expect(@stat.files_free).to be_kind_of(Numeric)
76
+ end
77
+
78
+ example "stat inodes_free is an alias for files_free" do
79
+ expect(@stat).to respond_to(:inodes_free)
80
+ expect(@stat.method(:inodes_free)).to eq(@stat.method(:files_free))
81
+ end
82
+
83
+ example "stat files_available works as expected" do
84
+ expect(@stat).to respond_to(:files_available)
85
+ expect(@stat.files_available).to be_kind_of(Numeric)
86
+ end
87
+
88
+ example "stat inodes_available is an alias for files_available" do
89
+ expect(@stat).to respond_to(:inodes_available)
90
+ expect(@stat.method(:inodes_available)).to eq(@stat.method(:files_available))
91
+ end
92
+
93
+ example "stat filesystem_id works as expected" do
94
+ expect(@stat).to respond_to(:filesystem_id)
95
+ expect(@stat.filesystem_id).to be_kind_of(Integer)
96
+ end
97
+
98
+ example "stat flags works as expected" do
99
+ expect(@stat).to respond_to(:flags)
100
+ expect(@stat.flags).to be_kind_of(Numeric)
101
+ end
102
+
103
+ example "stat name_max works as expected" do
104
+ expect(@stat).to respond_to(:name_max)
105
+ expect(@stat.name_max).to be_kind_of(Numeric)
106
+ end
107
+
108
+ example "stat base_type works as expected" do
109
+ skip "base_type test skipped except on Solaris" unless solaris
110
+
111
+ expect(@stat).to respond_to(:base_type)
112
+ expect(@stat.base_type).to be_kind_of(String)
113
+ end
114
+
115
+ example "stat constants are defined" do
116
+ expect(Sys::Filesystem::Stat::RDONLY).not_to be_nil
117
+ expect(Sys::Filesystem::Stat::NOSUID).not_to be_nil
118
+ end
119
+
120
+ example "stat constants for solaris are defined" do
121
+ skip "NOTRUNC test skipped except on Solaris" unless solaris
122
+ expect(Sys::Filesystem::Stat::NOTRUNC).not_to be_nil
123
+ end
124
+
125
+ example "stat bytes_total works as expected" do
126
+ expect(@stat).to respond_to(:bytes_total)
127
+ expect(@stat.bytes_total).to be_kind_of(Numeric)
128
+ end
129
+
130
+ example "stat bytes_free works as expected" do
131
+ expect(@stat).to respond_to(:bytes_free)
132
+ expect(@stat.bytes_free).to be_kind_of(Numeric)
133
+ expect(@stat.blocks_free * @stat.fragment_size).to eq(@stat.bytes_free)
134
+ end
135
+
136
+ example "stat bytes_available works as expected" do
137
+ expect(@stat).to respond_to(:bytes_available)
138
+ expect(@stat.bytes_available).to be_kind_of(Numeric)
139
+ expect(@stat.blocks_available * @stat.fragment_size).to eq(@stat.bytes_available)
140
+ end
141
+
142
+ example "stat bytes works as expected" do
143
+ expect(@stat).to respond_to(:bytes_used)
144
+ expect(@stat.bytes_used).to be_kind_of(Numeric)
145
+ end
146
+
147
+ example "stat percent_used works as expected" do
148
+ expect(@stat).to respond_to(:percent_used)
149
+ expect(@stat.percent_used).to be_kind_of(Float)
150
+ end
151
+
152
+ example "stat singleton method requires an argument" do
153
+ expect{ Sys::Filesystem.stat }.to raise_error(ArgumentError)
154
+ end
155
+
156
+ example "stat case_insensitive method works as expected" do
157
+ expected = darwin ? true : false
158
+ expect(@stat.case_insensitive?).to eq(expected)
159
+ expect(Sys::Filesystem.stat(Dir.home).case_insensitive?).to eq(expected)
160
+ end
161
+
162
+ example "stat case_sensitive method works as expected" do
163
+ expected = darwin ? false : true
164
+ expect(@stat.case_sensitive?).to eq(expected)
165
+ expect(Sys::Filesystem.stat(Dir.home).case_sensitive?).to eq(expected)
166
+ end
167
+
168
+ example "numeric helper methods are defined" do
169
+ expect(@size).to respond_to(:to_kb)
170
+ expect(@size).to respond_to(:to_mb)
171
+ expect(@size).to respond_to(:to_gb)
172
+ expect(@size).to respond_to(:to_tb)
173
+ end
174
+
175
+ example "to_kb works as expected" do
176
+ expect(@size.to_kb).to eq(57344)
177
+ end
178
+
179
+ example "to_mb works as expected" do
180
+ expect(@size.to_mb).to eq(56)
181
+ end
182
+
183
+ example "to_gb works as expected" do
184
+ expect(@size.to_gb).to eq(0)
185
+ end
186
+
187
+ context "Filesystem.stat(Pathname)" do
188
+ before do
189
+ @stat_pathname = Sys::Filesystem.stat(Pathname.new(root))
190
+ end
191
+
192
+ example "stat with Pathname argument works as expected" do
193
+ expect(@stat_pathname.class).to eq(@stat.class)
194
+ expect(@stat_pathname.path).to eq(@stat.path)
195
+ expect(@stat_pathname.block_size).to eq(@stat.block_size)
196
+ expect(@stat_pathname.fragment_size).to eq(@stat.fragment_size)
197
+ expect(@stat_pathname.blocks).to eq(@stat.blocks)
198
+ expect(@stat_pathname.blocks_free).to eq(@stat.blocks_free)
199
+ expect(@stat_pathname.blocks_available).to eq(@stat.blocks_available)
200
+ expect(@stat_pathname.files).to eq(@stat.files)
201
+ expect(@stat_pathname.files_free).to eq(@stat.files_free)
202
+ expect(@stat_pathname.files_available).to eq(@stat.files_available)
203
+ expect(@stat_pathname.filesystem_id).to eq(@stat.filesystem_id)
204
+ expect(@stat_pathname.flags).to eq(@stat.flags)
205
+ expect(@stat_pathname.name_max).to eq(@stat.name_max)
206
+ expect(@stat_pathname.base_type).to eq(@stat.base_type)
207
+ end
208
+ end
209
+
210
+ context "Filesystem.stat(File)" do
211
+ before do
212
+ @stat_file = File.open(root){ |file| Sys::Filesystem.stat(file) }
213
+ end
214
+
215
+ example "stat with File argument works as expected" do
216
+ expect(@stat_file.class).to eq(@stat.class)
217
+ expect(@stat_file.path).to eq(@stat.path)
218
+ expect(@stat_file.block_size).to eq(@stat.block_size)
219
+ expect(@stat_file.fragment_size).to eq(@stat.fragment_size)
220
+ expect(@stat_file.blocks).to eq(@stat.blocks)
221
+ expect(@stat_file.blocks_free).to eq(@stat.blocks_free)
222
+ expect(@stat_file.blocks_available).to eq(@stat.blocks_available)
223
+ expect(@stat_file.files).to eq(@stat.files)
224
+ expect(@stat_file.files_free).to eq(@stat.files_free)
225
+ expect(@stat_file.files_available).to eq(@stat.files_available)
226
+ expect(@stat_file.filesystem_id).to eq(@stat.filesystem_id)
227
+ expect(@stat_file.flags).to eq(@stat.flags)
228
+ expect(@stat_file.name_max).to eq(@stat.name_max)
229
+ expect(@stat_file.base_type).to eq(@stat.base_type)
230
+ end
231
+ end
232
+
233
+ context "Filesystem.stat(Dir)" do
234
+ before do
235
+ @stat_dir = Dir.open(root){ |dir| Sys::Filesystem.stat(dir) }
236
+ end
237
+
238
+ example "stat with Dir argument works as expected" do
239
+ expect(@stat_dir.class).to eq(@stat.class)
240
+ expect(@stat_dir.path).to eq(@stat.path)
241
+ expect(@stat_dir.block_size).to eq(@stat.block_size)
242
+ expect(@stat_dir.fragment_size).to eq(@stat.fragment_size)
243
+ expect(@stat_dir.blocks).to eq(@stat.blocks)
244
+ expect(@stat_dir.blocks_free).to eq(@stat.blocks_free)
245
+ expect(@stat_dir.blocks_available).to eq(@stat.blocks_available)
246
+ expect(@stat_dir.files).to eq(@stat.files)
247
+ expect(@stat_dir.files_free).to eq(@stat.files_free)
248
+ expect(@stat_dir.files_available).to eq(@stat.files_available)
249
+ expect(@stat_dir.filesystem_id).to eq(@stat.filesystem_id)
250
+ expect(@stat_dir.flags).to eq(@stat.flags)
251
+ expect(@stat_dir.name_max).to eq(@stat.name_max)
252
+ expect(@stat_dir.base_type).to eq(@stat.base_type)
253
+ end
254
+ end
255
+
256
+ context "Filesystem::Mount" do
257
+ let(:mount){ Sys::Filesystem.mounts[0] }
258
+
259
+ before do
260
+ @array = []
261
+ end
262
+
263
+ example "mounts singleton method works as expected without a block" do
264
+ expect{ @array = Sys::Filesystem.mounts }.not_to raise_error
265
+ expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
266
+ end
267
+
268
+ example "mounts singleton method works as expected with a block" do
269
+ expect{ Sys::Filesystem.mounts{ |m| @array << m } }.not_to raise_error
270
+ expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
271
+ end
272
+
273
+ example "calling the mounts singleton method a large number of times does not cause issues" do
274
+ expect{ 1000.times{ @array = Sys::Filesystem.mounts } }.not_to raise_error
275
+ end
276
+
277
+ example "mount name method works as expected" do
278
+ expect(mount).to respond_to(:name)
279
+ expect(mount.name).to be_kind_of(String)
280
+ end
281
+
282
+ example "mount fsname is an alias for name" do
283
+ expect(mount).to respond_to(:fsname)
284
+ expect(mount.method(:fsname)).to eq(mount.method(:name))
285
+ end
286
+
287
+ example "mount point method works as expected" do
288
+ expect(mount).to respond_to(:mount_point)
289
+ expect(mount.mount_point).to be_kind_of(String)
290
+ end
291
+
292
+ example "mount dir is an alias for mount_point" do
293
+ expect(mount).to respond_to(:dir)
294
+ expect(mount.method(:dir)).to eq(mount.method(:mount_point))
295
+ end
296
+
297
+ example "mount mount_type works as expected" do
298
+ expect(mount).to respond_to(:mount_type)
299
+ expect(mount.mount_type).to be_kind_of(String)
300
+ end
301
+
302
+ example "mount options works as expected" do
303
+ expect(mount).to respond_to(:options)
304
+ expect(mount.options).to be_kind_of(String)
305
+ end
306
+
307
+ example "mount opts is an alias for options" do
308
+ expect(mount).to respond_to(:opts)
309
+ expect(mount.method(:opts)).to eq(mount.method(:options))
310
+ end
311
+
312
+ example "mount time works as expected" do
313
+ expect(mount).to respond_to(:mount_time)
314
+
315
+ if solaris
316
+ expect(mount.mount_time).to be_kind_of(Time)
317
+ else
318
+ expect(mount.mount_time).to be_nil
319
+ end
320
+ end
321
+
322
+ example "mount dump_frequency works as expected" do
323
+ msg = 'dump_frequency test skipped on this platform'
324
+ skip msg if solaris || bsd || darwin
325
+ expect(mount).to respond_to(:dump_frequency)
326
+ expect(mount.dump_frequency).to be_kind_of(Numeric)
327
+ end
328
+
329
+ example "mount freq is an alias for dump_frequency" do
330
+ expect(mount).to respond_to(:freq)
331
+ expect(mount.method(:freq)).to eq(mount.method(:dump_frequency))
332
+ end
333
+
334
+ example "mount pass_number works as expected" do
335
+ msg = 'pass_number test skipped on this platform'
336
+ skip msg if solaris || bsd || darwin
337
+ expect(mount).to respond_to(:pass_number)
338
+ expect(mount.pass_number).to be_kind_of(Numeric)
339
+ end
340
+
341
+ example "mount passno is an alias for pass_number" do
342
+ expect(mount).to respond_to(:passno)
343
+ expect(mount.method(:passno)).to eq(mount.method(:pass_number))
344
+ end
345
+
346
+ example "mount_point singleton method works as expected" do
347
+ expect(Sys::Filesystem).to respond_to(:mount_point)
348
+ expect{ Sys::Filesystem.mount_point(Dir.pwd) }.not_to raise_error
349
+ expect(Sys::Filesystem.mount_point(Dir.pwd)).to be_kind_of(String)
350
+ end
351
+
352
+ example "mount singleton method is defined" do
353
+ expect(Sys::Filesystem).to respond_to(:mount)
354
+ end
355
+
356
+ example "umount singleton method is defined" do
357
+ expect(Sys::Filesystem).to respond_to(:umount)
358
+ end
359
+ end
360
+
361
+ context "FFI" do
362
+ before(:context) do
363
+ require 'mkmf-lite'
364
+ end
365
+
366
+ let(:dummy) { Class.new { extend Mkmf::Lite } }
367
+
368
+ example "ffi functions are private" do
369
+ expect(Sys::Filesystem.methods.include?('statvfs')).to be false
370
+ expect(Sys::Filesystem.methods.include?('strerror')).to be false
371
+ end
372
+
373
+ example "statfs struct is expected size" do
374
+ header = bsd || darwin ? 'sys/mount.h' : 'sys/statfs.h'
375
+ expect(Sys::Filesystem::Structs::Statfs.size).to eq(dummy.check_sizeof('struct statfs', header))
376
+ end
377
+
378
+ example "statvfs struct is expected size" do
379
+ expect(Sys::Filesystem::Structs::Statvfs.size).to eq(dummy.check_sizeof('struct statvfs', 'sys/statvfs.h'))
380
+ end
381
+
382
+ example "mnttab struct is expected size" do
383
+ skip "mnttab test skipped except on Solaris" unless solaris
384
+ expect(Sys::Filesystem::Structs::Mnttab.size).to eq(dummy.check_sizeof('struct mnttab', 'sys/mnttab.h'))
385
+ end
386
+
387
+ example "mntent struct is expected size" do
388
+ skip "mnttab test skipped except on Linux" unless linux
389
+ expect(Sys::Filesystem::Structs::Mntent.size).to eq(dummy.check_sizeof('struct mntent', 'mntent.h'))
390
+ end
391
+ end
392
+ end
@@ -0,0 +1,344 @@
1
+ ####################################################################
2
+ # sys_filesystem_windows_spec.rb
3
+ #
4
+ # Specs for the Sys::Filesystem.stat method and related stuff.
5
+ # This should be run via the 'rake spec' task.
6
+ ####################################################################
7
+ require 'spec_helper'
8
+ require 'sys/filesystem'
9
+ require 'pathname'
10
+
11
+ RSpec.describe Sys::Filesystem, :windows => true do
12
+ let(:root) { 'C:/' }
13
+
14
+ before do
15
+ @stat = Sys::Filesystem.stat(root)
16
+ @size = 58720256
17
+ end
18
+
19
+ example "version number is set to the expected value" do
20
+ expect(Sys::Filesystem::VERSION).to eq('1.4.2')
21
+ expect(Sys::Filesystem::VERSION).to be_frozen
22
+ end
23
+
24
+ example "stat path works as expected" do
25
+ expect(@stat).to respond_to(:path)
26
+ expect(@stat.path).to eq(root)
27
+ end
28
+
29
+ example "stat block_size works as expected" do
30
+ expect(@stat).to respond_to(:block_size)
31
+ expect(@stat.block_size).to be_kind_of(Numeric)
32
+ end
33
+
34
+ example "stat works with or without trailing slash on standard paths" do
35
+ expect(Sys::Filesystem.stat("C:/").path).to eq("C:/")
36
+ expect(Sys::Filesystem.stat("C:/Users").path).to eq("C:/Users")
37
+ expect(Sys::Filesystem.stat("C:/Users/").path).to eq("C:/Users/")
38
+ expect(Sys::Filesystem.stat("C:/Users/").path).to eq("C:/Users/")
39
+ end
40
+
41
+ example "stat works with or without trailing slash on UNC paths" do
42
+ expect(Sys::Filesystem.stat("//127.0.0.1/C$").path).to eq("//127.0.0.1/C$")
43
+ expect(Sys::Filesystem.stat("//127.0.0.1/C$/").path).to eq("//127.0.0.1/C$/")
44
+ expect(Sys::Filesystem.stat("\\\\127.0.0.1\\C$").path).to eq("\\\\127.0.0.1\\C$")
45
+ expect(Sys::Filesystem.stat("\\\\127.0.0.1\\C$\\").path).to eq("\\\\127.0.0.1\\C$\\")
46
+ end
47
+
48
+ example "stat fragment_size works as expected" do
49
+ expect(@stat).to respond_to(:fragment_size)
50
+ expect(@stat.fragment_size).to be_nil
51
+ end
52
+
53
+ example "stat blocks works as expected" do
54
+ expect(@stat).to respond_to(:blocks)
55
+ expect(@stat.blocks).to be_kind_of(Numeric)
56
+ end
57
+
58
+ example "stat blocks_free works as expected" do
59
+ expect(@stat).to respond_to(:blocks_free)
60
+ expect(@stat.blocks_free).to be_kind_of(Numeric)
61
+ end
62
+
63
+ example "stat blocks_available works as expected" do
64
+ expect(@stat).to respond_to(:blocks_available)
65
+ expect(@stat.blocks_available).to be_kind_of(Numeric)
66
+ end
67
+
68
+ example "block stats return expected relative values" do
69
+ expect(@stat.blocks >= @stat.blocks_free).to be true
70
+ expect(@stat.blocks_free >= @stat.blocks_available).to be true
71
+ end
72
+
73
+ example "stat files works as expected" do
74
+ expect(@stat).to respond_to(:files)
75
+ expect(@stat.files).to be_nil
76
+ end
77
+
78
+ example "stat inodes is an alias for files" do
79
+ expect(@stat.method(:inodes)).to eq(@stat.method(:files))
80
+ end
81
+
82
+ example "stat files_free works as expected" do
83
+ expect(@stat).to respond_to(:files_free)
84
+ expect(@stat.files_free).to be_nil
85
+ end
86
+
87
+ example "stat inodes_free is an alias for files_free" do
88
+ expect(@stat).to respond_to(:inodes_free)
89
+ end
90
+
91
+ example "stat files available works as expected" do
92
+ expect(@stat).to respond_to(:files_available)
93
+ expect(@stat.files_available).to be_nil
94
+ end
95
+
96
+ example "stat inodes_available is an alias for files_available" do
97
+ expect(@stat.method(:inodes_available)).to eq(@stat.method(:files_available))
98
+ end
99
+
100
+ example "stat filesystem_id works as expected" do
101
+ expect(@stat).to respond_to(:filesystem_id)
102
+ expect(@stat.filesystem_id).to be_kind_of(Integer)
103
+ end
104
+
105
+ example "stat flags works as expected" do
106
+ expect(@stat).to respond_to(:flags)
107
+ expect(@stat.flags).to be_kind_of(Numeric)
108
+ end
109
+
110
+ example "stat name_max works as expected" do
111
+ expect(@stat).to respond_to(:name_max)
112
+ expect(@stat.name_max).to be_kind_of(Numeric)
113
+ end
114
+
115
+ example "stat base_type works as expected" do
116
+ expect(@stat).to respond_to(:base_type)
117
+ expect(@stat.base_type).to be_kind_of(String)
118
+ end
119
+
120
+ example "stat bytes_total basic functionality" do
121
+ expect(@stat).to respond_to(:bytes_total)
122
+ expect(@stat.bytes_total).to be_kind_of(Numeric)
123
+ end
124
+
125
+ example "stat bytes_free basic functionality" do
126
+ expect(@stat).to respond_to(:bytes_free)
127
+ expect(@stat.bytes_free).to be_kind_of(Numeric)
128
+ expect(@stat.blocks_free * @stat.block_size).to eq(@stat.bytes_free)
129
+ end
130
+
131
+ example "stat bytes_available basic functionality" do
132
+ expect(@stat).to respond_to(:bytes_available)
133
+ expect(@stat.bytes_available).to be_kind_of(Numeric)
134
+ expect(@stat.blocks_available * @stat.block_size).to eq(@stat.bytes_available)
135
+ end
136
+
137
+ example "stat bytes_used basic functionality" do
138
+ expect(@stat).to respond_to(:bytes_used)
139
+ expect(@stat.bytes_used).to be_kind_of(Numeric)
140
+ end
141
+
142
+ example "stat percent_used basic functionality" do
143
+ expect(@stat).to respond_to(:percent_used)
144
+ expect(@stat.percent_used).to be_kind_of(Float)
145
+ end
146
+
147
+ example "case_insensitive returns expected result" do
148
+ expect(@stat).to respond_to(:case_insensitive?)
149
+ expect(@stat.case_insensitive?).to eq(true)
150
+ end
151
+
152
+ context "Filesystem.stat(Pathname)" do
153
+ before do
154
+ @stat_pathname = Sys::Filesystem.stat(Pathname.new(root))
155
+ end
156
+
157
+ example "stat with Pathname argument works as expected" do
158
+ expect(@stat_pathname.class).to eq(@stat.class)
159
+ expect(@stat_pathname.path).to eq(@stat.path)
160
+ expect(@stat_pathname.block_size).to eq(@stat.block_size)
161
+ expect(@stat_pathname.fragment_size).to eq(@stat.fragment_size)
162
+ expect(@stat_pathname.blocks).to eq(@stat.blocks)
163
+ expect(@stat_pathname.blocks_free).to eq(@stat.blocks_free)
164
+ expect(@stat_pathname.blocks_available).to eq(@stat.blocks_available)
165
+ expect(@stat_pathname.files).to eq(@stat.files)
166
+ expect(@stat_pathname.files_free).to eq(@stat.files_free)
167
+ expect(@stat_pathname.files_available).to eq(@stat.files_available)
168
+ expect(@stat_pathname.filesystem_id).to eq(@stat.filesystem_id)
169
+ expect(@stat_pathname.flags).to eq(@stat.flags)
170
+ expect(@stat_pathname.name_max).to eq(@stat.name_max)
171
+ expect(@stat_pathname.base_type).to eq(@stat.base_type)
172
+ end
173
+ end
174
+
175
+ context "Filesystem.stat(Dir)" do
176
+ before do
177
+ @stat_dir = Dir.open(root){ |dir| Sys::Filesystem.stat(dir) }
178
+ end
179
+
180
+ example "stat with Dir argument works as expected" do
181
+ expect( @stat_dir.class).to eq(@stat.class)
182
+ expect( @stat_dir.path).to eq(@stat.path)
183
+ expect( @stat_dir.block_size).to eq(@stat.block_size)
184
+ expect( @stat_dir.fragment_size).to eq(@stat.fragment_size)
185
+ expect( @stat_dir.blocks).to eq(@stat.blocks)
186
+ expect( @stat_dir.blocks_free).to eq(@stat.blocks_free)
187
+ expect( @stat_dir.blocks_available).to eq(@stat.blocks_available)
188
+ expect( @stat_dir.files).to eq(@stat.files)
189
+ expect( @stat_dir.files_free).to eq(@stat.files_free)
190
+ expect( @stat_dir.files_available).to eq(@stat.files_available)
191
+ expect( @stat_dir.filesystem_id).to eq(@stat.filesystem_id)
192
+ expect( @stat_dir.flags).to eq(@stat.flags)
193
+ expect( @stat_dir.name_max).to eq(@stat.name_max)
194
+ expect( @stat_dir.base_type).to eq(@stat.base_type)
195
+ end
196
+ end
197
+
198
+ context "mount_point" do
199
+ example "mount_point singleton method basic functionality" do
200
+ expect(Sys::Filesystem).to respond_to(:mount_point)
201
+ expect{ Sys::Filesystem.mount_point(Dir.pwd) }.not_to raise_error
202
+ expect(Sys::Filesystem.mount_point(Dir.pwd)).to be_kind_of(String)
203
+ end
204
+
205
+ example "mount_point singleton method returns expected value" do
206
+ expect(Sys::Filesystem.mount_point("C:\\Users\\foo")).to eq("C:\\")
207
+ expect(Sys::Filesystem.mount_point("//foo/bar/baz")).to eq("\\\\foo\\bar")
208
+ end
209
+
210
+ example "mount_point works with Pathname object" do
211
+ expect{ Sys::Filesystem.mount_point(Pathname.new("C:/Users/foo")) }.not_to raise_error
212
+ expect(Sys::Filesystem.mount_point("C:\\Users\\foo")).to eq("C:\\")
213
+ expect(Sys::Filesystem.mount_point("//foo/bar/baz")).to eq("\\\\foo\\bar")
214
+ end
215
+ end
216
+
217
+ example "filesystem constants are defined" do
218
+ expect(Sys::Filesystem::CASE_SENSITIVE_SEARCH).not_to be_nil
219
+ expect(Sys::Filesystem::CASE_PRESERVED_NAMES).not_to be_nil
220
+ expect(Sys::Filesystem::UNICODE_ON_DISK).not_to be_nil
221
+ expect(Sys::Filesystem::PERSISTENT_ACLS).not_to be_nil
222
+ expect(Sys::Filesystem::FILE_COMPRESSION).not_to be_nil
223
+ expect(Sys::Filesystem::VOLUME_QUOTAS).not_to be_nil
224
+ expect(Sys::Filesystem::SUPPORTS_SPARSE_FILES).not_to be_nil
225
+ expect(Sys::Filesystem::SUPPORTS_REPARSE_POINTS).not_to be_nil
226
+ expect(Sys::Filesystem::SUPPORTS_REMOTE_STORAGE).not_to be_nil
227
+ expect(Sys::Filesystem::VOLUME_IS_COMPRESSED).not_to be_nil
228
+ expect(Sys::Filesystem::SUPPORTS_OBJECT_IDS).not_to be_nil
229
+ expect(Sys::Filesystem::SUPPORTS_ENCRYPTION).not_to be_nil
230
+ expect(Sys::Filesystem::NAMED_STREAMS).not_to be_nil
231
+ expect(Sys::Filesystem::READ_ONLY_VOLUME).not_to be_nil
232
+ end
233
+
234
+ example "stat singleton method defaults to root path if proviced" do
235
+ expect{ Sys::Filesystem.stat("C://Program Files") }.not_to raise_error
236
+ end
237
+
238
+ example "stat singleton method accepts a Pathname object" do
239
+ expect{ Sys::Filesystem.stat(Pathname.new("C://Program Files")) }.not_to raise_error
240
+ end
241
+
242
+ example "stat singleton method requires a single argument" do
243
+ expect{ Sys::Filesystem.stat }.to raise_error(ArgumentError)
244
+ expect{ Sys::Filesystem.stat(Dir.pwd, Dir.pwd) }.to raise_error(ArgumentError)
245
+ end
246
+
247
+ example "stat singleton method raises an error if path is not found" do
248
+ expect{ Sys::Filesystem.stat("C://Bogus//Dir") }.to raise_error(Errno::ESRCH)
249
+ end
250
+
251
+ context "Filesystem::Mount" do
252
+ let(:mount){ Sys::Filesystem.mounts[0] }
253
+
254
+ before do
255
+ @array = []
256
+ end
257
+
258
+ example "mount singleton method exists" do
259
+ expect(Sys::Filesystem).to respond_to(:mount)
260
+ end
261
+
262
+ example "umount singleton method exists" do
263
+ expect(Sys::Filesystem).to respond_to(:umount)
264
+ end
265
+
266
+ example "mounts singleton method basic functionality" do
267
+ expect(Sys::Filesystem).to respond_to(:mounts)
268
+ expect{ Sys::Filesystem.mounts }.not_to raise_error
269
+ expect{ Sys::Filesystem.mounts{}.not_to raise_error }
270
+ end
271
+
272
+ example "mounts singleton method returns the expected value" do
273
+ expect(Sys::Filesystem.mounts).to be_kind_of(Array)
274
+ expect(Sys::Filesystem.mounts[0]).to be_kind_of(Sys::Filesystem::Mount)
275
+ end
276
+
277
+ example "mounts singleton method works as expected when a block is provided" do
278
+ expect(Sys::Filesystem.mounts{}).to be_nil
279
+ expect{ Sys::Filesystem.mounts{ |mt| @array << mt } }.not_to raise_error
280
+ expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
281
+ end
282
+
283
+ example "mount name works as expected" do
284
+ expect(mount).to respond_to(:name)
285
+ expect(mount.name).to be_kind_of(String)
286
+ end
287
+
288
+ example "mount_time works as expected" do
289
+ expect(mount).to respond_to(:mount_time)
290
+ expect(mount.mount_time).to be_kind_of(Time)
291
+ end
292
+
293
+ example "mount type works as expected" do
294
+ expect(mount).to respond_to(:mount_type)
295
+ expect(mount.mount_type).to be_kind_of(String)
296
+ end
297
+
298
+ example "mount point works as expected" do
299
+ expect(mount).to respond_to(:mount_point)
300
+ expect(mount.mount_point).to be_kind_of(String)
301
+ end
302
+
303
+ example "mount options works as expected" do
304
+ expect(mount).to respond_to(:options)
305
+ expect(mount.options).to be_kind_of(String)
306
+ end
307
+
308
+ example "mount pass_number works as expected" do
309
+ expect(mount).to respond_to(:pass_number)
310
+ expect(mount.pass_number).to be_nil
311
+ end
312
+
313
+ example "mount frequency works as expected" do
314
+ expect(mount).to respond_to(:frequency)
315
+ expect(mount.frequency).to be_nil
316
+ end
317
+
318
+ example "mounts singleton method does not accept any arguments" do
319
+ expect{ Sys::Filesystem.mounts("C:\\") }.to raise_error(ArgumentError)
320
+ end
321
+ end
322
+
323
+ example "custom Numeric#to_kb method works as expected" do
324
+ expect(@size).to respond_to(:to_kb)
325
+ expect(@size.to_kb).to eq(57344)
326
+ end
327
+
328
+ example "custom Numeric#to_mb method works as expected" do
329
+ expect(@size).to respond_to(:to_mb)
330
+ expect(@size.to_mb).to eq(56)
331
+ end
332
+
333
+ example "custom Numeric#to_gb method works as expected" do
334
+ expect(@size).to respond_to(:to_gb)
335
+ expect(@size.to_gb).to eq(0)
336
+ end
337
+
338
+ context "FFI" do
339
+ example "internal ffi functions are not public" do
340
+ expect(Sys::Filesystem.methods.include?(:GetVolumeInformationA)).to eq(false)
341
+ expect(Sys::Filesystem.instance_methods.include?(:GetVolumeInformationA)).to eq(false)
342
+ end
343
+ end
344
+ end