ucf 2.0.2 → 3.0.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/latest-docs.yml +29 -0
  3. data/.github/workflows/lint.yml +19 -0
  4. data/.github/workflows/tests.yml +89 -0
  5. data/.gitignore +3 -0
  6. data/.rubocop.yml +63 -0
  7. data/{test/tc_read_dir.rb → .simplecov} +19 -21
  8. data/{Changes.rdoc → CHANGES.md} +41 -14
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/CONTRIBUTING.md +67 -0
  11. data/Gemfile +4 -2
  12. data/{Licence.rdoc → LICENCE} +1 -1
  13. data/README.md +57 -0
  14. data/Rakefile +21 -18
  15. data/bin/console +15 -0
  16. data/bin/setup +6 -0
  17. data/examples/create-ucf +11 -10
  18. data/examples/ucfinfo +11 -7
  19. data/examples/verify-ucf +5 -3
  20. data/lib/ucf/dir.rb +7 -8
  21. data/lib/ucf/file.rb +7 -8
  22. data/lib/ucf/{meta-inf.rb → meta_inf.rb} +24 -23
  23. data/lib/ucf/version.rb +6 -13
  24. data/lib/ucf.rb +4 -2
  25. data/ucf.gemspec +46 -31
  26. metadata +108 -83
  27. data/.ruby-env +0 -1
  28. data/.ruby-gemset +0 -1
  29. data/.ruby-version +0 -1
  30. data/.travis.yml +0 -19
  31. data/ReadMe.rdoc +0 -90
  32. data/test/data/META-INF/container.xml +0 -13
  33. data/test/data/META-INF/manifest.xml +0 -26
  34. data/test/data/compressed_mimetype.ucf +0 -0
  35. data/test/data/dirs/empty/mimetype +0 -1
  36. data/test/data/dirs/managed/greeting.txt +0 -1
  37. data/test/data/dirs/managed/mimetype +0 -1
  38. data/test/data/dirs/null/.gitkeep +0 -1
  39. data/test/data/empty.ucf +0 -0
  40. data/test/data/empty.zip +0 -0
  41. data/test/data/example.ucf +0 -0
  42. data/test/data/null.file +0 -0
  43. data/test/tc_create_file.rb +0 -142
  44. data/test/tc_managed_entries.rb +0 -238
  45. data/test/tc_read_file.rb +0 -119
  46. data/test/tc_reserved_names.rb +0 -357
  47. data/test/ts_ucf.rb +0 -52
  48. data/version.yml +0 -4
