win32-file-stat 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.3.2 - 1-Oct-2008
2
+ * Fixed an issue with the private get_blksize method.
3
+ * Updated the test suite to use Test::Unit 2.x, which also makes it a
4
+ required dependency.
5
+ * Removed the pre-generated .txt and .exe files that were used for testing.
6
+ These are now generated within the test suite itself.
7
+ * Fixed two broken size tests, and now omits one blockdev test if there's no
8
+ media in the drive.
9
+
1
10
  == 1.3.1 - 9-Aug-2008
2
11
  * Fixed the stat buf to be the proper size (I had too many struct members).
3
12
  * Modified the tests slightly.
data/MANIFEST CHANGED
@@ -4,6 +4,4 @@
4
4
  * Rakefile
5
5
  * win32-file-stat.gemspec
6
6
  * lib/win32/file/stat.rb
7
- * test/sometestfile.exe
8
- * test/sometestfile.txt
9
- * test/test_file_stat.rb
7
+ * test/test_file_stat.rb
@@ -21,7 +21,7 @@ class File::Stat
21
21
  include Windows::Volume
22
22
  include Comparable
23
23
 
24
- VERSION = '1.3.1'
24
+ VERSION = '1.3.2'
25
25
 
26
26
  private
27
27
 
@@ -548,14 +548,15 @@ class File::Stat
548
548
  # The dup is necessary here because the function modifies the argument.
549
549
  file = file.dup
550
550
 
551
- if PathStripToRootW(file)
552
- file += "\\" unless file[-1].chr == "\\"
551
+ if PathStripToRootA(wide_to_multi(file))
552
+ file = file[/^[^\0]*/] << ':'
553
+ file << "\\" unless file[-1].chr == "\\"
553
554
  else
554
555
  file = nil # Default to the root drive on relative paths
555
556
  end
556
557
 
557
558
  # Don't check for an error here. Just default to nil.
558
- if GetDiskFreeSpaceW(file, sectors, bytes, free, total)
559
+ if GetDiskFreeSpaceA(file, sectors, bytes, free, total)
559
560
  size = sectors.unpack('L').first * bytes.unpack('L').first
560
561
  end
561
562
 
@@ -4,37 +4,46 @@
4
4
  # Test case for stat related methods of win32-file. You should use
5
5
  # the 'rake test' task to run these tests.
6
6
  #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
7
9
  require 'test/unit'
8
10
  require 'win32/file/stat'
9
11
  include Windows::Volume
10
12
 
11
- # Find a block device
12
- 'A'.upto('Z'){ |volume|
13
- volume += ":\\"
14
- case GetDriveType(volume)
15
- when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
16
- $block_dev = volume
17
- break
18
- end
19
- }
20
-
21
13
  class TC_Win32_File_Stat < Test::Unit::TestCase
22
14
  include Windows::File
15
+
16
+ def self.startup
17
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
18
+
19
+ 'A'.upto('Z'){ |volume|
20
+ volume += ":\\"
21
+ case GetDriveType(volume)
22
+ when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
23
+ @@block_dev = volume
24
+ break
25
+ end
26
+ }
27
+
28
+ @@txt_file = 'test_file.txt'
29
+ @@exe_file = 'test_file.exe'
30
+
31
+ File.open(@@txt_file, "w"){ |fh| fh.print "This is a test\nHello" }
32
+ File.open(@@exe_file, "wb"){ |fh| fh.print "This is a test" }
33
+ end
23
34
 
24
35
  def setup
25
- Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
26
- @file = 'sometestfile.txt'
27
- @exe = 'sometestfile.exe'
28
- @dir = Dir.pwd
29
- @stat = File::Stat.new(@file)
30
- @attr = GetFileAttributes(@file)
36
+ @dir = Dir.pwd
37
+ @stat = File::Stat.new(@@txt_file)
38
+ @attr = GetFileAttributes(@@txt_file)
31
39
  end
