win32-file 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,285 +1,285 @@
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 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
11
- require 'win32/file'
12
-
13
- class TC_Win32_File_Attributes < Test::Unit::TestCase
14
- include Windows::File
15
- extend Windows::File
16
-
17
- def self.startup
18
- Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
19
- @@file = File.join(Dir.pwd, 'test_file.txt')
20
- File.open(@@file, 'w'){ |fh| fh.puts "This is a test." }
21
- end
22
-
23
- def setup
24
- @fh = File.open(@@file)
25
- @attr = GetFileAttributes(@@file)
26
- end
27
-
28
- def test_version
29
- assert_equal('0.6.8', File::WIN32_FILE_VERSION)
30
- end
31
-
32
- def test_is_directory
33
- assert_true(File.directory?(Dir.pwd))
34
- assert_false(File.directory?(@@file))
35
- assert_false(File.directory?('C:/aaabbbccc'))
36
- end
37
-
38
- def test_temporary
39
- assert_respond_to(File, :temporary?)
40
- assert_nothing_raised{ File.temporary?(@@file) }
41
- assert_equal(false, File.temporary?(@@file))
42
- end
43
-
44
- def test_temporary_instance
45
- assert_respond_to(@fh, :temporary=)
46
- assert_nothing_raised{ @fh.temporary = true }
47
- assert(File.temporary?(@@file))
48
- end
49
-
50
- def test_temporary_expected_errors
51
- assert_raises(ArgumentError){ File.temporary? }
52
- assert_raises(ArgumentError){ File.temporary?(@@file, 'foo') }
53
- end
54
-
55
- def test_system
56
- assert_respond_to(File, :system?)
57
- assert_nothing_raised{ File.system?(@@file) }
58
- assert_equal(false, File.system?(@@file))
59
- end
60
-
61
- def test_system_instance
62
- assert_respond_to(@fh, :system=)
63
- assert_nothing_raised{ @fh.system = true }
64
- assert(File.system?(@@file))
65
- end
66
-
67
- def test_system_expected_errors
68
- assert_raises(ArgumentError){ File.system? }
69
- assert_raises(ArgumentError){ File.system?(@@file, 'foo') }
70
- end
71
-
72
- def test_sparse
73
- assert_respond_to(File, :sparse?)
74
- assert_nothing_raised{ File.sparse?(@@file) }
75
- assert_equal(false, File.sparse?(@@file))
76
- end
77
-
78
- # I don't actually test assignment here since making a file a sparse
79
- # file can't be undone.
80
- def test_sparse_instance
81
- assert_respond_to(@fh, :sparse=)
82
- end
83
-
84
- def test_sparse_file_expected_errors
85
- assert_raises(ArgumentError){ File.sparse? }
86
- assert_raises(ArgumentError){ File.sparse?(@@file, 'foo') }
87
- end
88
-
89
- def test_reparse_point
90
- assert_respond_to(File, :reparse_point?)
91
- assert_nothing_raised{ File.reparse_point?(@@file) }
92
- assert_equal(false, File.reparse_point?(@@file))
93
- end
94
-
95
- def test_reparse_point_expected_errors
96
- assert_raises(ArgumentError){ File.reparse_point? }
97
- assert_raises(ArgumentError){ File.reparse_point?(@@file, 'foo') }
98
- end
99
-
100
- def test_readonly
101
- assert_respond_to(File, :readonly?)
102
- assert_nothing_raised{ File.readonly?(@@file) }
103
- assert_equal(false, File.readonly?(@@file))
104
- end
105
-
106
- def test_read_only_alias
107
- assert_respond_to(File, :read_only?)
108
- assert_equal(true, File.method(:readonly?) == File.method(:read_only?))
109
- end
110
-
111
- def test_readonly_instance
112
- assert_respond_to(@fh, :readonly=)
113
- assert_nothing_raised{ @fh.readonly = true }
114
- assert(File.readonly?(@@file))
115
- end
116
-
117
- def test_read_only_expected_errors
118
- assert_raises(ArgumentError){ File.read_only? }
119
- assert_raises(ArgumentError){ File.read_only?(@@file, 'foo') }
120
- end
121
-
122
- def test_offline
123
- assert_respond_to(File, :offline?)
124
- assert_nothing_raised{ File.offline?(@@file) }
125
- assert_equal(false, File.offline?(@@file))
126
- end
127
-
128
- def test_offline_instance
129
- assert_respond_to(@fh, :offline=)
130
- assert_nothing_raised{ @fh.offline = true }
131
- assert(File.offline?(@@file))
132
- end
133
-
134
- def test_offline_expected_errors
135
- assert_raises(ArgumentError){ File.offline? }
136
- assert_raises(ArgumentError){ File.offline?(@@file, 'foo') }
137
- end
138
-
139
- def test_normal
140
- assert_respond_to(File, :normal?)
141
- assert_nothing_raised{ File.normal?(@@file) }
142
- assert_equal(false, File.normal?(@@file))
143
- end
144
-
145
- def test_normal_instance
146
- assert_respond_to(@fh, :normal=)
147
- assert_nothing_raised{ @fh.normal = true }
148
- assert(File.normal?(@@file))
149
- end
150
-
151
- def test_normal_expected_errors
152
- assert_raises(ArgumentError){ File.normal? }
153
- assert_raises(ArgumentError){ File.normal?(@@file, 'foo') }
154
- assert_raises(ArgumentError){ @fh.normal = false }
155
- end
156
-
157
- def test_hidden
158
- assert_respond_to(File, :hidden?)
159
- assert_nothing_raised{ File.hidden?(@@file) }
160
- assert_equal(false, File.hidden?(@@file))
161
- end
162
-
163
- def test_hidden_instance
164
- assert_respond_to(@fh, :hidden=)
165
- assert_nothing_raised{ @fh.hidden = true }
166
- assert(File.hidden?(@@file))
167
- end
168
-
169
- def test_hidden_expected_errors
170
- assert_raises(ArgumentError){ File.hidden? }
171
- assert_raises(ArgumentError){ File.hidden?(@@file, 'foo') }
172
- end
173
-
174
- def test_encrypted
175
- assert_respond_to(File, :encrypted?)
176
- assert_nothing_raised{ File.encrypted?(@@file) }
177
- assert_equal(false, File.encrypted?(@@file))
178
- end
179
-
180
- def test_encrypted_expected_errors
181
- assert_raises(ArgumentError){ File.encrypted? }
182
- assert_raises(ArgumentError){ File.encrypted?(@@file, 'foo') }
183
- end
184
-
185
- def test_indexed
186
- assert_respond_to(File, :indexed?)
187
- assert_nothing_raised{ File.indexed?(@@file) }
188
- assert_equal(true, File.indexed?(@@file))
189
- end
190
-
191
- def test_content_indexed_alias
192
- assert_respond_to(File, :content_indexed?)
193
- assert(File.method(:content_indexed?) == File.method(:indexed?))
194
- end
195
-
196
- def test_indexed_instance
197
- assert_respond_to(@fh, :indexed=)
198
- assert_nothing_raised{ @fh.indexed = true }
199
- assert(File.indexed?(@@file))
200
- end
201
-
202
- def test_indexed_expected_errors
203
- assert_raises(ArgumentError){ File.indexed? }
204
- assert_raises(ArgumentError){ File.indexed?(@@file, 'foo') }
205
- end
206
-
207
- def test_compressed
208
- assert_respond_to(File, :compressed?)
209
- assert_nothing_raised{ File.compressed?(@@file) }
210
- assert_equal(false, File.compressed?(@@file))
211
- end
212
-
213
- # We have to explicitly reset the compressed attribute to false as
214
- # the last of these assertions.
215
- def test_compressed_instance
216
- assert_respond_to(@fh, :compressed=)
217
- assert_equal(false, File.compressed?(@@file))
218
-
219
- assert_nothing_raised{ @fh.compressed = true }
220
- assert_equal(true, File.compressed?(@@file))
221
-
222
- assert_nothing_raised{ @fh.compressed = false }
223
- assert_equal(false, File.compressed?(@@file))
224
- end
225
-
226
- def test_compressed_expected_errors
227
- assert_raises(ArgumentError){ File.compressed? }
228
- assert_raises(ArgumentError){ File.compressed?(@@file, 'foo') }
229
- end
230
-
231
- def test_archive
232
- assert_respond_to(File, :archive?)
233
- assert_nothing_raised{ File.archive?(@@file) }
234
- assert_equal(true, File.archive?(@@file))
235
- end
236
-
237
- def test_archive_instance
238
- assert_respond_to(@fh, :archive=)
239
- assert_nothing_raised{ @fh.archive = false }
240
- assert_equal(false, File.archive?(@@file))
241
- end
242
-
243
- def test_archive_expected_errors
244
- assert_raises(ArgumentError){ File.archive? }
245
- assert_raises(ArgumentError){ File.archive?(@@file, 'foo') }
246
- end
247
-
248
- def test_attributes
249
- assert_respond_to(File, :attributes)
250
- assert_kind_of(Array, File.attributes(@@file))
251
- assert_equal(['archive', 'indexed'], File.attributes(@@file))
252
- end
253
-
254
- def test_set_attributes
255
- assert_respond_to(File, :set_attributes)
256
- assert_nothing_raised{ File.set_attributes(@@file, File::HIDDEN) }
257
- assert(File.hidden?(@@file))
258
- end
259
-
260
- def test_set_attr_alias
261
- assert_respond_to(File, :set_attr)
262
- assert(File.method(:set_attr) == File.method(:set_attributes))
263
- end
264
-
265
- def test_remove_attributes
266
- assert_respond_to(File, :remove_attributes)
267
- assert_nothing_raised{ File.remove_attributes(@@file, File::ARCHIVE) }
268
- assert_equal(false, File.archive?(@@file))
269
- end
270
-
271
- def test_unset_attr_alias
272
- assert_respond_to(File, :unset_attr)
273
- assert(File.method(:unset_attr) == File.method(:remove_attributes))
274
- end
275
-
276
- def teardown
277
- SetFileAttributesA(@@file, @attr)
278
- @fh.close
279
- end
280
-
281
- def self.shutdown
282
- File.delete(@@file)
283
- @@file = nil
284
- end
285
- 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 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'win32/file'
12
+
13
+ class TC_Win32_File_Attributes < Test::Unit::TestCase
14
+ include Windows::File
15
+ extend Windows::File
16
+
17
+ def self.startup
18
+ Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
19
+ @@file = File.join(Dir.pwd, 'test_file.txt')
20
+ File.open(@@file, 'w'){ |fh| fh.puts "This is a test." }
21
+ end
22
+
23
+ def setup
24
+ @fh = File.open(@@file)
25
+ @attr = GetFileAttributes(@@file)
26
+ end
27
+
28
+ def test_version
29
+ assert_equal('0.6.9', File::WIN32_FILE_VERSION)
30
+ end
31
+
32
+ def test_is_directory
33
+ assert_true(File.directory?(Dir.pwd))
34
+ assert_false(File.directory?(@@file))
35
+ assert_false(File.directory?('C:/aaabbbccc'))
36
+ end
37
+
38
+ def test_temporary
39
+ assert_respond_to(File, :temporary?)
40
+ assert_nothing_raised{ File.temporary?(@@file) }
41
+ assert_equal(false, File.temporary?(@@file))
42
+ end
43
+
44
+ def test_temporary_instance
45
+ assert_respond_to(@fh, :temporary=)
46
+ assert_nothing_raised{ @fh.temporary = true }
47
+ assert(File.temporary?(@@file))
48
+ end
49
+
50
+ def test_temporary_expected_errors
51
+ assert_raises(ArgumentError){ File.temporary? }
52
+ assert_raises(ArgumentError){ File.temporary?(@@file, 'foo') }
53
+ end
54
+
55
+ def test_system
56
+ assert_respond_to(File, :system?)
57
+ assert_nothing_raised{ File.system?(@@file) }
58
+ assert_equal(false, File.system?(@@file))
59
+ end
60
+
61
+ def test_system_instance
62
+ assert_respond_to(@fh, :system=)
63
+ assert_nothing_raised{ @fh.system = true }
64
+ assert(File.system?(@@file))
65
+ end
66
+
67
+ def test_system_expected_errors
68
+ assert_raises(ArgumentError){ File.system? }
69
+ assert_raises(ArgumentError){ File.system?(@@file, 'foo') }
70
+ end
71
+
72
+ def test_sparse
73
+ assert_respond_to(File, :sparse?)
74
+ assert_nothing_raised{ File.sparse?(@@file) }
75
+ assert_equal(false, File.sparse?(@@file))
76
+ end
77
+
78
+ # I don't actually test assignment here since making a file a sparse
79
+ # file can't be undone.
80
+ def test_sparse_instance
81
+ assert_respond_to(@fh, :sparse=)
82
+ end
83
+
84
+ def test_sparse_file_expected_errors
85
+ assert_raises(ArgumentError){ File.sparse? }
86
+ assert_raises(ArgumentError){ File.sparse?(@@file, 'foo') }
87
+ end
88
+
89
+ def test_reparse_point
90
+ assert_respond_to(File, :reparse_point?)
91
+ assert_nothing_raised{ File.reparse_point?(@@file) }
92
+ assert_equal(false, File.reparse_point?(@@file))
93
+ end
94
+
95
+ def test_reparse_point_expected_errors
96
+ assert_raises(ArgumentError){ File.reparse_point? }
97
+ assert_raises(ArgumentError){ File.reparse_point?(@@file, 'foo') }
98
+ end
99
+
100
+ def test_readonly
101
+ assert_respond_to(File, :readonly?)
102
+ assert_nothing_raised{ File.readonly?(@@file) }
103
+ assert_equal(false, File.readonly?(@@file))
104
+ end
105
+
106
+ def test_read_only_alias
107
+ assert_respond_to(File, :read_only?)
108
+ assert_equal(true, File.method(:readonly?) == File.method(:read_only?))
109
+ end
110
+
111
+ def test_readonly_instance
112
+ assert_respond_to(@fh, :readonly=)
113
+ assert_nothing_raised{ @fh.readonly = true }
114
+ assert(File.readonly?(@@file))
115
+ end
116
+
117
+ def test_read_only_expected_errors
118
+ assert_raises(ArgumentError){ File.read_only? }
119
+ assert_raises(ArgumentError){ File.read_only?(@@file, 'foo') }
120
+ end
121
+
122
+ def test_offline
123
+ assert_respond_to(File, :offline?)
124
+ assert_nothing_raised{ File.offline?(@@file) }
125
+ assert_equal(false, File.offline?(@@file))
126
+ end
127
+
128
+ def test_offline_instance
129
+ assert_respond_to(@fh, :offline=)
130
+ assert_nothing_raised{ @fh.offline = true }
131
+ assert(File.offline?(@@file))
132
+ end
133
+
134
+ def test_offline_expected_errors
135
+ assert_raises(ArgumentError){ File.offline? }
136
+ assert_raises(ArgumentError){ File.offline?(@@file, 'foo') }
137
+ end
138
+
139
+ def test_normal
140
+ assert_respond_to(File, :normal?)
141
+ assert_nothing_raised{ File.normal?(@@file) }
142
+ assert_equal(false, File.normal?(@@file))
143
+ end
144
+
145
+ def test_normal_instance
146
+ assert_respond_to(@fh, :normal=)
147
+ assert_nothing_raised{ @fh.normal = true }
148
+ assert(File.normal?(@@file))
149
+ end
150
+
151
+ def test_normal_expected_errors
152
+ assert_raises(ArgumentError){ File.normal? }
153
+ assert_raises(ArgumentError){ File.normal?(@@file, 'foo') }
154
+ assert_raises(ArgumentError){ @fh.normal = false }
155
+ end
156
+
157
+ def test_hidden
158
+ assert_respond_to(File, :hidden?)
159
+ assert_nothing_raised{ File.hidden?(@@file) }
160
+ assert_equal(false, File.hidden?(@@file))
161
+ end
162
+
163
+ def test_hidden_instance
164
+ assert_respond_to(@fh, :hidden=)
165
+ assert_nothing_raised{ @fh.hidden = true }
166
+ assert(File.hidden?(@@file))
167
+ end
168
+
169
+ def test_hidden_expected_errors
170
+ assert_raises(ArgumentError){ File.hidden? }
171
+ assert_raises(ArgumentError){ File.hidden?(@@file, 'foo') }
172
+ end
173
+
174
+ def test_encrypted
175
+ assert_respond_to(File, :encrypted?)
176
+ assert_nothing_raised{ File.encrypted?(@@file) }
177
+ assert_equal(false, File.encrypted?(@@file))
178
+ end
179
+
180
+ def test_encrypted_expected_errors
181
+ assert_raises(ArgumentError){ File.encrypted? }
182
+ assert_raises(ArgumentError){ File.encrypted?(@@file, 'foo') }
183
+ end
184
+
185
+ def test_indexed
186
+ assert_respond_to(File, :indexed?)
187
+ assert_nothing_raised{ File.indexed?(@@file) }
188
+ assert_equal(true, File.indexed?(@@file))
189
+ end
190
+
191
+ def test_content_indexed_alias
192
+ assert_respond_to(File, :content_indexed?)
193
+ assert(File.method(:content_indexed?) == File.method(:indexed?))
194
+ end
195
+
196
+ def test_indexed_instance
197
+ assert_respond_to(@fh, :indexed=)
198
+ assert_nothing_raised{ @fh.indexed = true }
199
+ assert(File.indexed?(@@file))
200
+ end
201
+
202
+ def test_indexed_expected_errors
203
+ assert_raises(ArgumentError){ File.indexed? }
204
+ assert_raises(ArgumentError){ File.indexed?(@@file, 'foo') }
205
+ end
206
+
207
+ def test_compressed
208
+ assert_respond_to(File, :compressed?)
209
+ assert_nothing_raised{ File.compressed?(@@file) }
210
+ assert_equal(false, File.compressed?(@@file))
211
+ end
212
+
213
+ # We have to explicitly reset the compressed attribute to false as
214
+ # the last of these assertions.
215
+ def test_compressed_instance
216
+ assert_respond_to(@fh, :compressed=)
217
+ assert_equal(false, File.compressed?(@@file))
218
+
219
+ assert_nothing_raised{ @fh.compressed = true }
220
+ assert_equal(true, File.compressed?(@@file))
221
+
222
+ assert_nothing_raised{ @fh.compressed = false }
223
+ assert_equal(false, File.compressed?(@@file))
224
+ end
225
+
226
+ def test_compressed_expected_errors
227
+ assert_raises(ArgumentError){ File.compressed? }
228
+ assert_raises(ArgumentError){ File.compressed?(@@file, 'foo') }
229
+ end
230
+
231
+ def test_archive
232
+ assert_respond_to(File, :archive?)
233
+ assert_nothing_raised{ File.archive?(@@file) }
234
+ assert_equal(true, File.archive?(@@file))
235
+ end
236
+
237
+ def test_archive_instance
238
+ assert_respond_to(@fh, :archive=)
239
+ assert_nothing_raised{ @fh.archive = false }
240
+ assert_equal(false, File.archive?(@@file))
241
+ end
242
+
243
+ def test_archive_expected_errors
244
+ assert_raises(ArgumentError){ File.archive? }
245
+ assert_raises(ArgumentError){ File.archive?(@@file, 'foo') }
246
+ end
247
+
248
+ def test_attributes
249
+ assert_respond_to(File, :attributes)
250
+ assert_kind_of(Array, File.attributes(@@file))
251
+ assert_equal(['archive', 'indexed'], File.attributes(@@file))
252
+ end
253
+
254
+ def test_set_attributes
255
+ assert_respond_to(File, :set_attributes)
256
+ assert_nothing_raised{ File.set_attributes(@@file, File::HIDDEN) }
257
+ assert(File.hidden?(@@file))
258
+ end
259
+
260
+ def test_set_attr_alias
261
+ assert_respond_to(File, :set_attr)
262
+ assert(File.method(:set_attr) == File.method(:set_attributes))
263
+ end
264
+
265
+ def test_remove_attributes
266
+ assert_respond_to(File, :remove_attributes)
267
+ assert_nothing_raised{ File.remove_attributes(@@file, File::ARCHIVE) }
268
+ assert_equal(false, File.archive?(@@file))
269
+ end
270
+
271
+ def test_unset_attr_alias
272
+ assert_respond_to(File, :unset_attr)
273
+ assert(File.method(:unset_attr) == File.method(:remove_attributes))
274
+ end
275
+
276
+ def teardown
277
+ SetFileAttributesA(@@file, @attr)
278
+ @fh.close
279
+ end
280
+
281
+ def self.shutdown
282
+ File.delete(@@file)
283
+ @@file = nil
284
+ end
285
+ end