zip-container 2.2.0 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -13
  2. data/Changes.rdoc +22 -0
  3. data/Gemfile +1 -1
  4. data/Licence.rdoc +1 -1
  5. data/Rakefile +15 -12
  6. data/ReadMe.rdoc +20 -8
  7. data/examples/create-zip-container +7 -8
  8. data/examples/zip-container-info +4 -4
  9. data/lib/zip-container/container.rb +49 -23
  10. data/lib/zip-container/dir.rb +8 -11
  11. data/lib/zip-container/entries/directory.rb +15 -11
  12. data/lib/zip-container/entries/entry.rb +38 -29
  13. data/lib/zip-container/entries/file.rb +19 -15
  14. data/lib/zip-container/entries/managed.rb +28 -16
  15. data/lib/zip-container/entries/reserved.rb +2 -2
  16. data/lib/zip-container/exceptions.rb +20 -13
  17. data/lib/zip-container/file.rb +16 -16
  18. data/lib/zip-container/util.rb +3 -3
  19. data/lib/zip-container/version.rb +4 -3
  20. data/version.yml +3 -3
  21. data/zip-container.gemspec +31 -28
  22. metadata +54 -95
  23. data/.gitignore +0 -9
  24. data/.ruby-env +0 -1
  25. data/.ruby-gemset +0 -2
  26. data/.ruby-version +0 -2
  27. data/.travis.yml +0 -17
  28. data/test/data/compressed_mimetype.container +0 -0
  29. data/test/data/dirs/dir-mimetype/mimetype/.gitkeep +0 -1
  30. data/test/data/dirs/empty/mimetype +0 -1
  31. data/test/data/dirs/managed/dir/.gitkeep +0 -0
  32. data/test/data/dirs/managed/greeting.txt +0 -1
  33. data/test/data/dirs/managed/mimetype +0 -1
  34. data/test/data/dirs/null/.gitkeep +0 -1
  35. data/test/data/empty.container +0 -0
  36. data/test/data/empty.zip +0 -0
  37. data/test/data/example.container +0 -0
  38. data/test/data/null.file +0 -0
  39. data/test/data/subclassed.container +0 -0
  40. data/test/helpers/entry_lists.rb +0 -35
  41. data/test/tc_create_dir.rb +0 -56
  42. data/test/tc_create_file.rb +0 -140
  43. data/test/tc_exceptions.rb +0 -56
  44. data/test/tc_managed_entries.rb +0 -399
  45. data/test/tc_read_dir.rb +0 -86
  46. data/test/tc_read_file.rb +0 -109
  47. data/test/tc_reserved_names.rb +0 -334
  48. data/test/tc_util.rb +0 -67
  49. data/test/ts_container.rb +0 -59