32
40
 
33
41
  def test_version
34
- assert_equal('1.3.1', File::Stat::VERSION)
42
+ assert_equal('1.3.2', File::Stat::VERSION)
35
43
  end
36
44
 
37
- # One or more tests will fail if the archive attribute on @file is not set.
45
+ # One or more tests will fail if the archive attribute on @@text_file
46
+ # is not set.
38
47
  def test_archive
39
48
  assert_respond_to(@stat, :archive?)
40
49
  assert_nothing_raised{ @stat.archive? }
@@ -57,7 +66,12 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
57
66
  assert_respond_to(@stat, :blockdev?)
58
67
  assert_equal(false, @stat.blockdev?)
59
68
  assert_equal(false, File::Stat.new('NUL').blockdev?)
60
- assert_equal(true, File::Stat.new($block_dev).blockdev?)
69
+
70
+ begin
71
+ assert_equal(true, File::Stat.new(@@block_dev).blockdev?)
72
+ rescue SystemCallError
73
+ omit("Skipping because drive is empty")
74
+ end
61
75
  end
62
76
 
63
77
  def test_blocks
@@ -74,7 +88,7 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
74
88
 
75
89
  def test_comparison
76
90
  assert_respond_to(@stat, :<=>)
77
- assert_nothing_raised{ @stat <=> File::Stat.new(@exe) }
91
+ assert_nothing_raised{ @stat <=> File::Stat.new(@@exe_file) }
78
92
  end
79
93
 
80
94
  def test_compressed
@@ -113,19 +127,19 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
113
127
  def test_executable
114
128
  assert_respond_to(@stat, :executable?)
115
129
  assert_equal(false, @stat.executable?)
116
- assert_equal(true, File::Stat.new(@exe).executable?)
130
+ assert_equal(true, File::Stat.new(@@exe_file).executable?)
117
131
  end
118
132
 
119
133
  def test_executable_real
120
134
  assert_respond_to(@stat, :executable_real?)
121
135
  assert_equal(false, @stat.executable_real?)
122
- assert_equal(true, File::Stat.new(@exe).executable_real?)
136
+ assert_equal(true, File::Stat.new(@@exe_file).executable_real?)
123
137
  end
124
138
 
125
139
  def test_file
126
140
  assert_respond_to(@stat, :file?)
127
141
  assert_equal(true, @stat.file?)
128
- assert_equal(true, File::Stat.new(@exe).file?)
142
+ assert_equal(true, File::Stat.new(@@exe_file).file?)
129
143
  assert_equal(true, File::Stat.new(Dir.pwd).file?)
130
144
  assert_equal(false, File::Stat.new('NUL').file?)
131
145
  end
@@ -175,12 +189,12 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
175
189
 
176
190
  def test_mode
177
191
  assert_respond_to(@stat, :mode)
178
- assert_equal(33188, File::Stat.new(@file).mode)
179
- assert_equal(33261, File::Stat.new(@exe).mode)
192
+ assert_equal(33188, File::Stat.new(@@txt_file).mode)
193
+ assert_equal(33261, File::Stat.new(@@exe_file).mode)
180
194
  assert_equal(16877, File::Stat.new(@dir).mode)
181
195
 
182
- SetFileAttributes(@file, 1) # Set to readonly.
183
- assert_equal(33060, File::Stat.new(@file).mode)
196
+ SetFileAttributes(@@txt_file, 1) # Set to readonly.
197
+ assert_equal(33060, File::Stat.new(@@txt_file).mode)
184
198
  end
185
199
 
186
200
  def test_mtime
@@ -251,12 +265,12 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
251
265
 
252
266
  def test_size
253
267
  assert_respond_to(@stat, :size)
254
- assert_equal(20, @stat.size)
268
+ assert_equal(21, @stat.size)
255
269
  end
256
270
 
257
271
  def test_size_bool
