win32-file 0.6.9 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,113 +2,283 @@
2
2
  # test_win32_file_stat.rb
3
3
  #
4
4
  # Test case for stat related methods of win32-file. You should run
5
- # this via the 'rake test' or 'rake test_stat' task.
5
+ # this via the 'rake test' or 'rake test:stat' task.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
8
+ require 'fileutils'
11
9
  require 'win32/file'
10
+ require 'win32/security'
11
+ require 'ffi'
12
12
 
13
13
  class TC_Win32_File_Stat < Test::Unit::TestCase
14
- include Windows::Volume
15
- extend Windows::Volume
16
-
17
- def self.startup
18
- Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
19
- @@file = File.join(Dir.pwd, 'stat_test.txt')
20
- File.open(@@file, 'w'){ |fh| fh.puts "This is a test." }
21
-
22
- @@block_dev = nil
23
-
24
- # Find a block device
25
- 'A'.upto('Z'){ |volume|
26
- volume += ":\\"
27
- case GetDriveType(volume)
28
- when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
29
- @@block_dev = volume
30
- break
31
- end
32
- }
33
- end
34
-
35
- # Although I don't perform a test against a file it works in my own tests.
36
- def test_size
37
- assert_respond_to(File, :size)
38
- assert_equal(17, File.size(@@file))
39
- end
40
-
41
- def test_blksize
42
- msg = "+The blksize may be different - ignore+"
43
- assert_respond_to(File, :blksize)
44
- assert_kind_of(Fixnum, File.blksize("C:\\Program Files\\Windows NT"))
45
- assert_kind_of(Fixnum, File.blksize(@@file))
46
- assert_equal(4096, File.blksize(@@file), msg)
47
- end
48
-
49
- def test_blksize_expected_errors
50
- assert_raises(ArgumentError){ File.blksize }
51
- assert_raises(ArgumentError){ File.blksize(@@file, "foo") }
52
- end
53
-
54
- # The test for a block device will fail unless the D: drive is a CDROM.
55
- def test_blockdev
56
- assert_respond_to(File, :blockdev?)
57
- assert_nothing_raised{ File.blockdev?("C:\\") }
58
- assert_equal(false, File.blockdev?("NUL"))
59
-
60
- omit_unless(@@block_dev, "Could not find block device")
61
- omit_unless(File.exists?(@@block_dev), "No media in device - skipping")
62
- assert_equal(true, File.blockdev?(@@block_dev))
63
- end
64
-
65
- def test_blockdev_expected_errors
66
- assert_raises(ArgumentError){ File.blockdev? }
67
- assert_raises(ArgumentError){ File.blockdev?(@@file, "foo") }
68
- end
69
-
70
- def test_chardev
71
- assert_respond_to(File, :chardev?)
72
- assert_nothing_raised{ File.chardev?("NUL") }
73
- assert_equal(true, File.chardev?("NUL"))
74
- assert_equal(false, File.chardev?(@@file))
75
- end
76
-
77
- def test_chardev_expected_errors
78
- assert_raises(ArgumentError){ File.chardev? }
79
- assert_raises(ArgumentError){ File.chardev?(@@file, "foo") }
80
- end
81
-
82
- # Ensure that not only does the File class respond to the stat method,
83
- # but also that it's returning the File::Stat class from the
84
- # win32-file-stat package.
85
- #
86
- def test_stat_class
87
- assert_respond_to(File, :stat)
88
- assert_kind_of(File::Stat, File.stat(@@file))
89
- assert_equal(false, File.stat(@@file).hidden?)
90
- end
91
-
92
- # This was added after it was discovered that lstat is not aliased
93
- # to stat automatically on Windows.
94
- #
95
- def test_lstat_class
96
- assert_respond_to(File, :lstat)
97
- assert_kind_of(File::Stat, File.lstat(@@file))
98
- assert_equal(false, File.stat(@@file).hidden?)
99
- end
100
-
101
- def test_stat_instance
102
- File.open(@@file){ |f|
103
- assert_respond_to(f, :stat)
104
- assert_kind_of(File::Stat, f.stat)
105
- assert_equal(false, f.stat.hidden?)
106
- }
107
- end
108
-
109
- def self.shutdown
110
- File.delete(@@file) if File.exists?(@@file)
111
- @@file = nil
112
- @@block_dev = nil
113
- end
14
+ extend FFI::Library
15
+ ffi_lib :kernel32
16
+
17
+ attach_function :GetDriveTypeA, [:string], :uint
18
+
19
+ def self.startup
20
+ @@txt_file = File.join(Dir.pwd, 'stat_test.txt')
21
+ @@exe_file = File.join(Dir.pwd, 'stat_test.exe')
22
+ @@sys_file = "C:/pagefile.sys"
23
+
24
+ Dir.chdir(File.expand_path(File.dirname(__FILE__)))
25
+ File.open(@@txt_file, 'w'){ |fh| fh.puts "This is a test." }
26
+
27
+ FileUtils.touch(@@exe_file)
28
+
29
+ @@java = RUBY_PLATFORM == 'java'
30
+ @@block_dev = nil
31
+ @@elevated = Win32::Security.elevated_security?
32
+
33
+ # Find a block device
34
+ 'A'.upto('Z'){ |volume|
35
+ volume += ":\\"
36
+ if [2,5,6].include?(GetDriveTypeA(volume))
37
+ @@block_dev = volume
38
+ break
39
+ end
40
+ }
41
+ end
42
+
43
+ def setup
44
+ @blksize = 4096 # Most likely
45
+ end
46
+
47
+ test "File::Stat class returned is from win32-file-stat library" do
48
+ assert_respond_to(File, :stat)
49
+ assert_kind_of(File::Stat, File.stat(@@txt_file))
50
+ assert_nothing_raised{ File.stat(@@txt_file).hidden? }
51
+ end
52
+
53
+ test "blksize basic functionality" do
54
+ assert_respond_to(File, :blksize)
55
+ assert_kind_of(Fixnum, File.blksize(@@txt_file))
56
+ end
57
+
58
+ test "blksize returns the expected value" do
59
+ assert_equal(@blksize, File.blksize(@@txt_file))
60
+ assert_equal(@blksize, File.blksize("C:/"))
61
+ end
62
+
63
+ test "blksize requires a single argument" do
64
+ assert_raises(ArgumentError){ File.blksize }
65
+ assert_raises(ArgumentError){ File.blksize(@@txt_file, 'foo') }
66
+ end
67
+
68
+ test "blockdev? basic functionality" do
69
+ assert_respond_to(File, :blockdev?)
70
+ assert_nothing_raised{ File.blockdev?("C:\\") }
71
+ assert_boolean(File.blockdev?('NUL'))
72
+ end
73
+
74
+ test "blockdev? returns false for non-block devices" do
75
+ assert_false(File.blockdev?(@@txt_file))
76
+ assert_false(File.blockdev?('NUL'))
77
+ assert_false(File.blockdev?('bogus'))
78
+ end
79
+
80
+ test "blockdev? returns true for block devices" do
81
+ omit_unless(@@block_dev)
82
+ omit_unless(File.exists?(@@block_dev), "No media in device - skipping")
83
+ assert_true(File.blockdev?(@@block_dev))
84
+ end
85
+
86
+ test "blockdev? requires a single argument" do
87
+ assert_raises(ArgumentError){ File.blockdev? }
88
+ assert_raises(ArgumentError){ File.blockdev?(@@txt_file, 'foo') }
89
+ end
90
+
91
+ test "chardev? basic functionality" do
92
+ assert_respond_to(File, :chardev?)
93
+ assert_nothing_raised{ File.chardev?("NUL") }
94
+ assert_boolean(File.chardev?(@@txt_file))
95
+ end
96
+
97
+ test "chardev? method returns the expected result for regular files" do
98
+ assert_false(File.chardev?(@@txt_file))
99
+ assert_false(File.chardev?('bogus'))
100
+ end
101
+
102
+ test "chardev? method returns the expected result for character devices" do
103
+ omit_if(@@java)
104
+ assert_true(File.chardev?('NUL'))
105
+ end
106
+
107
+ test "chardev? requires a single argument" do
108
+ assert_raises(ArgumentError){ File.chardev? }
109
+ assert_raises(ArgumentError){ File.chardev?(@@txt_file, 'foo') }
110
+ end
111
+
112
+ test "lstat is an alias for stat" do
113
+ assert_respond_to(File, :lstat)
114
+ assert_alias_method(File, :stat, :lstat)
115
+ end
116
+
117
+ test "directory? method basic functionality" do
118
+ assert_respond_to(File, :directory?)
119
+ assert_nothing_raised{ File.directory?(Dir.pwd) }
120
+ assert_boolean(File.directory?(Dir.pwd))
121
+ end
122
+
123
+ test "directory? method returns expected results" do
124
+ assert_true(File.directory?(Dir.pwd))
125
+ assert_false(File.directory?(@@txt_file))
126
+ assert_false(File.directory?('NUL'))
127
+ assert_false(File.directory?('bogus'))
128
+ end
129
+
130
+ test "executable? method basic functionality" do
131
+ assert_respond_to(File, :executable?)
132
+ assert_nothing_raised{ File.executable?(Dir.pwd) }
133
+ assert_boolean(File.executable?(Dir.pwd))
134
+ end
135
+
136
+ test "executable? method returns expected results" do
137
+ assert_true(File.executable?(@@exe_file))
138
+ assert_false(File.executable?(@@txt_file))
139
+ assert_false(File.directory?('NUL'))
140
+ assert_false(File.directory?('bogus'))
141
+ end
142
+
143
+ test "file? method basic functionality" do
144
+ assert_respond_to(File, :file?)
145
+ assert_nothing_raised{ File.file?(Dir.pwd) }
146
+ assert_boolean(File.file?(Dir.pwd))
147
+ end
148
+
149
+ test "file? method returns expected results" do
150
+ assert_true(File.file?(@@txt_file))
151
+ assert_true(File.file?(Dir.pwd))
152
+ assert_false(File.file?('NUL'))
153
+ assert_false(File.file?('bogus'))
154
+ end
155
+
156
+ test "ftype method basic functionality" do
157
+ assert_respond_to(File, :ftype)
158
+ assert_nothing_raised{ File.ftype(Dir.pwd) }
159
+ assert_kind_of(String, File.ftype(Dir.pwd))
160
+ end
161
+
162
+ test "ftype returns the expected string" do
163
+ assert_equal('file', File.ftype(@@txt_file))
164
+ assert_equal('directory', File.ftype(Dir.pwd))
165
+ assert_equal('characterSpecial', File.ftype('NUL'))
166
+ end
167
+
168
+ test "grpowned? method basic functionality" do
169
+ assert_respond_to(File, :grpowned?)
170
+ assert_nothing_raised{ File.grpowned?(Dir.pwd) }
171
+ assert_boolean(File.grpowned?(Dir.pwd))
172
+ end
173
+
174
+ test "grpowned? returns expected results" do
175
+ assert_true(File.grpowned?(@@txt_file))
176
+ assert_false(File.grpowned?('NUL'))
177
+ assert_false(File.grpowned?('bogus'))
178
+ end
179
+
180
+ test "owned? method basic functionality" do
181
+ assert_respond_to(File, :owned?)
182
+ assert_nothing_raised{ File.owned?(Dir.pwd) }
183
+ assert_boolean(File.owned?(Dir.pwd))
184
+ end
185
+
186
+ test "owned? returns expected results" do
187
+ if @@elevated
188
+ assert_false(File.owned?(@@txt_file))
189
+ else
190
+ assert_true(File.owned?(@@txt_file))
191
+ end
192
+ assert_false(File.owned?('NUL'))
193
+ assert_false(File.owned?('bogus'))
194
+ end
195
+
196
+ test "pipe? method basic functionality" do
197
+ assert_respond_to(File, :pipe?)
198
+ assert_nothing_raised{ File.pipe?(Dir.pwd) }
199
+ assert_boolean(File.pipe?(Dir.pwd))
200
+ end
201
+
202
+ test "pipe? returns expected results" do
203
+ assert_false(File.pipe?(@@txt_file))
204
+ assert_false(File.pipe?(Dir.pwd))
205
+ assert_false(File.pipe?('NUL'))
206
+ assert_false(File.pipe?('bogus'))
207
+ end
208
+
209
+ test "readable? basic functionality" do
210
+ assert_respond_to(File, :readable?)
211
+ assert_boolean(File.readable?(@@txt_file))
212
+ end
213
+
214
+ test "readable? returns expected value" do
215
+ assert_true(File.readable?(@@txt_file))
216
+ assert_true(File::Stat.new(Dir.pwd).readable?)
217
+ assert_false(File::Stat.new(@@sys_file).readable?)
218
+ end
219
+
220
+ test "readable_real? basic functionality" do
221
+ assert_respond_to(File, :readable_real?)
222
+ assert_boolean(File.readable_real?(@@txt_file))
223
+ end
224
+
225
+ test "readable_real? returns expected value" do
226
+ assert_true(File.readable_real?(@@txt_file))
227
+ end
228
+
229
+ test "socket? is an alias for pipe?" do
230
+ assert_respond_to(File, :socket?)
231
+ assert_alias_method(File, :socket?, :pipe?)
232
+ end
233
+
234
+ test "world_readable? basic functionality" do
235
+ assert_respond_to(File, :world_readable?)
236
+ assert_boolean(File.world_readable?(@@txt_file))
237
+ end
238
+
239
+ test "world_writable? returns expected value" do
240
+ assert_false(File.world_writable?(@@txt_file))
241
+ end
242
+
243
+ test "writable? basic functionality" do
244
+ assert_respond_to(File, :writable?)
245
+ assert_boolean(File.writable?(@@txt_file))
246
+ end
247
+
248
+ test "writable? returns expected value" do
249
+ assert_true(File.writable?(@@txt_file))
250
+ assert_true(File::Stat.new(Dir.pwd).writable?)
251
+ assert_false(File::Stat.new(@@sys_file).writable?)
252
+ end
253
+
254
+ test "writable_real? basic functionality" do
255
+ assert_respond_to(File, :writable_real?)
256
+ assert_boolean(File.writable_real?(@@txt_file))
257
+ end
258
+
259
+ test "writable_real? returns expected value" do
260
+ assert_true(File.writable_real?(@@txt_file))
261
+ end
262
+
263
+ test "check underlying custom stat attributes" do
264
+ File.open(@@txt_file){ |f|
265
+ assert_respond_to(f, :stat)
266
+ assert_kind_of(File::Stat, f.stat)
267
+ assert_false(f.stat.hidden?)
268
+ }
269
+ end
270
+
271
+ def teardown
272
+ @blksize = nil
273
+ end
274
+
275
+ def self.shutdown
276
+ File.delete(@@txt_file) if File.exists?(@@txt_file)
277
+ File.delete(@@exe_file) if File.exists?(@@exe_file)
278
+ @@txt_file = nil
279
+ @@exe_file = nil
280
+ @@elevated = nil
281
+ @@block_dev = nil
282
+ @@java = nil
283
+ end
114
284
  end
