win32-file-attributes 1.0.3 → 1.0.4
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +21 -16
- data/MANIFEST +12 -10
- data/README +46 -46
- data/Rakefile +29 -32
- data/certs/djberg96_pub.pem +21 -0
- data/lib/win32-file-attributes.rb +1 -0
- data/lib/win32/file/attributes.rb +569 -569
- data/lib/win32/file/windows/functions.rb +50 -50
- data/test/test_win32_file_attribute_constants.rb +25 -25
- data/test/test_win32_file_attributes.rb +386 -386
- data/win32-file-attributes.gemspec +24 -23
- metadata +28 -4
- metadata.gz.sig +0 -0
@@ -1,50 +1,50 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module File
|
5
|
-
module Functions
|
6
|
-
extend FFI::Library
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
|
-
# Wrapper method for attach_function + private
|
11
|
-
def self.attach_pfunc(*args)
|
12
|
-
attach_function(*args)
|
13
|
-
private args[0]
|
14
|
-
end
|
15
|
-
|
16
|
-
typedef :ulong, :dword
|
17
|
-
typedef :uintptr_t, :handle
|
18
|
-
|
19
|
-
ffi_lib :kernel32
|
20
|
-
|
21
|
-
attach_pfunc :CloseHandle, [:handle], :bool
|
22
|
-
attach_pfunc :CreateFileW, [:buffer_in, :dword, :dword, :pointer, :dword, :dword, :handle], :handle
|
23
|
-
attach_pfunc :DeviceIoControl, [:handle, :dword, :pointer, :dword, :pointer, :dword, :pointer, :pointer], :bool
|
24
|
-
attach_pfunc :GetFileAttributesW, [:buffer_in], :dword
|
25
|
-
attach_pfunc :SetFileAttributesW, [:buffer_in, :dword], :bool
|
26
|
-
|
27
|
-
def CTL_CODE(device, function, method, access)
|
28
|
-
((device) << 16) | ((access) << 14) | ((function) << 2) | (method)
|
29
|
-
end
|
30
|
-
|
31
|
-
def FSCTL_SET_COMPRESSION
|
32
|
-
CTL_CODE(9, 16, 0, 3)
|
33
|
-
end
|
34
|
-
|
35
|
-
def FSCTL_SET_SPARSE
|
36
|
-
CTL_CODE(9, 49, 0, 0)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class String
|
43
|
-
unless instance_methods.include?(:wincode)
|
44
|
-
# Convenience method for converting strings to UTF-16LE for wide character
|
45
|
-
# functions that require it.
|
46
|
-
def wincode
|
47
|
-
(self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module File
|
5
|
+
module Functions
|
6
|
+
extend FFI::Library
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
# Wrapper method for attach_function + private
|
11
|
+
def self.attach_pfunc(*args)
|
12
|
+
attach_function(*args)
|
13
|
+
private args[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
typedef :ulong, :dword
|
17
|
+
typedef :uintptr_t, :handle
|
18
|
+
|
19
|
+
ffi_lib :kernel32
|
20
|
+
|
21
|
+
attach_pfunc :CloseHandle, [:handle], :bool
|
22
|
+
attach_pfunc :CreateFileW, [:buffer_in, :dword, :dword, :pointer, :dword, :dword, :handle], :handle
|
23
|
+
attach_pfunc :DeviceIoControl, [:handle, :dword, :pointer, :dword, :pointer, :dword, :pointer, :pointer], :bool
|
24
|
+
attach_pfunc :GetFileAttributesW, [:buffer_in], :dword
|
25
|
+
attach_pfunc :SetFileAttributesW, [:buffer_in, :dword], :bool
|
26
|
+
|
27
|
+
def CTL_CODE(device, function, method, access)
|
28
|
+
((device) << 16) | ((access) << 14) | ((function) << 2) | (method)
|
29
|
+
end
|
30
|
+
|
31
|
+
def FSCTL_SET_COMPRESSION
|
32
|
+
CTL_CODE(9, 16, 0, 3)
|
33
|
+
end
|
34
|
+
|
35
|
+
def FSCTL_SET_SPARSE
|
36
|
+
CTL_CODE(9, 49, 0, 0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class String
|
43
|
+
unless instance_methods.include?(:wincode)
|
44
|
+
# Convenience method for converting strings to UTF-16LE for wide character
|
45
|
+
# functions that require it.
|
46
|
+
def wincode
|
47
|
+
(self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# test_win32_file_attribute_constants.rb
|
3
|
-
#
|
4
|
-
# Test cases for the "shortcut" constants for File attributes.
|
5
|
-
#############################################################################
|
6
|
-
require 'test-unit'
|
7
|
-
require 'win32/file/attributes'
|
8
|
-
|
9
|
-
class TC_Win32_File_Attribute_Constants < Test::Unit::TestCase
|
10
|
-
test "shortcut constants are defined" do
|
11
|
-
assert_not_nil(File::ARCHIVE)
|
12
|
-
assert_not_nil(File::HIDDEN)
|
13
|
-
assert_not_nil(File::NORMAL)
|
14
|
-
assert_not_nil(File::INDEXED)
|
15
|
-
assert_not_nil(File::OFFLINE)
|
16
|
-
assert_not_nil(File::READONLY)
|
17
|
-
assert_not_nil(File::SYSTEM)
|
18
|
-
assert_not_nil(File::TEMPORARY)
|
19
|
-
assert_not_nil(File::CONTENT_INDEXED)
|
20
|
-
end
|
21
|
-
|
22
|
-
test "CONTENT_INDEXED is identical to INDEXED" do
|
23
|
-
assert_equal(File::INDEXED, File::CONTENT_INDEXED)
|
24
|
-
end
|
25
|
-
end
|
1
|
+
#############################################################################
|
2
|
+
# test_win32_file_attribute_constants.rb
|
3
|
+
#
|
4
|
+
# Test cases for the "shortcut" constants for File attributes.
|
5
|
+
#############################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'win32/file/attributes'
|
8
|
+
|
9
|
+
class TC_Win32_File_Attribute_Constants < Test::Unit::TestCase
|
10
|
+
test "shortcut constants are defined" do
|
11
|
+
assert_not_nil(File::ARCHIVE)
|
12
|
+
assert_not_nil(File::HIDDEN)
|
13
|
+
assert_not_nil(File::NORMAL)
|
14
|
+
assert_not_nil(File::INDEXED)
|
15
|
+
assert_not_nil(File::OFFLINE)
|
16
|
+
assert_not_nil(File::READONLY)
|
17
|
+
assert_not_nil(File::SYSTEM)
|
18
|
+
assert_not_nil(File::TEMPORARY)
|
19
|
+
assert_not_nil(File::CONTENT_INDEXED)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "CONTENT_INDEXED is identical to INDEXED" do
|
23
|
+
assert_equal(File::INDEXED, File::CONTENT_INDEXED)
|
24
|
+
end
|
25
|
+
end
|
@@ -1,386 +1,386 @@
|
|
1
|
-
#############################################################################
|
2
|
-
# test_win32_file_attributes.rb
|
3
|
-
#
|
4
|
-
# Test case for the attribute related methods of win32-file. You should run
|
5
|
-
# this via the 'rake test' or 'rake test_attributes' task.
|
6
|
-
#############################################################################
|
7
|
-
require 'ffi'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'win32/file/attributes'
|
10
|
-
require 'pathname'
|
11
|
-
|
12
|
-
class TC_Win32_File_Attributes < Test::Unit::TestCase
|
13
|
-
extend FFI::Library
|
14
|
-
ffi_lib :kernel32
|
15
|
-
|
16
|
-
attach_function :GetFileAttributes, :GetFileAttributesA, [:string], :ulong
|
17
|
-
attach_function :SetFileAttributes, :SetFileAttributesA, [:string, :ulong], :ulong
|
18
|
-
|
19
|
-
def self.startup
|
20
|
-
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
21
|
-
@@file = File.join(Dir.pwd, 'test_file.txt')
|
22
|
-
File.open(@@file, 'w'){ |fh| fh.puts "This is a test." }
|
23
|
-
end
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@fh = File.open(@@file)
|
27
|
-
@attr = GetFileAttributes(@@file)
|
28
|
-
end
|
29
|
-
|
30
|
-
test "version is set to expected value" do
|
31
|
-
assert_equal('1.0.
|
32
|
-
end
|
33
|
-
|
34
|
-
test "temporary? singleton method basic functionality" do
|
35
|
-
assert_respond_to(File, :temporary?)
|
36
|
-
assert_nothing_raised{ File.temporary?(@@file) }
|
37
|
-
end
|
38
|
-
|
39
|
-
test "temporary? singleton method returns expected value" do
|
40
|
-
assert_false(File.temporary?(@@file))
|
41
|
-
end
|
42
|
-
|
43
|
-
test "temporary? singleton method requires a single argument" do
|
44
|
-
assert_raises(ArgumentError){ File.temporary? }
|
45
|
-
assert_raises(ArgumentError){ File.temporary?(@@file, 'foo') }
|
46
|
-
end
|
47
|
-
|
48
|
-
test "temporary? instance method basic functionality" do
|
49
|
-
assert_respond_to(@fh, :temporary=)
|
50
|
-
assert_nothing_raised{ @fh.temporary = true }
|
51
|
-
end
|
52
|
-
|
53
|
-
test "temporary? instance method works as expected" do
|
54
|
-
assert_false(File.temporary?(@@file))
|
55
|
-
@fh.temporary = true
|
56
|
-
assert_true(File.temporary?(@@file))
|
57
|
-
end
|
58
|
-
|
59
|
-
test "system? singleton method basic functionality" do
|
60
|
-
assert_respond_to(File, :system?)
|
61
|
-
assert_nothing_raised{ File.system?(@@file) }
|
62
|
-
end
|
63
|
-
|
64
|
-
test "system? singleton method returns the expected value" do
|
65
|
-
assert_false(File.system?(@@file))
|
66
|
-
end
|
67
|
-
|
68
|
-
test "system singleton method requires a single argument" do
|
69
|
-
assert_raises(ArgumentError){ File.system? }
|
70
|
-
assert_raises(ArgumentError){ File.system?(@@file, 'foo') }
|
71
|
-
end
|
72
|
-
|
73
|
-
test "system instance method basic functionality" do
|
74
|
-
assert_respond_to(@fh, :system=)
|
75
|
-
assert_nothing_raised{ @fh.system = true }
|
76
|
-
end
|
77
|
-
|
78
|
-
test "system instance method works as expected" do
|
79
|
-
assert_false(File.system?(@@file))
|
80
|
-
@fh.system = true
|
81
|
-
assert_true(File.system?(@@file))
|
82
|
-
end
|
83
|
-
|
84
|
-
test "sparse? singleton method basic functionality" do
|
85
|
-
assert_respond_to(File, :sparse?)
|
86
|
-
assert_nothing_raised{ File.sparse?(@@file) }
|
87
|
-
end
|
88
|
-
|
89
|
-
test "sparse? singleton method returns expected value" do
|
90
|
-
assert_false(File.sparse?(@@file))
|
91
|
-
end
|
92
|
-
|
93
|
-
test "sparse? singleton method requires one argument" do
|
94
|
-
assert_raises(ArgumentError){ File.sparse? }
|
95
|
-
assert_raises(ArgumentError){ File.sparse?(@@file, 'foo') }
|
96
|
-
end
|
97
|
-
|
98
|
-
# I don't actually test true assignment here since making a file a
|
99
|
-
# sparse file can't be undone.
|
100
|
-
test "sparse? instance method basic functionality" do
|
101
|
-
assert_respond_to(@fh, :sparse=)
|
102
|
-
assert_nothing_raised{ @fh.sparse= false }
|
103
|
-
end
|
104
|
-
|
105
|
-
test "reparse_point? singleton method basic functionality" do
|
106
|
-
assert_respond_to(File, :reparse_point?)
|
107
|
-
assert_nothing_raised{ File.reparse_point?(@@file) }
|
108
|
-
end
|
109
|
-
|
110
|
-
test "reparse_point? singleton method returns the expected value" do
|
111
|
-
assert_false(File.reparse_point?(@@file))
|
112
|
-
end
|
113
|
-
|
114
|
-
test "reparse_point? singleton method requires a single argument" do
|
115
|
-
assert_raises(ArgumentError){ File.reparse_point? }
|
116
|
-
assert_raises(ArgumentError){ File.reparse_point?(@@file, 'foo') }
|
117
|
-
end
|
118
|
-
|
119
|
-
test "readonly? singleton method basic functionality" do
|
120
|
-
assert_respond_to(File, :readonly?)
|
121
|
-
assert_nothing_raised{ File.readonly?(@@file) }
|
122
|
-
end
|
123
|
-
|
124
|
-
test "readonly? singleton method returns expected result" do
|
125
|
-
assert_false(File.readonly?(@@file))
|
126
|
-
end
|
127
|
-
|
128
|
-
test "readonly? singleton method requires a single argument" do
|
129
|
-
assert_raises(ArgumentError){ File.read_only? }
|
130
|
-
assert_raises(ArgumentError){ File.read_only?(@@file, 'foo') }
|
131
|
-
end
|
132
|
-
|
133
|
-
test "read_only? is an alias for readonly?" do
|
134
|
-
assert_respond_to(File, :read_only?)
|
135
|
-
assert_alias_method(File, :read_only?, :readonly?)
|
136
|
-
end
|
137
|
-
|
138
|
-
test "readonly? instance method basic functionality" do
|
139
|
-
assert_respond_to(@fh, :readonly=)
|
140
|
-
assert_nothing_raised{ @fh.readonly = true }
|
141
|
-
end
|
142
|
-
|
143
|
-
test "readonly? instance method returns expected value" do
|
144
|
-
assert_false(File.readonly?(@@file))
|
145
|
-
@fh.readonly = true
|
146
|
-
assert_true(File.readonly?(@@file))
|
147
|
-
end
|
148
|
-
|
149
|
-
test "offline? singleton method basic functionality" do
|
150
|
-
assert_respond_to(File, :offline?)
|
151
|
-
assert_nothing_raised{ File.offline?(@@file) }
|
152
|
-
end
|
153
|
-
|
154
|
-
test "offline? singleton method returns expected result" do
|
155
|
-
assert_false(File.offline?(@@file))
|
156
|
-
end
|
157
|
-
|
158
|
-
test "offline? singleton method requires a single argument" do
|
159
|
-
assert_raises(ArgumentError){ File.offline? }
|
160
|
-
assert_raises(ArgumentError){ File.offline?(@@file, 'foo') }
|
161
|
-
end
|
162
|
-
|
163
|
-
test "offline? instance method basic functionality" do
|
164
|
-
assert_respond_to(@fh, :offline=)
|
165
|
-
assert_nothing_raised{ @fh.offline = true }
|
166
|
-
end
|
167
|
-
|
168
|
-
test "offline? instance method returns expected value" do
|
169
|
-
assert_false(File.offline?(@@file))
|
170
|
-
@fh.offline = true
|
171
|
-
assert_true(File.offline?(@@file))
|
172
|
-
end
|
173
|
-
|
174
|
-
test "normal? singleton method basic functionality" do
|
175
|
-
assert_respond_to(File, :normal?)
|
176
|
-
assert_nothing_raised{ File.normal?(@@file) }
|
177
|
-
end
|
178
|
-
|
179
|
-
test "normal? singleton method returns expected results" do
|
180
|
-
assert_false(File.normal?(@@file))
|
181
|
-
@fh.normal = true
|
182
|
-
assert_true(File.normal?(@@file))
|
183
|
-
end
|
184
|
-
|
185
|
-
test "normal? singleton method requires a single argument" do
|
186
|
-
assert_raises(ArgumentError){ File.normal? }
|
187
|
-
assert_raises(ArgumentError){ File.normal?(@@file, 'foo') }
|
188
|
-
end
|
189
|
-
|
190
|
-
test "normal? instance method basic functionality" do
|
191
|
-
assert_respond_to(@fh, :normal=)
|
192
|
-
assert_nothing_raised{ @fh.normal = true }
|
193
|
-
end
|
194
|
-
|
195
|
-
test "normal? instance method setter does not accept false" do
|
196
|
-
assert_raises(ArgumentError){ @fh.normal = false }
|
197
|
-
end
|
198
|
-
|
199
|
-
test "hidden? singleton method basic functionality" do
|
200
|
-
assert_respond_to(File, :hidden?)
|
201
|
-
assert_nothing_raised{ File.hidden?(@@file) }
|
202
|
-
end
|
203
|
-
|
204
|
-
test "hidden? singleton method returns the expected result" do
|
205
|
-
assert_false(File.hidden?(@@file))
|
206
|
-
@fh.hidden = true
|
207
|
-
assert_true(File.hidden?(@@file))
|
208
|
-
end
|
209
|
-
|
210
|
-
test "hidden? singleton method requires a single argument" do
|
211
|
-
assert_raises(ArgumentError){ File.hidden? }
|
212
|
-
assert_raises(ArgumentError){ File.hidden?(@@file, 'foo') }
|
213
|
-
end
|
214
|
-
|
215
|
-
test "hidden? instance method basic functionality" do
|
216
|
-
assert_respond_to(@fh, :hidden=)
|
217
|
-
assert_nothing_raised{ @fh.hidden = true }
|
218
|
-
end
|
219
|
-
|
220
|
-
test "encrypted? singleton method basic functionality" do
|
221
|
-
assert_respond_to(File, :encrypted?)
|
222
|
-
assert_nothing_raised{ File.encrypted?(@@file) }
|
223
|
-
end
|
224
|
-
|
225
|
-
test "encrypted? singleton method returns the expected result" do
|
226
|
-
assert_false(File.encrypted?(@@file))
|
227
|
-
end
|
228
|
-
|
229
|
-
test "encrypted? singleton method requires a single argument" do
|
230
|
-
assert_raises(ArgumentError){ File.encrypted? }
|
231
|
-
assert_raises(ArgumentError){ File.encrypted?(@@file, 'foo') }
|
232
|
-
end
|
233
|
-
|
234
|
-
test "indexed? singleton method basic functionality" do
|
235
|
-
assert_respond_to(File, :indexed?)
|
236
|
-
assert_nothing_raised{ File.indexed?(@@file) }
|
237
|
-
end
|
238
|
-
|
239
|
-
test "indexed? singleton method returns the expected results" do
|
240
|
-
assert_true(File.indexed?(@@file))
|
241
|
-
@fh.indexed = false
|
242
|
-
assert_false(File.indexed?(@@file))
|
243
|
-
end
|
244
|
-
|
245
|
-
test "content_indexed? is an alias for indexed?" do
|
246
|
-
assert_respond_to(File, :content_indexed?)
|
247
|
-
assert_alias_method(File, :content_indexed?, :indexed?)
|
248
|
-
end
|
249
|
-
|
250
|
-
test "indexed? singleton method requires a single argument" do
|
251
|
-
assert_raises(ArgumentError){ File.indexed? }
|
252
|
-
assert_raises(ArgumentError){ File.indexed?(@@file, 'foo') }
|
253
|
-
end
|
254
|
-
|
255
|
-
test "indexed? instance method basic functionality" do
|
256
|
-
assert_respond_to(@fh, :indexed=)
|
257
|
-
assert_nothing_raised{ @fh.indexed = true }
|
258
|
-
end
|
259
|
-
|
260
|
-
test "indexed? instance method returns expected method" do
|
261
|
-
assert_true(File.indexed?(@@file))
|
262
|
-
@fh.indexed = false
|
263
|
-
assert_false(File.indexed?(@@file))
|
264
|
-
end
|
265
|
-
|
266
|
-
test "compressed? singleton method basic functionality" do
|
267
|
-
assert_respond_to(File, :compressed?)
|
268
|
-
assert_nothing_raised{ File.compressed?(@@file) }
|
269
|
-
end
|
270
|
-
|
271
|
-
test "compressed? singleton method returns the expected result" do
|
272
|
-
assert_false(File.compressed?(@@file))
|
273
|
-
end
|
274
|
-
|
275
|
-
test "compressed instance method setter basic functionality" do
|
276
|
-
assert_respond_to(@fh, :compressed=)
|
277
|
-
assert_false(File.compressed?(@@file))
|
278
|
-
end
|
279
|
-
|
280
|
-
test "compressed? singleton method requires a single argument" do
|
281
|
-
assert_raises(ArgumentError){ File.compressed? }
|
282
|
-
assert_raises(ArgumentError){ File.compressed?(@@file, 'foo') }
|
283
|
-
end
|
284
|
-
|
285
|
-
# We have to explicitly reset the compressed attribute to false as
|
286
|
-
# the last of these assertions.
|
287
|
-
|
288
|
-
test "compressed instance method setter works as expected" do
|
289
|
-
assert_nothing_raised{ @fh.compressed = true }
|
290
|
-
assert_true(File.compressed?(@@file))
|
291
|
-
assert_nothing_raised{ @fh.compressed = false }
|
292
|
-
assert_false(File.compressed?(@@file))
|
293
|
-
end
|
294
|
-
|
295
|
-
test "archive? singleton method basic functionality" do
|
296
|
-
assert_respond_to(File, :archive?)
|
297
|
-
assert_nothing_raised{ File.archive?(@@file) }
|
298
|
-
end
|
299
|
-
|
300
|
-
test "archive? singleton method returns the expected results" do
|
301
|
-
assert_true(File.archive?(@@file))
|
302
|
-
@fh.archive = false
|
303
|
-
assert_false(File.archive?(@@file))
|
304
|
-
end
|
305
|
-
|
306
|
-
test "archive? singleton method requires a single argument" do
|
307
|
-
assert_raises(ArgumentError){ File.archive? }
|
308
|
-
assert_raises(ArgumentError){ File.archive?(@@file, 'foo') }
|
309
|
-
end
|
310
|
-
|
311
|
-
test "archive instance method setter basic functionality" do
|
312
|
-
assert_respond_to(@fh, :archive=)
|
313
|
-
assert_nothing_raised{ @fh.archive = false }
|
314
|
-
end
|
315
|
-
|
316
|
-
test "attributes singleton method basic functionality" do
|
317
|
-
assert_respond_to(File, :attributes)
|
318
|
-
assert_kind_of(Array, File.attributes(@@file))
|
319
|
-
end
|
320
|
-
|
321
|
-
test "attributes singleton method returns expected results" do
|
322
|
-
assert_equal(['archive', 'indexed'], File.attributes(@@file))
|
323
|
-
end
|
324
|
-
|
325
|
-
test "attributes singleton method accepts a pathname argument" do
|
326
|
-
assert_nothing_raised{ File.attributes(Pathname.new(@@file)) }
|
327
|
-
end
|
328
|
-
|
329
|
-
test "attribute singleton method requires a stringy argument" do
|
330
|
-
assert_raise(TypeError){ File.attributes(nil) }
|
331
|
-
assert_raise(TypeError){ File.attributes([]) }
|
332
|
-
end
|
333
|
-
|
334
|
-
test "set_attributes singleton method basic functionality" do
|
335
|
-
assert_respond_to(File, :set_attributes)
|
336
|
-
assert_nothing_raised{ File.set_attributes(@@file, File::FILE_ATTRIBUTE_HIDDEN) }
|
337
|
-
end
|
338
|
-
|
339
|
-
test "set_attributes singleton method works as expected" do
|
340
|
-
assert_nothing_raised{ File.set_attributes(@@file, File::FILE_ATTRIBUTE_HIDDEN) }
|
341
|
-
assert_true(File.attributes(@@file).include?('hidden'))
|
342
|
-
end
|
343
|
-
|
344
|
-
test "set_attr is an alias for set_attributes" do
|
345
|
-
assert_respond_to(File, :set_attr)
|
346
|
-
assert_alias_method(File, :set_attr, :set_attributes)
|
347
|
-
end
|
348
|
-
|
349
|
-
test "remove_attributes singleton method basic functionality" do
|
350
|
-
assert_respond_to(File, :remove_attributes)
|
351
|
-
assert_nothing_raised{ File.remove_attributes(@@file, File::FILE_ATTRIBUTE_ARCHIVE) }
|
352
|
-
end
|
353
|
-
|
354
|
-
test "remove_attributes works as expected" do
|
355
|
-
assert_true(File.archive?(@@file))
|
356
|
-
assert_nothing_raised{ File.remove_attributes(@@file, File::FILE_ATTRIBUTE_ARCHIVE) }
|
357
|
-
assert_false(File.archive?(@@file))
|
358
|
-
end
|
359
|
-
|
360
|
-
test "unset_attr is an alias for remove_attributes" do
|
361
|
-
assert_respond_to(File, :unset_attr)
|
362
|
-
assert_alias_method(File, :unset_attr, :remove_attributes)
|
363
|
-
end
|
364
|
-
|
365
|
-
test "shorthand constants are defined" do
|
366
|
-
assert_not_nil(File::ARCHIVE)
|
367
|
-
assert_not_nil(File::HIDDEN)
|
368
|
-
assert_not_nil(File::NORMAL)
|
369
|
-
assert_not_nil(File::INDEXED)
|
370
|
-
assert_not_nil(File::OFFLINE)
|
371
|
-
assert_not_nil(File::READONLY)
|
372
|
-
assert_not_nil(File::SYSTEM)
|
373
|
-
assert_not_nil(File::TEMPORARY)
|
374
|
-
assert_not_nil(File::CONTENT_INDEXED) # alias for INDEXED
|
375
|
-
end
|
376
|
-
|
377
|
-
def teardown
|
378
|
-
SetFileAttributes(@@file, @attr)
|
379
|
-
@fh.close
|
380
|
-
end
|
381
|
-
|
382
|
-
def self.shutdown
|
383
|
-
File.delete(@@file)
|
384
|
-
@@file = nil
|
385
|
-
end
|
386
|
-
end
|
1
|
+
#############################################################################
|
2
|
+
# test_win32_file_attributes.rb
|
3
|
+
#
|
4
|
+
# Test case for the attribute related methods of win32-file. You should run
|
5
|
+
# this via the 'rake test' or 'rake test_attributes' task.
|
6
|
+
#############################################################################
|
7
|
+
require 'ffi'
|
8
|
+
require 'test-unit'
|
9
|
+
require 'win32/file/attributes'
|
10
|
+
require 'pathname'
|
11
|
+
|
12
|
+
class TC_Win32_File_Attributes < Test::Unit::TestCase
|
13
|
+
extend FFI::Library
|
14
|
+
ffi_lib :kernel32
|
15
|
+
|
16
|
+
attach_function :GetFileAttributes, :GetFileAttributesA, [:string], :ulong
|
17
|
+
attach_function :SetFileAttributes, :SetFileAttributesA, [:string, :ulong], :ulong
|
18
|
+
|
19
|
+
def self.startup
|
20
|
+
Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
|
21
|
+
@@file = File.join(Dir.pwd, 'test_file.txt')
|
22
|
+
File.open(@@file, 'w'){ |fh| fh.puts "This is a test." }
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@fh = File.open(@@file)
|
27
|
+
@attr = GetFileAttributes(@@file)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "version is set to expected value" do
|
31
|
+
assert_equal('1.0.4', File::WIN32_FILE_ATTRIBUTE_VERSION)
|
32
|
+
end
|
33
|
+
|
34
|
+
test "temporary? singleton method basic functionality" do
|
35
|
+
assert_respond_to(File, :temporary?)
|
36
|
+
assert_nothing_raised{ File.temporary?(@@file) }
|
37
|
+
end
|
38
|
+
|
39
|
+
test "temporary? singleton method returns expected value" do
|
40
|
+
assert_false(File.temporary?(@@file))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "temporary? singleton method requires a single argument" do
|
44
|
+
assert_raises(ArgumentError){ File.temporary? }
|
45
|
+
assert_raises(ArgumentError){ File.temporary?(@@file, 'foo') }
|
46
|
+
end
|
47
|
+
|
48
|
+
test "temporary? instance method basic functionality" do
|
49
|
+
assert_respond_to(@fh, :temporary=)
|
50
|
+
assert_nothing_raised{ @fh.temporary = true }
|
51
|
+
end
|
52
|
+
|
53
|
+
test "temporary? instance method works as expected" do
|
54
|
+
assert_false(File.temporary?(@@file))
|
55
|
+
@fh.temporary = true
|
56
|
+
assert_true(File.temporary?(@@file))
|
57
|
+
end
|
58
|
+
|
59
|
+
test "system? singleton method basic functionality" do
|
60
|
+
assert_respond_to(File, :system?)
|
61
|
+
assert_nothing_raised{ File.system?(@@file) }
|
62
|
+
end
|
63
|
+
|
64
|
+
test "system? singleton method returns the expected value" do
|
65
|
+
assert_false(File.system?(@@file))
|
66
|
+
end
|
67
|
+
|
68
|
+
test "system singleton method requires a single argument" do
|
69
|
+
assert_raises(ArgumentError){ File.system? }
|
70
|
+
assert_raises(ArgumentError){ File.system?(@@file, 'foo') }
|
71
|
+
end
|
72
|
+
|
73
|
+
test "system instance method basic functionality" do
|
74
|
+
assert_respond_to(@fh, :system=)
|
75
|
+
assert_nothing_raised{ @fh.system = true }
|
76
|
+
end
|
77
|
+
|
78
|
+
test "system instance method works as expected" do
|
79
|
+
assert_false(File.system?(@@file))
|
80
|
+
@fh.system = true
|
81
|
+
assert_true(File.system?(@@file))
|
82
|
+
end
|
83
|
+
|
84
|
+
test "sparse? singleton method basic functionality" do
|
85
|
+
assert_respond_to(File, :sparse?)
|
86
|
+
assert_nothing_raised{ File.sparse?(@@file) }
|
87
|
+
end
|
88
|
+
|
89
|
+
test "sparse? singleton method returns expected value" do
|
90
|
+
assert_false(File.sparse?(@@file))
|
91
|
+
end
|
92
|
+
|
93
|
+
test "sparse? singleton method requires one argument" do
|
94
|
+
assert_raises(ArgumentError){ File.sparse? }
|
95
|
+
assert_raises(ArgumentError){ File.sparse?(@@file, 'foo') }
|
96
|
+
end
|
97
|
+
|
98
|
+
# I don't actually test true assignment here since making a file a
|
99
|
+
# sparse file can't be undone.
|
100
|
+
test "sparse? instance method basic functionality" do
|
101
|
+
assert_respond_to(@fh, :sparse=)
|
102
|
+
assert_nothing_raised{ @fh.sparse= false }
|
103
|
+
end
|
104
|
+
|
105
|
+
test "reparse_point? singleton method basic functionality" do
|
106
|
+
assert_respond_to(File, :reparse_point?)
|
107
|
+
assert_nothing_raised{ File.reparse_point?(@@file) }
|
108
|
+
end
|
109
|
+
|
110
|
+
test "reparse_point? singleton method returns the expected value" do
|
111
|
+
assert_false(File.reparse_point?(@@file))
|
112
|
+
end
|
113
|
+
|
114
|
+
test "reparse_point? singleton method requires a single argument" do
|
115
|
+
assert_raises(ArgumentError){ File.reparse_point? }
|
116
|
+
assert_raises(ArgumentError){ File.reparse_point?(@@file, 'foo') }
|
117
|
+
end
|
118
|
+
|
119
|
+
test "readonly? singleton method basic functionality" do
|
120
|
+
assert_respond_to(File, :readonly?)
|
121
|
+
assert_nothing_raised{ File.readonly?(@@file) }
|
122
|
+
end
|
123
|
+
|
124
|
+
test "readonly? singleton method returns expected result" do
|
125
|
+
assert_false(File.readonly?(@@file))
|
126
|
+
end
|
127
|
+
|
128
|
+
test "readonly? singleton method requires a single argument" do
|
129
|
+
assert_raises(ArgumentError){ File.read_only? }
|
130
|
+
assert_raises(ArgumentError){ File.read_only?(@@file, 'foo') }
|
131
|
+
end
|
132
|
+
|
133
|
+
test "read_only? is an alias for readonly?" do
|
134
|
+
assert_respond_to(File, :read_only?)
|
135
|
+
assert_alias_method(File, :read_only?, :readonly?)
|
136
|
+
end
|
137
|
+
|
138
|
+
test "readonly? instance method basic functionality" do
|
139
|
+
assert_respond_to(@fh, :readonly=)
|
140
|
+
assert_nothing_raised{ @fh.readonly = true }
|
141
|
+
end
|
142
|
+
|
143
|
+
test "readonly? instance method returns expected value" do
|
144
|
+
assert_false(File.readonly?(@@file))
|
145
|
+
@fh.readonly = true
|
146
|
+
assert_true(File.readonly?(@@file))
|
147
|
+
end
|
148
|
+
|
149
|
+
test "offline? singleton method basic functionality" do
|
150
|
+
assert_respond_to(File, :offline?)
|
151
|
+
assert_nothing_raised{ File.offline?(@@file) }
|
152
|
+
end
|
153
|
+
|
154
|
+
test "offline? singleton method returns expected result" do
|
155
|
+
assert_false(File.offline?(@@file))
|
156
|
+
end
|
157
|
+
|
158
|
+
test "offline? singleton method requires a single argument" do
|
159
|
+
assert_raises(ArgumentError){ File.offline? }
|
160
|
+
assert_raises(ArgumentError){ File.offline?(@@file, 'foo') }
|
161
|
+
end
|
162
|
+
|
163
|
+
test "offline? instance method basic functionality" do
|
164
|
+
assert_respond_to(@fh, :offline=)
|
165
|
+
assert_nothing_raised{ @fh.offline = true }
|
166
|
+
end
|
167
|
+
|
168
|
+
test "offline? instance method returns expected value" do
|
169
|
+
assert_false(File.offline?(@@file))
|
170
|
+
@fh.offline = true
|
171
|
+
assert_true(File.offline?(@@file))
|
172
|
+
end
|
173
|
+
|
174
|
+
test "normal? singleton method basic functionality" do
|
175
|
+
assert_respond_to(File, :normal?)
|
176
|
+
assert_nothing_raised{ File.normal?(@@file) }
|
177
|
+
end
|
178
|
+
|
179
|
+
test "normal? singleton method returns expected results" do
|
180
|
+
assert_false(File.normal?(@@file))
|
181
|
+
@fh.normal = true
|
182
|
+
assert_true(File.normal?(@@file))
|
183
|
+
end
|
184
|
+
|
185
|
+
test "normal? singleton method requires a single argument" do
|
186
|
+
assert_raises(ArgumentError){ File.normal? }
|
187
|
+
assert_raises(ArgumentError){ File.normal?(@@file, 'foo') }
|
188
|
+
end
|
189
|
+
|
190
|
+
test "normal? instance method basic functionality" do
|
191
|
+
assert_respond_to(@fh, :normal=)
|
192
|
+
assert_nothing_raised{ @fh.normal = true }
|
193
|
+
end
|
194
|
+
|
195
|
+
test "normal? instance method setter does not accept false" do
|
196
|
+
assert_raises(ArgumentError){ @fh.normal = false }
|
197
|
+
end
|
198
|
+
|
199
|
+
test "hidden? singleton method basic functionality" do
|
200
|
+
assert_respond_to(File, :hidden?)
|
201
|
+
assert_nothing_raised{ File.hidden?(@@file) }
|
202
|
+
end
|
203
|
+
|
204
|
+
test "hidden? singleton method returns the expected result" do
|
205
|
+
assert_false(File.hidden?(@@file))
|
206
|
+
@fh.hidden = true
|
207
|
+
assert_true(File.hidden?(@@file))
|
208
|
+
end
|
209
|
+
|
210
|
+
test "hidden? singleton method requires a single argument" do
|
211
|
+
assert_raises(ArgumentError){ File.hidden? }
|
212
|
+
assert_raises(ArgumentError){ File.hidden?(@@file, 'foo') }
|
213
|
+
end
|
214
|
+
|
215
|
+
test "hidden? instance method basic functionality" do
|
216
|
+
assert_respond_to(@fh, :hidden=)
|
217
|
+
assert_nothing_raised{ @fh.hidden = true }
|
218
|
+
end
|
219
|
+
|
220
|
+
test "encrypted? singleton method basic functionality" do
|
221
|
+
assert_respond_to(File, :encrypted?)
|
222
|
+
assert_nothing_raised{ File.encrypted?(@@file) }
|
223
|
+
end
|
224
|
+
|
225
|
+
test "encrypted? singleton method returns the expected result" do
|
226
|
+
assert_false(File.encrypted?(@@file))
|
227
|
+
end
|
228
|
+
|
229
|
+
test "encrypted? singleton method requires a single argument" do
|
230
|
+
assert_raises(ArgumentError){ File.encrypted? }
|
231
|
+
assert_raises(ArgumentError){ File.encrypted?(@@file, 'foo') }
|
232
|
+
end
|
233
|
+
|
234
|
+
test "indexed? singleton method basic functionality" do
|
235
|
+
assert_respond_to(File, :indexed?)
|
236
|
+
assert_nothing_raised{ File.indexed?(@@file) }
|
237
|
+
end
|
238
|
+
|
239
|
+
test "indexed? singleton method returns the expected results" do
|
240
|
+
assert_true(File.indexed?(@@file))
|
241
|
+
@fh.indexed = false
|
242
|
+
assert_false(File.indexed?(@@file))
|
243
|
+
end
|
244
|
+
|
245
|
+
test "content_indexed? is an alias for indexed?" do
|
246
|
+
assert_respond_to(File, :content_indexed?)
|
247
|
+
assert_alias_method(File, :content_indexed?, :indexed?)
|
248
|
+
end
|
249
|
+
|
250
|
+
test "indexed? singleton method requires a single argument" do
|
251
|
+
assert_raises(ArgumentError){ File.indexed? }
|
252
|
+
assert_raises(ArgumentError){ File.indexed?(@@file, 'foo') }
|
253
|
+
end
|
254
|
+
|
255
|
+
test "indexed? instance method basic functionality" do
|
256
|
+
assert_respond_to(@fh, :indexed=)
|
257
|
+
assert_nothing_raised{ @fh.indexed = true }
|
258
|
+
end
|
259
|
+
|
260
|
+
test "indexed? instance method returns expected method" do
|
261
|
+
assert_true(File.indexed?(@@file))
|
262
|
+
@fh.indexed = false
|
263
|
+
assert_false(File.indexed?(@@file))
|
264
|
+
end
|
265
|
+
|
266
|
+
test "compressed? singleton method basic functionality" do
|
267
|
+
assert_respond_to(File, :compressed?)
|
268
|
+
assert_nothing_raised{ File.compressed?(@@file) }
|
269
|
+
end
|
270
|
+
|
271
|
+
test "compressed? singleton method returns the expected result" do
|
272
|
+
assert_false(File.compressed?(@@file))
|
273
|
+
end
|
274
|
+
|
275
|
+
test "compressed instance method setter basic functionality" do
|
276
|
+
assert_respond_to(@fh, :compressed=)
|
277
|
+
assert_false(File.compressed?(@@file))
|
278
|
+
end
|
279
|
+
|
280
|
+
test "compressed? singleton method requires a single argument" do
|
281
|
+
assert_raises(ArgumentError){ File.compressed? }
|
282
|
+
assert_raises(ArgumentError){ File.compressed?(@@file, 'foo') }
|
283
|
+
end
|
284
|
+
|
285
|
+
# We have to explicitly reset the compressed attribute to false as
|
286
|
+
# the last of these assertions.
|
287
|
+
|
288
|
+
test "compressed instance method setter works as expected" do
|
289
|
+
assert_nothing_raised{ @fh.compressed = true }
|
290
|
+
assert_true(File.compressed?(@@file))
|
291
|
+
assert_nothing_raised{ @fh.compressed = false }
|
292
|
+
assert_false(File.compressed?(@@file))
|
293
|
+
end
|
294
|
+
|
295
|
+
test "archive? singleton method basic functionality" do
|
296
|
+
assert_respond_to(File, :archive?)
|
297
|
+
assert_nothing_raised{ File.archive?(@@file) }
|
298
|
+
end
|
299
|
+
|
300
|
+
test "archive? singleton method returns the expected results" do
|
301
|
+
assert_true(File.archive?(@@file))
|
302
|
+
@fh.archive = false
|
303
|
+
assert_false(File.archive?(@@file))
|
304
|
+
end
|
305
|
+
|
306
|
+
test "archive? singleton method requires a single argument" do
|
307
|
+
assert_raises(ArgumentError){ File.archive? }
|
308
|
+
assert_raises(ArgumentError){ File.archive?(@@file, 'foo') }
|
309
|
+
end
|
310
|
+
|
311
|
+
test "archive instance method setter basic functionality" do
|
312
|
+
assert_respond_to(@fh, :archive=)
|
313
|
+
assert_nothing_raised{ @fh.archive = false }
|
314
|
+
end
|
315
|
+
|
316
|
+
test "attributes singleton method basic functionality" do
|
317
|
+
assert_respond_to(File, :attributes)
|
318
|
+
assert_kind_of(Array, File.attributes(@@file))
|
319
|
+
end
|
320
|
+
|
321
|
+
test "attributes singleton method returns expected results" do
|
322
|
+
assert_equal(['archive', 'indexed'], File.attributes(@@file))
|
323
|
+
end
|
324
|
+
|
325
|
+
test "attributes singleton method accepts a pathname argument" do
|
326
|
+
assert_nothing_raised{ File.attributes(Pathname.new(@@file)) }
|
327
|
+
end
|
328
|
+
|
329
|
+
test "attribute singleton method requires a stringy argument" do
|
330
|
+
assert_raise(TypeError){ File.attributes(nil) }
|
331
|
+
assert_raise(TypeError){ File.attributes([]) }
|
332
|
+
end
|
333
|
+
|
334
|
+
test "set_attributes singleton method basic functionality" do
|
335
|
+
assert_respond_to(File, :set_attributes)
|
336
|
+
assert_nothing_raised{ File.set_attributes(@@file, File::FILE_ATTRIBUTE_HIDDEN) }
|
337
|
+
end
|
338
|
+
|
339
|
+
test "set_attributes singleton method works as expected" do
|
340
|
+
assert_nothing_raised{ File.set_attributes(@@file, File::FILE_ATTRIBUTE_HIDDEN) }
|
341
|
+
assert_true(File.attributes(@@file).include?('hidden'))
|
342
|
+
end
|
343
|
+
|
344
|
+
test "set_attr is an alias for set_attributes" do
|
345
|
+
assert_respond_to(File, :set_attr)
|
346
|
+
assert_alias_method(File, :set_attr, :set_attributes)
|
347
|
+
end
|
348
|
+
|
349
|
+
test "remove_attributes singleton method basic functionality" do
|
350
|
+
assert_respond_to(File, :remove_attributes)
|
351
|
+
assert_nothing_raised{ File.remove_attributes(@@file, File::FILE_ATTRIBUTE_ARCHIVE) }
|
352
|
+
end
|
353
|
+
|
354
|
+
test "remove_attributes works as expected" do
|
355
|
+
assert_true(File.archive?(@@file))
|
356
|
+
assert_nothing_raised{ File.remove_attributes(@@file, File::FILE_ATTRIBUTE_ARCHIVE) }
|
357
|
+
assert_false(File.archive?(@@file))
|
358
|
+
end
|
359
|
+
|
360
|
+
test "unset_attr is an alias for remove_attributes" do
|
361
|
+
assert_respond_to(File, :unset_attr)
|
362
|
+
assert_alias_method(File, :unset_attr, :remove_attributes)
|
363
|
+
end
|
364
|
+
|
365
|
+
test "shorthand constants are defined" do
|
366
|
+
assert_not_nil(File::ARCHIVE)
|
367
|
+
assert_not_nil(File::HIDDEN)
|
368
|
+
assert_not_nil(File::NORMAL)
|
369
|
+
assert_not_nil(File::INDEXED)
|
370
|
+
assert_not_nil(File::OFFLINE)
|
371
|
+
assert_not_nil(File::READONLY)
|
372
|
+
assert_not_nil(File::SYSTEM)
|
373
|
+
assert_not_nil(File::TEMPORARY)
|
374
|
+
assert_not_nil(File::CONTENT_INDEXED) # alias for INDEXED
|
375
|
+
end
|
376
|
+
|
377
|
+
def teardown
|
378
|
+
SetFileAttributes(@@file, @attr)
|
379
|
+
@fh.close
|
380
|
+
end
|
381
|
+
|
382
|
+
def self.shutdown
|
383
|
+
File.delete(@@file)
|
384
|
+
@@file = nil
|
385
|
+
end
|
386
|
+
end
|