258
272
  assert_respond_to(@stat, :size?)
259
- assert_equal(20, @stat.size?)
273
+ assert_equal(21, @stat.size?)
260
274
  end
261
275
 
262
276
  def test_socket
@@ -313,10 +327,17 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
313
327
  end
314
328
 
315
329
  def teardown
316
- SetFileAttributes(@file, @attr) # Set file back to normal
317
- @file = nil
318
- @exe = nil
330
+ SetFileAttributes(@@txt_file, @attr) # Set file back to normal
319
331
  @dir = nil
320
332
  @stat = nil
333
+ @attr = nil
334
+ end
335
+
336
+ def self.shutdown
337
+ File.delete(@@txt_file) if File.exists?(@@txt_file)
338
+ File.delete(@@exe_file) if File.exists?(@@exe_file)
339
+ @@block_dev = nil
340
+ @@txt_file = nil
341
+ @@exe_file = nil
321
342
  end
322
343
  end
@@ -0,0 +1,343 @@
1
+ #####################################################################
2
+ # test_file_stat.rb
3
+ #
4
+ # Test case for stat related methods of win32-file. You should use
5
+ # the 'rake test' task to run these tests.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+ require 'test/unit'
10
+ require 'win32/file/stat'
11
+ include Windows::Volume
12
+
13
+ class TC_Win32_File_Stat < Test::Unit::TestCase
14
+ include Windows::File
15
+
16
+ def self.startup
17
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
18
+
19
+ 'A'.upto('Z'){ |volume|
20
+ volume += ":\\"
21
+ case GetDriveType(volume)
22
+ when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
23
+ @@block_dev = volume
24
+ break
25
+ end
26
+ }
27
+
28
+ @@txt_file = 'test_file.txt'
29
+ @@exe_file = 'test_file.exe'
30
+
31
+ File.open(@@txt_file, "w"){ |fh| fh.print "This is a test\nHello" }
32
+ File.open(@@exe_file, "wb"){ |fh| fh.print "This is a test" }
33
+ end
34
+
35
+ def setup
36
+ @dir = Dir.pwd
37
+ @stat = File::Stat.new(@@txt_file)
38
+ @attr = GetFileAttributes(@@txt_file)
39
+ end
40
+
41
+ def test_version
42
+ assert_equal('1.3.3', File::Stat::VERSION)
43
+ end
44
+
45
+ # One or more tests will fail if the archive attribute on @@text_file
46
+ # is not set.
47
+ def test_archive
48
+ assert_respond_to(@stat, :archive?)
49
+ assert_nothing_raised{ @stat.archive? }
50
+ assert(@stat.archive?, '=> May fail - ignore')
51
+ end
52
+
53
+ def test_atime
54
+ assert_respond_to(@stat, :atime)
55
+ assert_kind_of(Time, @stat.atime)
56
+ end
57
+
58
+ def test_blksize
59
+ assert_respond_to(@stat, :blksize)
60
+ assert_equal(4096, @stat.blksize)
61
+ assert_equal(4096, File::Stat.new("C:\\").blksize)
62
+ end
63
+
64
+ # The block dev test error out if there's no media in it.
65
+ def test_blockdev
66
+ assert_respond_to(@stat, :blockdev?)
67
+ assert_equal(false, @stat.blockdev?)
68
+ assert_equal(false, File::Stat.new('NUL').blockdev?)
69
+
70
+ begin
71
+ assert_equal(true, File::Stat.new(@@block_dev).blockdev?)
72
+ rescue SystemCallError
73
+ omit("Skipping because drive is empty")
74
+ end
75
+ end
76
+
77
+ def test_blocks
78
+ assert_respond_to(@stat, :blocks)
79
+ assert_equal(1, @stat.blocks)
80
+ end
81
+
82
+ def test_chardev
83
+ assert_respond_to(@stat, :chardev?)
84
+ assert_nothing_raised{ File::Stat.new("NUL").chardev? }
85
+ assert_equal(true, File::Stat.new("NUL").chardev?)
86
+ assert_equal(false, File::Stat.new("C:\\").chardev?)
87
+ end
88
+
89
+ def test_comparison
90
+ assert_respond_to(@stat, :<=>)
91
+ assert_nothing_raised{ @stat <=> File::Stat.new(@@exe_file) }
92
+ end
93
+
94
+ def test_compressed
95
+ assert_respond_to(@stat, :compressed?)
96
+ assert_nothing_raised{ @stat.compressed? }
97
+ assert_equal(false, @stat.compressed?)
98
+ end
99
+
100
+ def test_ctime
101
+ assert_respond_to(@stat, :ctime)
102
+ assert_kind_of(Time, @stat.ctime)
103
+ end
104
+
105
+ # Assumes you've installed on C: drive.
106
+ def test_dev
107
+ assert_respond_to(@stat, :dev)
108
+ assert_equal('C:', @stat.dev)
109
+ end
110
+
111
+ def test_dev_major
112
+ assert_respond_to(@stat, :dev_major)
113
+ assert_nil(@stat.dev_major)
114
+ end
115
+
116
+ def test_dev_minor
117
+ assert_respond_to(@stat, :dev_minor)
118
+ assert_nil(@stat.dev_minor)
119
+ end
120
+
121
+ def test_directory
122
+ assert_respond_to(@stat, :directory?)
123
+ assert_equal(false, @stat.directory?)
124
+ assert_equal(true, File::Stat.new("C:\\").directory?)
125
+ end
126
+
127
+ def test_executable
128
+ assert_respond_to(@stat, :executable?)
129
+ assert_equal(false, @stat.executable?)
130
+ assert_equal(true, File::Stat.new(@@exe_file).executable?)
131
+ end
132
+
133
+ def test_executable_real
134
+ assert_respond_to(@stat, :executable_real?)
135
+ assert_equal(false, @stat.executable_real?)
136
+ assert_equal(true, File::Stat.new(@@exe_file).executable_real?)
137
+ end
138
+
139
+ def test_file
140
+ assert_respond_to(@stat, :file?)
141
+ assert_equal(true, @stat.file?)
142
+ assert_equal(true, File::Stat.new(@@exe_file).file?)
143
+ assert_equal(true, File::Stat.new(Dir.pwd).file?)
144
+ assert_equal(false, File::Stat.new('NUL').file?)
145
+ end
146
+
147
+ def test_ftype
148
+ assert_respond_to(@stat, :ftype)
149
+ assert_equal('file', @stat.ftype)
150
+ assert_equal('characterSpecial', File::Stat.new('NUL').ftype)
151
+ assert_equal('directory', File::Stat.new(Dir.pwd).ftype)
152
+ end
153
+
154
+ def encrypted
155
+ assert_respond_to(@stat, :encrypted?)
156
+ assert_nothing_raised{ @stat.encrypted? }
157
+ end
158
+
159
+ def test_gid
160
+ assert_respond_to(@stat, :gid)
161
+ assert_equal(0, @stat.gid)
162
+ end
163
+
164
+ def test_grpowned
165
+ assert_respond_to(@stat, :grpowned?)
166
+ end
167
+
168
+ def test_hidden
169
+ assert_respond_to(@stat, :hidden?)
170
+ assert_nothing_raised{ @stat.hidden? }
171
+ assert_equal(false, @stat.hidden?)
172
+ end
173
+
174
+ def test_indexed
175
+ assert_respond_to(@stat, :indexed?)
176
+ assert_respond_to(@stat, :content_indexed?) # alias
177
+ assert_nothing_raised{ @stat.indexed? }
178
+ assert(@stat.indexed?)
179
+ end
180
+
181
+ def test_ino
182
+ assert_respond_to(@stat, :ino)
183
+ assert_equal(0, @stat.ino)
184
+ end
185
+
186
+ def test_inspect
187
+ assert_respond_to(@stat, :inspect)
188
+ end
189
+
190
+ def test_mode
191
+ assert_respond_to(@stat, :mode)
192
+ assert_equal(33188, File::Stat.new(@@txt_file).mode)
193
+ assert_equal(33261, File::Stat.new(@@exe_file).mode)
194
+ assert_equal(16877, File::Stat.new(@dir).mode)
195
+
196
+ SetFileAttributes(@@txt_file, 1) # Set to readonly.
197
+ assert_equal(33060, File::Stat.new(@@txt_file).mode)
198
+ end
199
+
200
+ def test_mtime
201
+ assert_respond_to(@stat, :mtime)
202
+ assert_kind_of(Time, @stat.mtime)
203
+ end
204
+
205
+ def test_nlink
206
+ assert_respond_to(@stat, :nlink)
207
+ assert_equal(1, @stat.nlink)
208
+ end
209
+
210
+ def test_normal
211
+ assert_respond_to(@stat, :normal?)
212
+ assert_nothing_raised{ @stat.normal? }
213
+ assert_equal(false, @stat.normal?)
214
+ end
215
+
216
+ def test_offline
217
+ assert_respond_to(@stat, :offline?)
218
+ assert_nothing_raised{ @stat.offline? }
219
+ assert_equal(false, @stat.offline?)
220
+ end
221
+
222
+ def test_pipe
223
+ assert_respond_to(@stat, :pipe?)
224
+ assert_equal(false, @stat.pipe?)
225
+ end
226
+
227
+ def test_readable
228
+ assert_respond_to(@stat, :readable?)
229
+ assert_equal(true, @stat.readable?)
230
+ end
231
+
232
+ def test_readable_real
233
+ assert_respond_to(@stat, :readable_real?)
234
+ assert_equal(true, @stat.readable_real?)
235
+ end
236
+
237
+ def test_readonly
238
+ assert_respond_to(@stat, :readonly?)
239
+ assert_nothing_raised{ @stat.readonly? }
240
+ assert_equal(false, @stat.readonly?)
241
+ end
242
+
243
+ def test_reparse_point
244
+ assert_respond_to(@stat, :reparse_point?)
245
+ assert_nothing_raised{ @stat.reparse_point? }
246
+ assert_equal(false, @stat.reparse_point?)
247
+ end
248
+
249
+ # Assumes you've installed on C: drive.
250
+ def test_rdev
251
+ msg = "ignore failure if Ruby is not installed on C: drive"
252
+ assert_respond_to(@stat, :rdev)
253
+ assert_equal(2, @stat.rdev, msg)
254
+ end
255
+
256
+ def test_setgid
257
+ assert_respond_to(@stat, :setgid?)
258
+ assert_equal(false, @stat.setgid?)
259
+ end
260
+
261
+ def test_setuid
262
+ assert_respond_to(@stat, :setuid?)
263
+ assert_equal(false, @stat.setuid?)
264
+ end
265
+
266
+ def test_size
267
+ assert_respond_to(@stat, :size)
268
+ assert_equal(21, @stat.size)
269
+ end
270
+
271
+ def test_size_bool
272
+ assert_respond_to(@stat, :size?)
273
+ assert_equal(21, @stat.size?)
274
+ end
275
+
276
+ def test_socket
277
+ assert_respond_to(@stat, :socket?)
278
+ assert_equal(false, @stat.socket?)
279
+ end
280
+
281
+ def test_sparse
282
+ assert_respond_to(@stat, :sparse?)
283
+ assert_nothing_raised{ @stat.sparse? }
284
+ assert_equal(false, @stat.sparse?)
285
+ end
286
+
287
+ def test_sticky
288
+ assert_respond_to(@stat, :sticky?)
289
+ assert_equal(false, @stat.sticky?)
290
+ end
291
+
292
+ def test_symlink
293
+ assert_respond_to(@stat, :symlink?)
294
+ assert_equal(false, @stat.symlink?)
295
+ end
296
+
297
+ def test_system
298
+ assert_respond_to(@stat, :system?)
299
+ assert_nothing_raised{ @stat.system? }
300
+ assert_equal(false, @stat.system?)
301
+ end
302
+
303
+ def test_temporary
304
+ assert_respond_to(@stat, :temporary?)
305
+ assert_nothing_raised{ @stat.temporary? }
306
+ assert_equal(false, @stat.temporary?)
307
+ end
308
+
309
+ def test_uid
310
+ assert_respond_to(@stat, :uid)
311
+ assert_equal(0, @stat.uid)
312
+ end
313
+
314
+ def test_writable
315
+ assert_respond_to(@stat, :writable?)
316
+ assert_equal(true, @stat.writable?)
317
+ end
318
+
319
+ def test_writable_real
320
+ assert_respond_to(@stat, :writable_real?)
321
+ assert_equal(true, @stat.writable_real?)
322
+ end
323
+
324
+ def test_zero
325
+ assert_respond_to(@stat, :zero?)
326
+ assert_equal(false, @stat.zero?)
327
+ end
328
+
329
+ def teardown
330
+ SetFileAttributes(@@txt_file, @attr) # Set file back to normal
331
+ @dir = nil
332
+ @stat = nil
333
+ @attr = nil
334
+ end
335
+
336
+ def self.shutdown
337
+ File.delete(@@txt_file) if File.exists?(@@txt_file)
338
+ File.delete(@@exe_file) if File.exists?(@@exe_file)
339
+ @@block_dev = nil
340
+ @@txt_file = nil
341
+ @@exe_file = nil
342
+ end
343
+ end
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
4
  gem.name = "win32-file-stat"