@@ -1,238 +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 'ucf'
36
-
37
- # Classes to test managed entries.
38
- class ManagedUCF < UCF::File
39
-
40
- private_class_method :new
41
-
42
- def initialize(filename)
43
- super(filename)
44
- register_managed_entry(ZipContainer::ManagedDirectory.new("src",
45
- :required => true))
46
- register_managed_entry(ZipContainer::ManagedDirectory.new("test"))
47
- register_managed_entry(ZipContainer::ManagedDirectory.new("lib"))
48
- register_managed_entry(ZipContainer::ManagedFile.new("index.html",
49
- :required => true))
50
- end
51
-
52
- end
53
-
54
- class ExampleUCF < UCF::File
55
-
56
- private_class_method :new
57
-
58
- def initialize(filename)
59
- super(filename)
60
- register_managed_entry(ZipContainer::ManagedDirectory.new("dir",
61
- :required => true))
62
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
63
- :required => true))
64
- end
65
-
66
- end
67
-
68
- class ExampleUCF2 < UCF::File
69
-
70
- private_class_method :new
71
-
72
- def initialize(filename)
73
- super(filename)
74
-
75
- valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
76
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
77
- :required => true, :validation_proc => valid))
78
- end
79
-
80
- end
81
-
82
- class ExampleUCFDir < UCF::Dir
83
-
84
- private_class_method :new
85
-
86
- def initialize(filename)
87
- super(filename)
88
-
89
- valid = Proc.new { |contents| contents.match(/[Hh]ello/) }
90
-
91
- register_managed_entry(ZipContainer::ManagedFile.new("greeting.txt",
92
- :required => true, :validation_proc => valid))
93
- end
94
-
95
- end
96
-
97
- class TestManagedEntries < Test::Unit::TestCase
98
-
99
- # Check that the example UCF document does not validate as a ManagedUCF.
100
- def test_fail_verification
101
- refute(ManagedUCF.verify?($ucf_example))
102
-
103
- assert_raises(ZipContainer::MalformedContainerError) do
104
- ManagedUCF.verify!($ucf_example)
105
- end
106
- end
107
-
108
- # Check that the example UCF document does validate as an ExampleUCF.
109
- def test_pass_verification
110
- assert(ExampleUCF.verify?($ucf_example))
111
-
112
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
113
- ExampleUCF.verify!($ucf_example)
114
- end
115
- end
116
-
117
- # Check that the example UCF document does validate as an ExampleUCF2.
118
- def test_pass_verification_2
119
- assert(ExampleUCF2.verify?($ucf_example))
120
-
121
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
122
- ExampleUCF2.verify!($ucf_example)
123
- end
124
- end
125
-
126
- # Check that the example UCF directory validates.
127
- def test_pass_verification_dir
128
- assert(ExampleUCFDir.verify?($dir_mngd))
129
-
130
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
131
- ExampleUCFDir.verify!($dir_mngd)
132
- end
133
- end
134
-
135
- # Check that a standard UCF Container can be created and things within it
136
- # are verified correctly.
137
- def test_create_standard_container
138
- Dir.mktmpdir do |dir|
139
- filename = File.join(dir, "test.ucf")
140
-
141
- assert_nothing_raised do
142
- UCF::File.create(filename) do |c|
143
- c.mkdir("META-INF")
144
- assert(c.file.exists?("META-INF"))
145
-
146
- %w(container.xml manifest.xml).each do |file|
147
- full_path = "META-INF/#{file}"
148
- c.add(full_path, File.join($meta_inf_dir, file))
149
- assert(c.file.exists?(full_path))
150
- end
151
- end
152
- end
153
-
154
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
155
- UCF::File.verify!(filename)
156
- end
157
- end
158
- end
159
-
160
- # Check that a ManagedUCF does not verify immediately after creation.
161
- def test_create_bad_subclassed_container
162
- Dir.mktmpdir do |dir|
163
- filename = File.join(dir, "test.ucf")
164
-
165
- assert_nothing_raised do
166
- ManagedUCF.create(filename) do |c|
167
- assert_raises(ZipContainer::MalformedContainerError) do
168
- c.verify!
169
- end
170
- end
171
- end
172
-
173
- refute(ManagedUCF.verify?(filename))
174
- assert_raises(ZipContainer::MalformedContainerError) do
175
- ManagedUCF.verify!(filename)
176
- end
177
- end
178
- end
179
-
180
- # Check that a ManagedUCF does verify when required objects are added.
181
- def test_create_subclassed_container
182
- Dir.mktmpdir do |dir|
183
- filename = File.join(dir, "test.ucf")
184
-
185
- assert_nothing_raised do
186
- ManagedUCF.create(filename) do |c|
187
- c.dir.mkdir("src")
188
- c.file.open("index.html", "w") do |f|
189
- f.puts "<html />"
190
- end
191
- end
192
- end
193
-
194
- assert(ManagedUCF.verify?(filename))
195
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
196
- ManagedUCF.verify!(filename)
197
- end
198
- end
199
- end
200
-
201
- # Check that a ExampleUCF2 will only verify when required objects are added
202
- # with the correct contents.
203
- def test_create_subclassed_container_with_content_verification
204
- Dir.mktmpdir do |dir|
205
- filename = File.join(dir, "test.ucf")
206
-
207
- #assert_nothing_raised do
208
- ExampleUCF2.create(filename) do |c|
209
- assert_raises(ZipContainer::MalformedContainerError) do
210
- c.verify!
211
- end
212
-
213
- c.file.open("greeting.txt", "w") do |f|
214
- f.puts "Goodbye!"
215
- end
216
-
217
- assert_raises(ZipContainer::MalformedContainerError) do
218
- c.verify!
219
- end
220
-
221
- c.file.open("greeting.txt", "w") do |f|
222
- f.puts "Hello, Y'All!"
223
- end
224
-
225
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
226
- c.verify!
227
- end
228
- end
229
- #end
230
-
231
- assert(ExampleUCF2.verify?(filename))
232
- assert_nothing_raised(ZipContainer::MalformedContainerError) do
233
- ExampleUCF2.verify!(filename)
234
- end
235
- end
236
- end
237
-
238
- end
data/test/tc_read_file.rb DELETED
@@ -1,119 +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 'ucf'
35
-
36
- class TestReadFile < Test::Unit::TestCase
37
-
38
- # Check that the null file does not verify.
39
- def test_verify_null_file
40
- assert_raise(ZipContainer::Error) do
41
- UCF::File.verify!($file_null)
42
- end
43
-
44
- assert_raise(ZipContainer::Error) do
45
- UCF::File.verify?($file_null)
46
- end
47
- end
48
-
49
- # Check that the empty ucf file does verify.
50
- def test_verify_empty_ucf
51
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::Error) do
52
- UCF::File.verify!($ucf_empty)
53
- end
54
-
55
- assert(UCF::File.verify?($ucf_empty))
56
- end
57
-
58
- # Check that the example ucf file does verify.
59
- def test_verify_example_ucf
60
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::Error) do
61
- UCF::File.verify!($ucf_example)
62
- end
63
-
64
- assert(UCF::File.verify?($ucf_example))
65
- end
66
-
67
- # Check that the empty zip file does not verify.
68
- def test_verify_empty_zip
69
- assert_raise(ZipContainer::MalformedContainerError) do
70
- UCF::File.verify!($zip_empty)
71
- end
72
-
73
- refute(UCF::File.verify?($zip_empty))
74
- end
75
-
76
- # Check that a compressed mimetype file is detected.
77
- def test_verify_compressed_mimetype
78
- assert_raise(ZipContainer::MalformedContainerError) do
79
- UCF::File.verify!($ucf_compressed_mimetype)
80
- end
81
-
82
- refute(UCF::File.verify?($ucf_compressed_mimetype))
83
- end
84
-
85
- # Check the raw mimetype bytes
86
- def test_raw_mimetypes
87
- empty_ucf = File.read($ucf_empty)
88
- assert_equal("application/epub+zip", empty_ucf[38..57])
89
-
90
- compressed_mimetype = File.read($ucf_compressed_mimetype)
91
- assert_not_equal("application/epub+zip", compressed_mimetype[38..57])
92
- end
93
-
94
- # Check reading files out of a ucf file and make sure we don't change it.
95
- def test_read_files_from_ucf
96
- assert_nothing_raised(ZipContainer::MalformedContainerError, ZipContainer::Error) do
97
- UCF::File.open($ucf_example) do |ucf|
98
- assert(ucf.on_disk?)
99
- refute(ucf.in_memory?)
100
-
101
- assert(ucf.file.exists?("greeting.txt"))
102
-
103
- greeting = ucf.file.read("greeting.txt")
104
- assert_equal("Hello, World!\n", greeting)
105
-
106
- assert(ucf.file.exists?("dir"))
107
- assert(ucf.file.directory?("dir"))
108
-
109
- assert(ucf.file.exists?("dir/code.rb"))
110
-
111
- assert_equal("This is an example UCF file!", ucf.comment)
112
-
113
- refute(ucf.commit_required?)
114
- refute(ucf.commit)
115
- end
116
- end
117
- end
118
-
119
- end