sys-filesystem 1.1.1 → 1.5.1

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.
@@ -1,257 +0,0 @@
1
- ####################################################################
2
- # test_sys_filesystem_unix.rb
3
- #
4
- # Test case for the Sys::Filesystem.stat method and related stuff.
5
- # This test suite should be run via the 'rake test' task.
6
- ####################################################################
7
- require 'test-unit'
8
- require 'sys/filesystem'
9
- include Sys
10
-
11
- class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
12
- def self.startup
13
- @@solaris = RbConfig::CONFIG['host_os'] =~ /solaris/i
14
- @@linux = RbConfig::CONFIG['host_os'] =~ /linux/i
15
- @@freebsd = RbConfig::CONFIG['host_os'] =~ /freebsd/i
16
- @@darwin = RbConfig::CONFIG['host_os'] =~ /darwin/i
17
- end
18
-
19
- def setup
20
- @dir = "/"
21
- @stat = Filesystem.stat(@dir)
22
- @mnt = Filesystem.mounts[0]
23
- @size = 58720256
24
- @array = []
25
- end
26
-
27
- def test_version
28
- assert_equal('1.1.1', Filesystem::VERSION)
29
- end
30
-
31
- def test_stat_path
32
- assert_respond_to(@stat, :path)
33
- assert_equal("/", @stat.path)
34
- end
35
-
36
- def test_stat_block_size
37
- assert_respond_to(@stat, :block_size)
38
- assert_kind_of(Fixnum, @stat.block_size)
39
- end
40
-
41
- def test_block_size_is_a_plausible_value
42
- assert_true(@stat.block_size >= 1024)
43
- assert_true(@stat.block_size <= 16384)
44
- end
45
-
46
- def test_stat_fragment_size
47
- assert_respond_to(@stat, :fragment_size)
48
- assert_kind_of(Fixnum, @stat.fragment_size)
49
- end
50
-
51
- def test_stat_blocks
52
- assert_respond_to(@stat, :blocks)
53
- assert_kind_of(Fixnum, @stat.blocks)
54
- end
55
-
56
- def test_stat_blocks_free
57
- assert_respond_to(@stat, :blocks_free)
58
- assert_kind_of(Fixnum, @stat.blocks_free)
59
- end
60
-
61
- def test_stat_blocks_available
62
- assert_respond_to(@stat, :blocks_available)
63
- assert_kind_of(Fixnum, @stat.blocks_available)
64
- end
65
-
66
- def test_stat_files
67
- assert_respond_to(@stat, :files)
68
- assert_kind_of(Fixnum, @stat.files)
69
- end
70
-
71
- def test_inodes_alias
72
- assert_respond_to(@stat, :inodes)
73
- assert_true(@stat.method(:inodes) == @stat.method(:files))
74
- end
75
-
76
- def test_stat_files_free
77
- assert_respond_to(@stat, :files_free)
78
- assert_kind_of(Fixnum, @stat.files_free)
79
- end
80
-
81
- def test_stat_inodes_free_alias
82
- assert_respond_to(@stat, :inodes_free)
83
- assert_true(@stat.method(:inodes_free) == @stat.method(:files_free))
84
- end
85
-
86
- def test_stat_files_available
87
- assert_respond_to(@stat, :files_available)
88
- assert_kind_of(Fixnum, @stat.files_available)
89
- end
90
-
91
- def test_stat_inodes_available_alias
92
- assert_respond_to(@stat, :inodes_available)
93
- assert_true(@stat.method(:inodes_available) == @stat.method(:files_available))
94
- end
95
-
96
- def test_stat_filesystem_id
97
- assert_respond_to(@stat, :filesystem_id)
98
- assert_kind_of(Integer, @stat.filesystem_id)
99
- end
100
-
101
- def test_stat_flags
102
- assert_respond_to(@stat, :flags)
103
- assert_kind_of(Fixnum, @stat.flags)
104
- end
105
-
106
- def test_stat_name_max
107
- assert_respond_to(@stat, :name_max)
108
- assert_kind_of(Fixnum, @stat.name_max)
109
- end
110
-
111
- def test_stat_base_type
112
- omit_unless(@@solaris, "base_type test skipped except on Solaris")
113
-
114
- assert_respond_to(@stat, :base_type)
115
- assert_kind_of(String, @stat.base_type)
116
- end
117
-
118
- def test_stat_constants
119
- assert_not_nil(Filesystem::Stat::RDONLY)
120
- assert_not_nil(Filesystem::Stat::NOSUID)
121
-
122
- omit_unless(@@solaris, "NOTRUNC test skipped except on Solaris")
123
-
124
- assert_not_nil(Filesystem::Stat::NOTRUNC)
125
- end
126
-
127
- def test_stat_expected_errors
128
- assert_raises(ArgumentError){ Filesystem.stat }
129
- end
130
-
131
- def test_fixnum_methods_basic
132
- assert_respond_to(@size, :to_kb)
133
- assert_respond_to(@size, :to_mb)
134
- assert_respond_to(@size, :to_gb)
135
- end
136
-
137
- def test_to_kb
138
- assert_equal(57344, @size.to_kb)
139
- end
140
-
141
- def test_to_mb
142
- assert_equal(56, @size.to_mb)
143
- end
144
-
145
- def test_to_gb
146
- assert_equal(0, @size.to_gb)
147
- end
148
-
149
- # Filesystem::Mount tests
150
-
151
- def test_mounts_with_no_block
152
- assert_nothing_raised{ @array = Filesystem.mounts }
153
- assert_kind_of(Filesystem::Mount, @array[0])
154
- end
155
-
156
- def test_mounts_with_block
157
- assert_nothing_raised{ Filesystem.mounts{ |m| @array << m } }
158
- assert_kind_of(Filesystem::Mount, @array[0])
159
- end
160
-
161
- def test_mounts_high_iteration
162
- assert_nothing_raised{ 1000.times{ @array = Filesystem.mounts } }
163
- end
164
-
165
- def test_mount_name
166
- assert_respond_to(@mnt, :name)
167
- assert_kind_of(String, @mnt.name)
168
- end
169
-
170
- def test_fsname_alias
171
- assert_respond_to(@mnt, :fsname)
172
- assert_true(@mnt.method(:fsname) == @mnt.method(:name))
173
- end
174
-
175
- def test_mount_point
176
- assert_respond_to(@mnt, :mount_point)
177
- assert_kind_of(String, @mnt.mount_point)
178
- end
179
-
180
- def test_dir_alias
181
- assert_respond_to(@mnt, :dir)
182
- assert_true(@mnt.method(:dir) == @mnt.method(:mount_point))
183
- end
184
-
185
- def test_mount_type
186
- assert_respond_to(@mnt, :mount_type)
187
- assert_kind_of(String, @mnt.mount_type)
188
- end
189
-
190
- def test_mount_options
191
- assert_respond_to(@mnt, :options)
192
- assert_kind_of(String, @mnt.options)
193
- end
194
-
195
- def test_opts_alias
196
- assert_respond_to(@mnt, :opts)
197
- assert_true(@mnt.method(:opts) == @mnt.method(:options))
198
- end
199
-
200
- def test_mount_time
201
- assert_respond_to(@mnt, :mount_time)
202
-
203
- if @@solaris
204
- assert_kind_of(Time, @mnt.mount_time)
205
- else
206
- assert_nil(@mnt.mount_time)
207
- end
208
- end
209
-
210
- def test_mount_dump_frequency
211
- msg = 'dump_frequency test skipped on this platform'
212
- omit_if(@@solaris || @@freebsd || @@darwin, msg)
213
- assert_respond_to(@mnt, :dump_frequency)
214
- assert_kind_of(Fixnum, @mnt.dump_frequency)
215
- end
216
-
217
- def test_freq_alias
218
- assert_respond_to(@mnt, :freq)
219
- assert_true(@mnt.method(:freq) == @mnt.method(:dump_frequency))
220
- end
221
-
222
- def test_mount_pass_number
223
- msg = 'pass_number test skipped on this platform'
224
- omit_if(@@solaris || @@freebsd || @@darwin, msg)
225
- assert_respond_to(@mnt, :pass_number)
226
- assert_kind_of(Fixnum, @mnt.pass_number)
227
- end
228
-
229
- def test_passno_alias
230
- assert_respond_to(@mnt, :passno)
231
- assert_true(@mnt.method(:passno) == @mnt.method(:pass_number))
232
- end
233
-
234
- def test_mount_point_singleton
235
- assert_respond_to(Filesystem, :mount_point)
236
- assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
237
- assert_kind_of(String, Filesystem.mount_point(Dir.pwd))
238
- end
239
-
240
- def test_ffi_functions_are_private
241
- assert_false(Filesystem.methods.include?('statvfs'))
242
- assert_false(Filesystem.methods.include?('strerror'))
243
- end
244
-
245
- def teardown
246
- @dir = nil
247
- @stat = nil
248
- @array = nil
249
- end
250
-
251
- def self.shutdown
252
- @@solaris = nil
253
- @@linux = nil
254
- @@freebsd = nil
255
- @@darwin = nil
256
- end
257
- end
@@ -1,222 +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
- include Sys
11
-
12
- class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
13
- def setup
14
- @dir = '/'
15
- @stat = Filesystem.stat(@dir)
16
- @mount = Filesystem.mounts[0]
17
- @size = 58720256
18
- @array = []
19
- end
20
-
21
- test "version number is set to the expected value" do
22
- assert_equal('1.1.1', Filesystem::VERSION)
23
- end
24
-
25
- test "stat path works as expected" do
26
- assert_respond_to(@stat, :path)
27
- assert_equal("/", @stat.path)
28
- end
29
-
30
- test "stat block_size works as expected" do
31
- assert_respond_to(@stat, :block_size)
32
- assert_kind_of(Fixnum, @stat.block_size)
33
- end
34
-
35
- test "stat fragment_size works as expected" do
36
- assert_respond_to(@stat, :fragment_size)
37
- assert_nil(@stat.fragment_size)
38
- end
39
-
40
- test "stat blocks works as expected" do
41
- assert_respond_to(@stat, :blocks)
42
- assert_kind_of(Fixnum, @stat.blocks)
43
- end
44
-
45
- test "stat blocks_free works as expected" do
46
- assert_respond_to(@stat, :blocks_free)
47
- assert_kind_of(Fixnum, @stat.blocks_free)
48
- end
49
-
50
- test "stat blocks_available works as expected" do
51
- assert_respond_to(@stat, :blocks_available)
52
- assert_kind_of(Fixnum, @stat.blocks_available)
53
- end
54
-
55
- test "stat files works as expected" do
56
- assert_respond_to(@stat, :files)
57
- assert_nil(@stat.files)
58
- end
59
-
60
- test "stat inodes is an alias for files" do
61
- assert_alias_method(@stat, :inodes, :files)
62
- end
63
-
64
- test "stat files_free works as expected" do
65
- assert_respond_to(@stat, :files_free)
66
- assert_nil(@stat.files_free)
67
- end
68
-
69
- test "stat inodes_free is an alias for files_free" do
70
- assert_respond_to(@stat, :inodes_free)
71
- end
72
-
73
- test "stat files available works as expected" do
74
- assert_respond_to(@stat, :files_available)
75
- assert_nil(@stat.files_available)
76
- end
77
-
78
- test "stat inodes_available is an alias for files_available" do
79
- assert_alias_method(@stat, :inodes_available, :files_available)
80
- end
81
-
82
- test "stat filesystem_id works as expected" do
83
- assert_respond_to(@stat, :filesystem_id)
84
- assert_kind_of(Integer, @stat.filesystem_id)
85
- end
86
-
87
- test "stat flags works as expected" do
88
- assert_respond_to(@stat, :flags)
89
- assert_kind_of(Fixnum, @stat.flags)
90
- end
91
-
92
- test "stat name_max works as expected" do
93
- assert_respond_to(@stat, :name_max)
94
- assert_kind_of(Fixnum, @stat.name_max)
95
- end
96
-
97
- test "stat base_type works as expected" do
98
- assert_respond_to(@stat, :base_type)
99
- assert_kind_of(String, @stat.base_type)
100
- end
101
-
102
- test "mount_point singleton method basic functionality" do
103
- assert_respond_to(Filesystem, :mount_point)
104
- assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
105
- assert_kind_of(String, Filesystem.mount_point(Dir.pwd))
106
- end
107
-
108
- test "mount_point singleton method returns expected value" do
109
- assert_equal("C:\\", Filesystem.mount_point("C:\\Users\\foo"))
110
- assert_equal("\\\\foo\\bar", Filesystem.mount_point("//foo/bar/baz"))
111
- end
112
-
113
- test "filesystem constants are defined" do
114
- assert_not_nil(Filesystem::CASE_SENSITIVE_SEARCH)
115
- assert_not_nil(Filesystem::CASE_PRESERVED_NAMES)
116
- assert_not_nil(Filesystem::UNICODE_ON_DISK)
117
- assert_not_nil(Filesystem::PERSISTENT_ACLS)
118
- assert_not_nil(Filesystem::FILE_COMPRESSION)
119
- assert_not_nil(Filesystem::VOLUME_QUOTAS)
120
- assert_not_nil(Filesystem::SUPPORTS_SPARSE_FILES)
121
- assert_not_nil(Filesystem::SUPPORTS_REPARSE_POINTS)
122
- assert_not_nil(Filesystem::SUPPORTS_REMOTE_STORAGE)
123
- assert_not_nil(Filesystem::VOLUME_IS_COMPRESSED)
124
- assert_not_nil(Filesystem::SUPPORTS_OBJECT_IDS)
125
- assert_not_nil(Filesystem::SUPPORTS_ENCRYPTION)
126
- assert_not_nil(Filesystem::NAMED_STREAMS)
127
- assert_not_nil(Filesystem::READ_ONLY_VOLUME)
128
- end
129
-
130
- test "stat singleton method requires a single argument" do
131
- assert_raise(ArgumentError){ Filesystem.stat }
132
- assert_raise(ArgumentError){ Filesystem.stat(Dir.pwd, Dir.pwd) }
133
- end
134
-
135
- # Filesystem.mounts
136
-
137
- test "mounts singleton method basic functionality" do
138
- assert_respond_to(Filesystem, :mounts)
139
- assert_nothing_raised{ Filesystem.mounts }
140
- assert_nothing_raised{ Filesystem.mounts{} }
141
- end
142
-
143
- test "mounts singleton method returns the expected value" do
144
- assert_kind_of(Array, Filesystem.mounts)
145
- assert_kind_of(Filesystem::Mount, Filesystem.mounts[0])
146
- end
147
-
148
- test "mounts singleton method works as expected when a block is provided" do
149
- assert_nil(Filesystem.mounts{})
150
- assert_nothing_raised{ Filesystem.mounts{ |mt| @array << mt }}
151
- assert_kind_of(Filesystem::Mount, @array[0])
152
- end
153
-
154
- test "mount name works as expected" do
155
- assert_respond_to(@mount, :name)
156
- assert_kind_of(String, @mount.name)
157
- end
158
-
159
- test "mount time works as expected" do
160
- assert_respond_to(@mount, :mount_time)
161
- assert_kind_of(Time, @mount.mount_time)
162
- end
163
-
164
- test "mount type works as expected" do
165
- assert_respond_to(@mount, :mount_type)
166
- assert_kind_of(String, @mount.mount_type)
167
- end
168
-
169
- test "mount point works as expected" do
170
- assert_respond_to(@mount, :mount_point)
171
- assert_kind_of(String, @mount.mount_point)
172
- end
173
-
174
- test "mount options works as expected" do
175
- assert_respond_to(@mount, :options)
176
- assert_kind_of(String, @mount.options)
177
- end
178
-
179
- test "mount pass_number works as expected" do
180
- assert_respond_to(@mount, :pass_number)
181
- assert_nil(@mount.pass_number)
182
- end
183
-
184
- test "mount frequency works as expected" do
185
- assert_respond_to(@mount, :frequency)
186
- assert_nil(@mount.frequency)
187
- end
188
-
189
- test "mounts singleton method does not accept any arguments" do
190
- assert_raise(ArgumentError){ Filesystem.mounts("C:\\") }
191
- end
192
-
193
- test "custom Fixnum#to_kb method works as expected" do
194
- assert_respond_to(@size, :to_kb)
195
- assert_equal(57344, @size.to_kb)
196
- end
197
-
198
- test "custom Fixnum#to_mb method works as expected" do
199
- assert_respond_to(@size, :to_mb)
200
- assert_equal(56, @size.to_mb)
201
- end
202
-
203
- test "custom Fixnum#to_gb method works as expected" do
204
- assert_respond_to(@size, :to_gb)
205
- assert_equal(0, @size.to_gb)
206
- end
207
-
208
- # FFI
209
-
210
- test "internal ffi functions are not public" do
211
- assert_false(Filesystem.methods.include?(:GetVolumeInformationA))
212
- assert_false(Filesystem.instance_methods.include?(:GetVolumeInformationA))
213
- end
214
-
215
- def teardown
216
- @array = nil
217
- @dir = nil
218
- @stat = nil
219
- @size = nil
220
- @mount = nil
221
- end
222
- end