5
- gem.version = "1.3.1"
5
+ gem.version = "1.3.2"
6
6
  gem.authors = ["Daniel J. Berger", "Park Heesob"]
7
7
  gem.email = "djberg96@gmail.com"
8
8
  gem.homepage = "http://www.rubyforge.org/projects/win32utils"
@@ -16,6 +16,7 @@ spec = Gem::Specification.new do |gem|
16
16
  gem.require_path = "lib"
17
17
  gem.extra_rdoc_files = ["README", "CHANGES"]
18
18
  gem.add_dependency("windows-pr", ">= 0.9.1")
19
+ gem.add_dependency("test-unit", ">= 2.0.0")
19
20
  gem.rubyforge_project = 'Win32Utils'
20
21
  end
21
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-file-stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-09 00:00:00 -06:00
13
+ date: 2008-10-01 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -23,6 +23,16 @@ dependencies:
23
23
  - !ruby/object:Gem::Version
24
24
  version: 0.9.1
25
25
  version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: test-unit
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.0
35
+ version:
26
36
  description: A File::Stat class tailored to MS Windows
27
37
  email: djberg96@gmail.com
28
38
  executables: []
@@ -41,9 +51,8 @@ files:
41
51
  - README
42
52
  - test
43
53
  - win32-file-stat.gemspec
44
- - test/sometestfile.exe
45
- - test/sometestfile.txt
46
54
  - test/test_file_stat.rb
55
+ - test/test_file_stat.rb~
47
56
  has_rdoc: true
48
57
  homepage: http://www.rubyforge.org/projects/win32utils
49
58
  post_install_message:
@@ -66,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
75
  requirements: []
67
76
 
68
77
  rubyforge_project: Win32Utils
69
- rubygems_version: 1.2.0
78
+ rubygems_version: 1.3.0
70
79
  signing_key:
71
80
  specification_version: 2
72
81
  summary: A File::Stat class tailored to MS Windows
@@ -1 +0,0 @@
1
- This is a test
@@ -1,2 +0,0 @@
1
- This is a test
2
- Hello