data/win32-file.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-file'
5
- spec.version = '0.6.9'
5
+ spec.version = '0.7.0'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -13,13 +13,14 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.rubyforge_project = 'win32utils'
15
15
  spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
+ spec.required_ruby_version = ">= 1.9.0"
16
17
 
17
- spec.add_dependency('win32-api', '>= 1.5.0')
18
- spec.add_dependency('win32-file-stat', '>= 1.3.6', '< 1.4.0')
19
- spec.add_dependency('windows-pr', '>= 1.2.0')
18
+ spec.add_dependency('ffi')
19
+ spec.add_dependency('win32-file-stat', '>= 1.4.0')
20
20
 
21
21
  spec.add_development_dependency('rake')
22
22
  spec.add_development_dependency('test-unit')
23
+ spec.add_development_dependency('win32-security')
23
24
 
24
25
  spec.description = <<-EOF
25
26
  The win32-file library adds several methods to the core File class which
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,30 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-11 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: win32-api
15
+ name: ffi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.5.0
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.5.0
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: win32-file-stat
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '>='
33
- - !ruby/object:Gem::Version
34
- version: 1.3.6
35
- - - <
36
33
  - !ruby/object:Gem::Version
37
34
  version: 1.4.0
38
35
  type: :runtime
@@ -40,27 +37,24 @@ dependencies:
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
38
  requirements:
42
39
  - - '>='
43
- - !ruby/object:Gem::Version
44
- version: 1.3.6
45
- - - <
46
40
  - !ruby/object:Gem::Version
47
41
  version: 1.4.0
48
42
  - !ruby/object:Gem::Dependency
49
- name: windows-pr
43
+ name: rake
50
44
  requirement: !ruby/object:Gem::Requirement
51
45
  requirements:
52
46
  - - '>='
53
47
  - !ruby/object:Gem::Version
54
- version: 1.2.0
55
- type: :runtime
48
+ version: '0'
49
+ type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
52
  requirements:
59
53
  - - '>='
60
54
  - !ruby/object:Gem::Version
61
- version: 1.2.0
55
+ version: '0'
62
56
  - !ruby/object:Gem::Dependency
63
- name: rake
57
+ name: test-unit
64
58
  requirement: !ruby/object:Gem::Requirement
65
59
  requirements:
66
60
  - - '>='
@@ -74,7 +68,7 @@ dependencies:
74
68
  - !ruby/object:Gem::Version
75
69
  version: '0'
76
70
  - !ruby/object:Gem::Dependency
77
- name: test-unit
71
+ name: win32-security
78
72
  requirement: !ruby/object:Gem::Requirement
79
73
  requirements:
80
74
  - - '>='