@@ -1,56 +0,0 @@
1
- # Copyright (c) 2014 The University of Manchester, UK.
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # * Neither the names of The University of Manchester nor the names of its
16
- # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
- # POSSIBILITY OF SUCH DAMAGE.
30
- #
31
- # Author: Robert Haines
32
-
33
- require 'test/unit'
34
- require 'tmpdir'
35
- require 'zip-container'
36
-
37
- class TestCreateDir < Test::Unit::TestCase
38
-
39
- def test_create_container
40
- Dir.mktmpdir do |dir|
41
- container = File.join(dir, "empty.container")
42
-
43
- assert_nothing_raised do
44
- ZipContainer::Dir.create(container, $mimetype) do |c|
45
- assert File.exists?(File.join(container, "mimetype"))
46
- end
47
- end
48
-
49
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
50
- ZipContainer::Dir.verify!(container)
51
- end
52
-
53
- end
54
- end
55
-
56
- end
@@ -1,140 +0,0 @@
1
- # Copyright (c) 2013, 2014 The University of Manchester, UK.
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # * Neither the names of The University of Manchester nor the names of its
16
- # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
- # POSSIBILITY OF SUCH DAMAGE.
30
- #
31
- # Author: Robert Haines
32
-
33
- require 'test/unit'
34
- require 'tmpdir'
35
- require 'zip-container'
36
-
37
- class TestCreateFile < Test::Unit::TestCase
38
-
39
- # Check creation of standard empty container files.
40
- def test_create_standard_file
41
- Dir.mktmpdir do |dir|
42
- filename = File.join(dir, "test.container")
43
-
44
- assert_nothing_raised do
45
- ZipContainer::File.create(filename, $mimetype) do |c|
46
- assert(c.on_disk?)
47
- refute(c.in_memory?)
48
-
49
- assert(c.find_entry("mimetype").local_header_offset == 0)
50
- end
51
- end
52
-
53
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
54
- ZipContainer::File.verify!(filename)
55
- end
56
- end
57
- end
58
-
59
- # Check creation of empty container files with a different mimetype.
60
- def test_create_mimetype_file
61
- mimetype = "application/x-something-really-odd"
62
-
63
- Dir.mktmpdir do |dir|
64
- filename = File.join(dir, "test.container")
65
-
66
- assert_nothing_raised do
67
- ZipContainer::File.create(filename, mimetype) do |c|
68
- assert(c.on_disk?)
69
- refute(c.in_memory?)
70
-
71
- assert(c.find_entry("mimetype").local_header_offset == 0)
72
- end
73
- end
74
-
75
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
76
- ZipContainer::File.verify!(filename)
77
- end
78
- end
79
- end
80
-
81
- # Check creation of stuff in container files. Check the commit status a few
82
- # times to ensure that what we expect to happen, happens.
83
- def test_create_contents_file
84
- Dir.mktmpdir do |dir|
85
- filename = File.join(dir, "test.container")
86
-
87
- assert_nothing_raised do
88
- ZipContainer::File.create(filename, $mimetype) do |c|
89
- assert(c.on_disk?)
90
- refute(c.in_memory?)
91
-
92
- c.file.open("test.txt", "w") do |f|
93
- f.print "testing"
94
- end
95
-
96
- assert(c.commit_required?)
97
- assert(c.commit)
98
- refute(c.commit_required?)
99
- refute(c.commit)
100
-
101
- c.dir.mkdir("dir1")
102
- c.mkdir("dir2")
103
-
104
- assert(c.commit_required?)
105
- assert(c.commit)
106
- refute(c.commit_required?)
107
- refute(c.commit)
108
-
109
- c.comment = "A comment!"
110
-
111
- assert(c.commit_required?)
112
- assert(c.commit)
113
- refute(c.commit_required?)
114
- refute(c.commit)
115
- end
116
- end
117
-
118
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::ZipError) do
119
- ZipContainer::File.open(filename) do |c|
120
- assert(c.on_disk?)
121
- refute(c.in_memory?)
122
-
123
- assert(c.file.exists?("test.txt"))
124
- assert(c.file.exists?("dir1"))
125
- assert(c.file.exists?("dir2"))
126
- refute(c.file.exists?("dir3"))
127
-
128
- text = c.file.read("test.txt")
129
- assert_equal("testing", text)
130
-
131
- assert_equal("A comment!", c.comment)
132
-
133
- refute(c.commit_required?)
134
- refute(c.commit)
135
- end
136
- end
137
- end
138
- end
139
-
140
- end
@@ -1,56 +0,0 @@
1
- # Copyright (c) 2014 The University of Manchester, UK.
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # * Neither the names of The University of Manchester nor the names of its
16
- # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
- # POSSIBILITY OF SUCH DAMAGE.
30
- #
31
- # Author: Robert Haines
32
-
33
- require 'test/unit'
34
- require 'zip-container'
35
-
36
- class TestExceptions < Test::Unit::TestCase
37
-
38
- def test_rescue_container_errors
39
- assert_raise(ZipContainer::ContainerError) do
40
- raise ZipContainer::ZipError.new
41
- end
42
-
43
- assert_raise(ZipContainer::ContainerError) do
44
- raise ZipContainer::MalformedContainerError.new
45
- end
46
-
47
- assert_raise(ZipContainer::ContainerError) do
48
- raise ZipContainer::ReservedNameClashError.new("test")
49
- end
50
-
51
- assert_raise(ZipContainer::ContainerError) do
52
- raise Zip::ZipError.new
53
- end
54
- end
55
-
56
- end
@@ -1,399 +0,0 @@
1
- # Copyright (c) 2013, 2014 The University of Manchester, UK.
2
- #
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # * Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # * Neither the names of The University of Manchester nor the names of its
16
- # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
- # POSSIBILITY OF SUCH DAMAGE.
30
- #
31
- # Author: Robert Haines
32
-
33
- require 'test/unit'
34
- require 'tmpdir'
35
- require 'zip-container'
36
- require 'helpers/entry_lists'
37
-
38
- # Classes to test managed entries.
39
- class ManagedZipContainer < ZipContainer::File
40
-
41
- private_class_method :new
42
-
43
- def initialize(filename)
44
- super(filename)
45
- test_file = ZipContainer::ManagedFile.new("test.txt")
46
- deep_file = ZipContainer::ManagedFile.new("deep.txt")
47
- deep_dir = ZipContainer::ManagedDirectory.new("deep",
48
- :entries => [deep_file])
49
- register_managed_entry(ZipContainer::ManagedDirectory.new("src", :required => true))
50
- register_managed_entry(ZipContainer::ManagedDirectory.new("test",
51
- :hidden => true, :entries => [deep_dir, test_file]))
52
- register_managed_entry(ZipContainer::ManagedDirectory.new("lib"))
53
- register_managed_entry(ZipContainer::ManagedFile.new("index.html", :required => true))
54
- end
55
-
56
- end
57
-
58
- class ExampleZipContainer < ZipContainer::File
59
-
60
- private_class_method :new
61
-
62
- def initialize(filename)
63
- super(filename)
64
- register_managed_entry(ZipContainer::ManagedDirectory.new("dir", :required => true))
65
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt", :required => true))
66
- end
67
-
68
- end
69
-
70
- class ExampleZipContainer2 < ZipContainer::File
71
-
72
- private_class_method :new
73
-
74
- def initialize(filename)
75
- super(filename)
76
-
77
- valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
78
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
79
- :required => true, :validation_proc => valid))
80
- end
81
-
82
- def ExampleZipContainer2.create(filename, &block)
83
- super(filename, "application/example+zip", &block)
84
- end
85
-
86
- end
87
-
88
- class ExampleDirContainer < ZipContainer::Dir
89
-
90
- private_class_method :new
91
-
92
- def initialize(filename)
93
- super(filename)
94
-
95
- valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
96
-
97
- test_file = ZipContainer::ManagedFile.new("test.txt")
98
- register_managed_entry(ZipContainer::ManagedDirectory.new("dir",
99
- :required => true, :entries => [test_file]))
100
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
101
- :required => true, :validation_proc => valid))
102
- end
103
-
104
- #def ExampleDirContainer.create(filename, &block)
105
- # super(filename, "application/example+zip", &block)
106
- #end
107
-
108
- end
109
-
110
- class TestManagedEntries < Test::Unit::TestCase
111
-
112
- # Check that the example ZipContainer file does not validate as a
113
- # ManagedZipContainer.
114
- def test_fail_verification
115
- refute(ManagedZipContainer.verify($example))
116
-
117
- assert_raises(ZipContainer::MalformedContainerError) do
118
- ManagedZipContainer.verify!($example)
119
- end
120
- end
121
-
122
- # Check that the example ZipContainer file does validate as an
123
- # ExampleZipContainer.
124
- def test_pass_verification
125
- assert(ExampleZipContainer.verify($example))
126
-
127
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
128
- ExampleZipContainer.verify!($example)
129
- end
130
- end
131
-
132
- # Check that the example ZipContainer file does validate as an
133
- # ExampleZipContainer2.
134
- def test_pass_verification_2
135
- assert(ExampleZipContainer2.verify($example))
136
-
137
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
138
- ExampleZipContainer2.verify!($example)
139
- end
140
- end
141
-
142
- # Check that a standard Container can be created
143
- def test_create_standard_container
144
- Dir.mktmpdir do |dir|
145
- filename = File.join(dir, "test.container")
146
-
147
- assert_nothing_raised do
148
- ZipContainer::File.create(filename, $mimetype) do |c|
149
- c.mkdir("META-INF")
150
- assert(c.file.exists?("META-INF"))
151
-
152
- c.file.open("META-INF/container.xml", "w") do |f|
153
- f.puts "<?xml version=\"1.0\"?>"
154
- end
155
- assert(c.file.exists?("META-INF/container.xml"))
156
- end
157
- end
158
-
159
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
160
- ZipContainer::File.verify!(filename)
161
- end
162
- end
163
- end
164
-
165
- # Check that a subclassed container with managed files verifies correctly.
166
- def test_verify_subclassed_dir_container
167
- assert_nothing_raised do
168
- ExampleDirContainer.verify!($dir_managed)
169
- end
170
- end
171
-
172
- # Create a subclassed container. Check it doesn't verify at first; satisfy
173
- # the conditions; then assert that it verifies correctly.
174
- def test_create_subclassed_dir_container
175
- Dir.mktmpdir do |dir|
176
- filename = File.join(dir, "test.container")
177
-
178
- assert_nothing_raised do
179
- ExampleDirContainer.create(filename, $mimetype) do |c|
180
- assert_raises(ZipContainer::MalformedContainerError) do
181
- c.verify!
182
- end
183
-
184
- Dir.mkdir(File.join(filename, "dir"))
185
- File.open(File.join(filename, "greeting.txt"), "w") do |f|
186
- f.puts "Yo means hello."
187
- end
188
-
189
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
190
- c.verify!
191
- end
192
- end
193
- end
194
- end
195
- end
196
-
197
- # Check that a ManagedZipContainer does not verify immediately after
198
- # creation.
199
- def test_create_bad_subclassed_container
200
- Dir.mktmpdir do |dir|
201
- filename = File.join(dir, "test.container")
202
-
203
- assert_nothing_raised do
204
- ManagedZipContainer.create(filename, $mimetype) do |c|
205
- assert_raises(ZipContainer::MalformedContainerError) do
206
- c.verify!
207
- end
208
- end
209
- end
210
-
211
- refute(ManagedZipContainer.verify(filename))
212
- assert_raises(ZipContainer::MalformedContainerError) do
213
- ManagedZipContainer.verify!(filename)
214
- end
215
- end
216
- end
217
-
218
- # Check that a ManagedZipContainer does verify when required objects are
219
- # added.
220
- def test_create_subclassed_container
221
- Dir.mktmpdir do |dir|
222
- filename = File.join(dir, "test.container")
223
-
224
- assert_nothing_raised do
225
- ManagedZipContainer.create(filename, $mimetype) do |c|
226
- c.dir.mkdir("src")
227
- c.file.open("index.html", "w") do |f|
228
- f.puts "<html />"
229
- end
230
-
231
- # Test hidden entries before and after creation.
232
- assert_nil(c.find_entry("test", :include_hidden => true))
233
- assert_nil(c.find_entry("test/test.txt", :include_hidden => true))
234
- c.dir.mkdir("test")
235
- c.file.open("test/test.txt", "w") do |f|
236
- f.puts "A test!"
237
- end
238
- assert_not_nil(c.find_entry("test", :include_hidden => true))
239
- assert_not_nil(c.find_entry("test/test.txt", :include_hidden => true))
240
-
241
- # Test deep hidden entries before and after creation.
242
- assert_nil(c.find_entry("test/deep", :include_hidden => true))
243
- assert_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
244
- c.dir.mkdir("test/deep")
245
- c.file.open("test/deep/deep.txt", "w") do |f|
246
- f.puts "A deep test!"
247
- end
248
- assert_not_nil(c.find_entry("test/deep", :include_hidden => true))
249
- assert_not_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
250
- end
251
- end
252
-
253
- assert(ManagedZipContainer.verify(filename))
254
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
255
- ManagedZipContainer.verify!(filename)
256
- end
257
- end
258
- end
259
-
260
- def test_hidden_entries
261
- assert_nothing_raised do
262
- ManagedZipContainer.open($subclass) do |c|
263
- refute(c.hidden_entry?("src"))
264
- refute(c.hidden_file?("src"))
265
- refute(c.hidden_directory?("src"))
266
-
267
- assert(c.hidden_entry?("test"))
268
- assert(c.hidden_directory?("test"))
269
- assert(c.hidden_entry?("test/"))
270
- assert(c.hidden_directory?("test/"))
271
- refute(c.hidden_file?("test"))
272
-
273
- assert(c.hidden_entry?("test/deep"))
274
- assert(c.hidden_directory?("test/deep"))
275
- assert(c.hidden_entry?("test/deep/deep.txt"))
276
- assert(c.hidden_file?("test/deep/deep.txt"))
277
- end
278
- end
279
- end
280
-
281
- def test_find_entry
282
- assert_nothing_raised do
283
- ManagedZipContainer.open($subclass) do |c|
284
- assert_not_nil(c.find_entry("src"))
285
- assert_not_nil(c.find_entry("src", :include_hidden => true))
286
-
287
- assert_nil(c.find_entry("test"))
288
- assert_nil(c.find_entry("test/test.txt"))
289
- assert_not_nil(c.find_entry("test", :include_hidden => true))
290
- assert_not_nil(c.find_entry("test/test.txt", :include_hidden => true))
291
-
292
- assert_nil(c.find_entry("test/deep"))
293
- assert_nil(c.find_entry("test/deep/deep.txt"))
294
- assert_not_nil(c.find_entry("test/deep", :include_hidden => true))
295
- assert_not_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
296
- end
297
- end
298
- end
299
-
300
- def test_get_entry
301
- ManagedZipContainer.open($subclass) do |c|
302
- assert_nothing_raised(Errno::ENOENT) do
303
- c.get_entry("src")
304
- end
305
- assert_nothing_raised(Errno::ENOENT) do
306
- c.get_entry("src", :include_hidden => true)
307
- end
308
-
309
- assert_raise(Errno::ENOENT) do
310
- c.get_entry("test")
311
- end
312
- assert_raise(Errno::ENOENT) do
313
- c.get_entry("test/test.txt")
314
- end
315
- assert_nothing_raised(Errno::ENOENT) do
316
- c.get_entry("test", :include_hidden => true)
317
- end
318
- assert_nothing_raised(Errno::ENOENT) do
319
- c.get_entry("test/test.txt", :include_hidden => true)
320
- end
321
-
322
- assert_raise(Errno::ENOENT) do
323
- c.get_entry("test/deep")
324
- end
325
- assert_raise(Errno::ENOENT) do
326
- c.get_entry("test/deep/deep.txt")
327
- end
328
- assert_nothing_raised(Errno::ENOENT) do
329
- c.get_entry("test/deep", :include_hidden => true)
330
- end
331
- assert_nothing_raised(Errno::ENOENT) do
332
- c.get_entry("test/deep/deep.txt", :include_hidden => true)
333
- end
334
- end
335
- end
336
-
337
- def test_glob
338
- ManagedZipContainer.open($subclass) do |c|
339
- assert_equal(["index.html"], entry_list_names(c.glob("in*")))
340
- assert_equal([], c.glob("test/**/*"))
341
- assert_equal(["test/test.txt", "test/deep", "test/deep/deep.txt"],
342
- entry_list_names(c.glob("test/**/*", :include_hidden => true)))
343
- assert_equal(["test/test.txt", "test/deep/deep.txt"],
344
- entry_list_names(c.glob("**/*.TXT", ::File::FNM_CASEFOLD,
345
- :include_hidden => true)))
346
- end
347
- end
348
-
349
- def test_create_subclassed_mimetype
350
- Dir.mktmpdir do |dir|
351
- filename = File.join(dir, "test.container")
352
-
353
- assert_nothing_raised do
354
- ExampleZipContainer2.create(filename) do |c|
355
- assert(c.file.exists?("mimetype"))
356
- assert_equal("application/example+zip", c.file.read("mimetype"))
357
- end
358
- end
359
- end
360
- end
361
-
362
- # Check that a ExampleZipContainer2 will only verify when required objects
363
- # are added with the correct contents.
364
- def test_create_subclassed_container_with_content_verification
365
- Dir.mktmpdir do |dir|
366
- filename = File.join(dir, "test.container")
367
-
368
- assert_nothing_raised do
369
- ExampleZipContainer2.create(filename) do |c|
370
- assert_raises(ZipContainer::MalformedContainerError) do
371
- c.verify!
372
- end
373
-
374
- c.file.open("greeting.txt", "w") do |f|
375
- f.puts "Goodbye!"
376
- end
377
-
378
- assert_raises(ZipContainer::MalformedContainerError) do
379
- c.verify!
380
- end
381
-
382
- c.file.open("greeting.txt", "w") do |f|
383
- f.puts "Hello, Y'All!"
384
- end
385
-
386
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
387
- c.verify!
388
- end
389
- end
390
- end
391
-
392
- assert(ExampleZipContainer2.verify(filename))
393
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
394
- ExampleZipContainer2.verify!(filename)
395
- end
396
- end
397
- end
398
-
399
- end