zip-container 3.0.2 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +1 -1
  3. data/Licence.rdoc +1 -1
  4. data/Rakefile +15 -12
  5. data/examples/create-zip-container +7 -8
  6. data/examples/zip-container-info +4 -4
  7. data/lib/zip-container/container.rb +5 -7
  8. data/lib/zip-container/dir.rb +8 -11
  9. data/lib/zip-container/entries/directory.rb +5 -5
  10. data/lib/zip-container/entries/entry.rb +19 -15
  11. data/lib/zip-container/entries/file.rb +10 -9
  12. data/lib/zip-container/entries/managed.rb +11 -11
  13. data/lib/zip-container/entries/reserved.rb +2 -2
  14. data/lib/zip-container/exceptions.rb +4 -2
  15. data/lib/zip-container/file.rb +16 -16
  16. data/lib/zip-container/util.rb +3 -3
  17. data/lib/zip-container/version.rb +4 -3
  18. data/version.yml +2 -2
  19. data/zip-container.gemspec +30 -27
  20. metadata +41 -83
  21. data/.gitignore +0 -9
  22. data/.ruby-env +0 -1
  23. data/.ruby-gemset +0 -1
  24. data/.ruby-version +0 -1
  25. data/.travis.yml +0 -19
  26. data/test/data/compressed_mimetype.container +0 -0
  27. data/test/data/dirs/dir-mimetype/mimetype/.gitkeep +0 -1
  28. data/test/data/dirs/empty/mimetype +0 -1
  29. data/test/data/dirs/managed/dir/.gitkeep +0 -0
  30. data/test/data/dirs/managed/greeting.txt +0 -1
  31. data/test/data/dirs/managed/mimetype +0 -1
  32. data/test/data/dirs/null/.gitkeep +0 -1
  33. data/test/data/empty.container +0 -0
  34. data/test/data/empty.zip +0 -0
  35. data/test/data/example.container +0 -0
  36. data/test/data/null.file +0 -0
  37. data/test/data/subclassed.container +0 -0
  38. data/test/helpers/entry_lists.rb +0 -35
  39. data/test/tc_create_dir.rb +0 -56
  40. data/test/tc_create_file.rb +0 -140
  41. data/test/tc_exceptions.rb +0 -105
  42. data/test/tc_managed_entries.rb +0 -446
  43. data/test/tc_read_dir.rb +0 -90
  44. data/test/tc_read_file.rb +0 -118
  45. data/test/tc_reserved_names.rb +0 -334
  46. data/test/tc_util.rb +0 -67
  47. data/test/ts_container.rb +0 -59
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- pkg/
2
- html/
3
- coverage/
4
- .buildpath
5
- .project
6
- .idea
7
- .rvmrc
8
- Gemfile.lock
9
- example.zip
data/.ruby-env DELETED
@@ -1 +0,0 @@
1
- RUBYLIB=./lib:../lib
@@ -1 +0,0 @@
1
- zip-container
@@ -1 +0,0 @@
1
- ruby-2.2.1
@@ -1,19 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.5
7
- - 2.2.1
8
- - ruby-head
9
- - rbx-2
10
-
11
- sudo: false
12
-
13
- cache: bundler
14
-
15
- matrix:
16
- allow_failures:
17
- - rvm: 1.9.3
18
- - rvm: ruby-head
19
- - rvm: rbx-2
@@ -1 +0,0 @@
1
- This "mimetype" directory needs to be preserved by git.
@@ -1 +0,0 @@
1
- application/epub+zip
File without changes
@@ -1 +0,0 @@
1
- Hello, World!
@@ -1 +0,0 @@
1
- application/epub+zip
@@ -1 +0,0 @@
1
- This dir should be "empty", which in this case just means no "mimetype" file.
Binary file
Binary file
Binary file
File without changes
@@ -1,35 +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
- def entry_list_names(entries)
34
- entries.map { |entry| entry.name }
35
- 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 '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,105 +0,0 @@
1
- # Copyright (c) 2014, 2015 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::Error) do
40
- raise ZipContainer::ZipError.new
41
- end
42
-
43
- assert_raise(ZipContainer::Error) do
44
- raise ZipContainer::MalformedContainerError.new
45
- end
46
-
47
- assert_raise(ZipContainer::Error) do
48
- raise ZipContainer::ReservedNameClashError.new("test")
49
- end
50
-
51
- assert_raise(ZipContainer::Error) do
52
- raise Zip::ZipError.new
53
- end
54
- end
55
-
56
- def test_malformed_container_error_nil
57
- mce = nil
58
-
59
- assert_nothing_raised do
60
- mce = ZipContainer::MalformedContainerError.new(nil)
61
- end
62
-
63
- refute mce.message.empty?
64
- refute mce.message.include?(':')
65
- end
66
-
67
- def test_malformed_container_error_empty_string
68
- mce = nil
69
-
70
- assert_nothing_raised do
71
- mce = ZipContainer::MalformedContainerError.new("")
72
- end
73
-
74
- refute mce.message.empty?
75
- refute mce.message.include?(':')
76
- end
77
-
78
- def test_malformed_container_error_string
79
- mce = nil
80
- message = "test"
81
-
82
- assert_nothing_raised do
83
- mce = ZipContainer::MalformedContainerError.new(message)
84
- end
85
-
86
- refute mce.message.empty?
87
- assert mce.message.include?(':')
88
- assert mce.message.include?(message)
89
- end
90
-
91
- def test_malformed_container_error_list
92
- mce = nil
93
- message = %w(test1 test2)
94
-
95
- assert_nothing_raised do
96
- mce = ZipContainer::MalformedContainerError.new(message)
97
- end
98
-
99
- refute mce.message.empty?
100
- assert mce.message.include?(':')
101
- assert mce.message.include?(' * test1')
102
- assert mce.message.include?(' * test2')
103
- end
104
-
105
- end
@@ -1,446 +0,0 @@
1
- # Copyright (c) 2013-2015 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
-
81
- deep_greet = ZipContainer::ManagedFile.new("greet.txt",
82
- :validation_proc => valid)
83
- register_managed_entry(ZipContainer::ManagedDirectory.new("dir",
84
- :entries => [deep_greet]))
85
- end
86
-
87
- def ExampleZipContainer2.create(filename, &block)
88
- super(filename, "application/example+zip", &block)
89
- end
90
-
91
- end
92
-
93
- class ExampleDirContainer < ZipContainer::Dir
94
-
95
- private_class_method :new
96
-
97
- def initialize(filename)
98
- super(filename)
99
-
100
- valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
101
-
102
- test_file = ZipContainer::ManagedFile.new("test.txt")
103
- register_managed_entry(ZipContainer::ManagedDirectory.new("dir",
104
- :required => true, :entries => [test_file]))
105
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
106
- :required => true, :validation_proc => valid))
107
- end
108
-
109
- end
110
-
111
- class TestManagedEntries < Test::Unit::TestCase
112
-
113
- # Check that the example ZipContainer file does not validate as a
114
- # ManagedZipContainer.
115
- def test_fail_verification
116
- refute(ManagedZipContainer.verify?($example))
117
-
118
- assert_raises(ZipContainer::MalformedContainerError) do
119
- ManagedZipContainer.verify!($example)
120
- end
121
- end
122
-
123
- # Check that the example ZipContainer file does validate as an
124
- # ExampleZipContainer.
125
- def test_pass_verification
126
- assert(ExampleZipContainer.verify?($example))
127
-
128
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
129
- ExampleZipContainer.verify!($example)
130
- end
131
- end
132
-
133
- # Check that the example ZipContainer file does validate as an
134
- # ExampleZipContainer2.
135
- def test_pass_verification_2
136
- assert(ExampleZipContainer2.verify?($example))
137
-
138
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
139
- ExampleZipContainer2.verify!($example)
140
- end
141
- end
142
-
143
- # Check that a standard Container can be created
144
- def test_create_standard_container
145
- Dir.mktmpdir do |dir|
146
- filename = File.join(dir, "test.container")
147
-
148
- assert_nothing_raised do
149
- ZipContainer::File.create(filename, $mimetype) do |c|
150
- c.mkdir("META-INF")
151
- assert(c.file.exists?("META-INF"))
152
-
153
- c.file.open("META-INF/container.xml", "w") do |f|
154
- f.puts "<?xml version=\"1.0\"?>"
155
- end
156
- assert(c.file.exists?("META-INF/container.xml"))
157
- end
158
- end
159
-
160
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
161
- ZipContainer::File.verify!(filename)
162
- end
163
- end
164
- end
165
-
166
- # Check that a subclassed container with managed files verifies correctly.
167
- def test_verify_subclassed_dir_container
168
- assert_nothing_raised do
169
- ExampleDirContainer.verify!($dir_managed)
170
- end
171
- end
172
-
173
- # Create a subclassed container. Check it doesn't verify at first; satisfy
174
- # the conditions; then assert that it verifies correctly.
175
- def test_create_subclassed_dir_container
176
- Dir.mktmpdir do |dir|
177
- filename = File.join(dir, "test.container")
178
-
179
- assert_nothing_raised do
180
- ExampleDirContainer.create(filename, $mimetype) do |c|
181
- assert_raises(ZipContainer::MalformedContainerError) do
182
- c.verify!
183
- end
184
-
185
- Dir.mkdir(File.join(filename, "dir"))
186
- File.open(File.join(filename, "greeting.txt"), "w") do |f|
187
- f.puts "Yo means hello."
188
- end
189
-
190
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
191
- c.verify!
192
- end
193
- end
194
- end
195
- end
196
- end
197
-
198
- # Check that a ManagedZipContainer does not verify immediately after
199
- # creation.
200
- def test_create_bad_subclassed_container
201
- Dir.mktmpdir do |dir|
202
- filename = File.join(dir, "test.container")
203
-
204
- assert_nothing_raised do
205
- ManagedZipContainer.create(filename, $mimetype) do |c|
206
- assert_raises(ZipContainer::MalformedContainerError) do
207
- c.verify!
208
- end
209
- end
210
- end
211
-
212
- refute(ManagedZipContainer.verify?(filename))
213
- assert_raises(ZipContainer::MalformedContainerError) do
214
- ManagedZipContainer.verify!(filename)
215
- end
216
- end
217
- end
218
-
219
- # Check that a ManagedZipContainer does verify when required objects are
220
- # added.
221
- def test_create_subclassed_container
222
- Dir.mktmpdir do |dir|
223
- filename = File.join(dir, "test.container")
224
-
225
- assert_nothing_raised do
226
- ManagedZipContainer.create(filename, $mimetype) do |c|
227
- c.dir.mkdir("src")
228
- c.file.open("index.html", "w") do |f|
229
- f.puts "<html />"
230
- end
231
-
232
- # Test hidden entries before and after creation.
233
- assert_nil(c.find_entry("test", :include_hidden => true))
234
- assert_nil(c.find_entry("test/test.txt", :include_hidden => true))
235
- c.dir.mkdir("test")
236
- c.file.open("test/test.txt", "w") do |f|
237
- f.puts "A test!"
238
- end
239
- assert_not_nil(c.find_entry("test", :include_hidden => true))
240
- assert_not_nil(c.find_entry("test/test.txt", :include_hidden => true))
241
-
242
- # Test deep hidden entries before and after creation.
243
- assert_nil(c.find_entry("test/deep", :include_hidden => true))
244
- assert_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
245
- c.dir.mkdir("test/deep")
246
- c.file.open("test/deep/deep.txt", "w") do |f|
247
- f.puts "A deep test!"
248
- end
249
- assert_not_nil(c.find_entry("test/deep", :include_hidden => true))
250
- assert_not_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
251
- end
252
- end
253
-
254
- assert(ManagedZipContainer.verify?(filename))
255
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
256
- ManagedZipContainer.verify!(filename)
257
- end
258
- end
259
- end
260
-
261
- def test_hidden_entries
262
- assert_nothing_raised do
263
- ManagedZipContainer.open($subclass) do |c|
264
- refute(c.hidden_entry?("src"))
265
- refute(c.hidden_file?("src"))
266
- refute(c.hidden_directory?("src"))
267
-
268
- assert(c.hidden_entry?("test"))
269
- assert(c.hidden_directory?("test"))
270
- assert(c.hidden_entry?("test/"))
271
- assert(c.hidden_directory?("test/"))
272
- refute(c.hidden_file?("test"))
273
-
274
- assert(c.hidden_entry?("test/deep"))
275
- assert(c.hidden_directory?("test/deep"))
276
- assert(c.hidden_entry?("test/deep/deep.txt"))
277
- assert(c.hidden_file?("test/deep/deep.txt"))
278
- end
279
- end
280
- end
281
-
282
- def test_find_entry
283
- assert_nothing_raised do
284
- ManagedZipContainer.open($subclass) do |c|
285
- assert_not_nil(c.find_entry("src"))
286
- assert_not_nil(c.find_entry("src", :include_hidden => true))
287
-
288
- assert_nil(c.find_entry("test"))
289
- assert_nil(c.find_entry("test/test.txt"))
290
- assert_not_nil(c.find_entry("test", :include_hidden => true))
291
- assert_not_nil(c.find_entry("test/test.txt", :include_hidden => true))
292
-
293
- assert_nil(c.find_entry("test/deep"))
294
- assert_nil(c.find_entry("test/deep/deep.txt"))
295
- assert_not_nil(c.find_entry("test/deep", :include_hidden => true))
296
- assert_not_nil(c.find_entry("test/deep/deep.txt", :include_hidden => true))
297
- end
298
- end
299
- end
300
-
301
- def test_get_entry
302
- ManagedZipContainer.open($subclass) do |c|
303
- assert_nothing_raised(Errno::ENOENT) do
304
- c.get_entry("src")
305
- end
306
- assert_nothing_raised(Errno::ENOENT) do
307
- c.get_entry("src", :include_hidden => true)
308
- end
309
-
310
- assert_raise(Errno::ENOENT) do
311
- c.get_entry("test")
312
- end
313
- assert_raise(Errno::ENOENT) do
314
- c.get_entry("test/test.txt")
315
- end
316
- assert_nothing_raised(Errno::ENOENT) do
317
- c.get_entry("test", :include_hidden => true)
318
- end
319
- assert_nothing_raised(Errno::ENOENT) do
320
- c.get_entry("test/test.txt", :include_hidden => true)
321
- end
322
-
323
- assert_raise(Errno::ENOENT) do
324
- c.get_entry("test/deep")
325
- end
326
- assert_raise(Errno::ENOENT) do
327
- c.get_entry("test/deep/deep.txt")
328
- end
329
- assert_nothing_raised(Errno::ENOENT) do
330
- c.get_entry("test/deep", :include_hidden => true)
331
- end
332
- assert_nothing_raised(Errno::ENOENT) do
333
- c.get_entry("test/deep/deep.txt", :include_hidden => true)
334
- end
335
- end
336
- end
337
-
338
- def test_glob
339
- ManagedZipContainer.open($subclass) do |c|
340
- assert_equal(["index.html"], entry_list_names(c.glob("in*")))
341
- assert_equal([], c.glob("test/**/*"))
342
- assert_equal(["test/test.txt", "test/deep", "test/deep/deep.txt"],
343
- entry_list_names(c.glob("test/**/*", :include_hidden => true)))
344
- assert_equal(["test/test.txt", "test/deep/deep.txt"],
345
- entry_list_names(c.glob("**/*.TXT", ::File::FNM_CASEFOLD,
346
- :include_hidden => true)))
347
- end
348
- end
349
-
350
- def test_create_subclassed_mimetype
351
- Dir.mktmpdir do |dir|
352
- filename = File.join(dir, "test.container")
353
-
354
- assert_nothing_raised do
355
- ExampleZipContainer2.create(filename) do |c|
356
- assert(c.file.exists?("mimetype"))
357
- assert_equal("application/example+zip", c.file.read("mimetype"))
358
- end
359
- end
360
- end
361
- end
362
-
363
- # Check that an ExampleZipContainer2 will only verify when required objects
364
- # are added with the correct contents.
365
- def test_create_subclassed_container_with_content_verification
366
- Dir.mktmpdir do |dir|
367
- filename = File.join(dir, "test.container")
368
-
369
- assert_nothing_raised do
370
- ExampleZipContainer2.create(filename) do |c|
371
- assert_raises(ZipContainer::MalformedContainerError) do
372
- c.verify!
373
- end
374
-
375
- c.file.open("greeting.txt", "w") do |f|
376
- f.puts "Goodbye!"
377
- end
378
-
379
- assert_raises(ZipContainer::MalformedContainerError) do
380
- c.verify!
381
- end
382
-
383
- c.file.open("greeting.txt", "w") do |f|
384
- f.puts "Hello, Y'All!"
385
- end
386
-
387
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
388
- c.verify!
389
- end
390
- end
391
- end
392
-
393
- assert(ExampleZipContainer2.verify?(filename))
394
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
395
- ExampleZipContainer2.verify!(filename)
396
- end
397
- end
398
- end
399
-
400
- # Check that an ExampleZipContainer2 will verify when deep objects are added
401
- # with the correct contents.
402
- def test_create_subclassed_container_with_deep_content_verification
403
- Dir.mktmpdir do |dir|
404
- filename = File.join(dir, "test.container")
405
-
406
- assert_nothing_raised do
407
- ExampleZipContainer2.create(filename) do |c|
408
- assert_raises(ZipContainer::MalformedContainerError) do
409
- c.verify!
410
- end
411
-
412
- c.file.open("greeting.txt", "w") do |f|
413
- f.puts "Hello, Y'All!"
414
- end
415
-
416
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
417
- c.verify!
418
- end
419
-
420
- c.mkdir("dir")
421
- c.file.open("dir/greet.txt", "w") do |f|
422
- f.puts "Goodbye!"
423
- end
424
-
425
- assert_raises(ZipContainer::MalformedContainerError) do
426
- c.verify!
427
- end
428
-
429
- c.file.open("dir/greet.txt", "w") do |f|
430
- f.puts "hello everyone."
431
- end
432
-
433
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
434
- c.verify!
435
- end
436
- end
437
- end
438
-
439
- assert(ExampleZipContainer2.verify?(filename))
440
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
441
- ExampleZipContainer2.verify!(filename)
442
- end
443
- end
444
- end
445
-
446
- end