@@ -102,15 +96,16 @@ extra_rdoc_files:
102
96
  - MANIFEST
103
97
  files:
104
98
  - CHANGES
99
+ - lib/win32/file/constants.rb
100
+ - lib/win32/file/functions.rb
101
+ - lib/win32/file/structs.rb
105
102
  - lib/win32/file.rb
106
103
  - MANIFEST
107
104
  - Rakefile
108
105
  - README
109
- - test/test_win32_file_attributes.rb
110
- - test/test_win32_file_constants.rb
111
- - test/test_win32_file_encryption.rb
106
+ - test/test_win32_file_link.rb
107
+ - test/test_win32_file_misc.rb
112
108
  - test/test_win32_file_path.rb
113
- - test/test_win32_file_security.rb
114
109
  - test/test_win32_file_stat.rb
115
110
  - win32-file.gemspec
116
111
  homepage: http://github.com/djberg96/win32-file
@@ -125,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
120
  requirements:
126
121
  - - '>='
127
122
  - !ruby/object:Gem::Version
128
- version: '0'
123
+ version: 1.9.0
129
124
  required_rubygems_version: !ruby/object:Gem::Requirement
130
125
  requirements:
131
126
  - - '>='
@@ -138,9 +133,7 @@ signing_key:
138
133
  specification_version: 4
139
134
  summary: Extra or redefined methods for the File class on Windows.
140
135
  test_files:
141
- - test/test_win32_file_attributes.rb
142
- - test/test_win32_file_constants.rb
143
- - test/test_win32_file_encryption.rb
136
+ - test/test_win32_file_link.rb
137
+ - test/test_win32_file_misc.rb
144
138
  - test/test_win32_file_path.rb
145
- - test/test_win32_file_security.rb
146
139
  - test/test_win32_file_stat.rb