ucf 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,75 +32,116 @@
32
32
 
33
33
  require 'ucf'
34
34
 
35
- # A class to test the overriding of reserved names.
35
+ # A class to test the overriding of reserved and managed names.
36
36
  class NewUCF < UCF::Container
37
- def reserved_files
38
- super + ["index.html"]
39
- end
40
37
 
41
- def reserved_directories
42
- super + ["src", "test", "lib"]
38
+ private_class_method :new
39
+
40
+ def initialize(filename)
41
+ super(filename)
42
+ register_managed_entry(UCF::ManagedDirectory.new("src"))
43
+ register_managed_entry(UCF::ManagedDirectory.new("test"))
44
+ register_managed_entry(UCF::ManagedDirectory.new("lib"))
45
+ register_managed_entry(UCF::ManagedFile.new("index.html"))
46
+
47
+ register_reserved_name("reserved_dir")
43
48
  end
49
+
44
50
  end
45
51
 
46
52
  class TestReservedNames < Test::Unit::TestCase
47
53
 
54
+ # Check that the reserved names verify correctly.
55
+ def test_verify_reserved_name
56
+ assert(NewUCF.verify($ucf_example))
57
+
58
+ assert_nothing_raised(UCF::MalformedUCFError) do
59
+ NewUCF.verify!($ucf_example)
60
+ end
61
+ end
62
+
48
63
  # Check the reserved names stuff all works correctly, baring in mind that
49
64
  # such comparisons for UCF documents should be case sensitive.
50
65
  def test_reserved_names
51
66
  UCF::Container.open($ucf_example) do |ucf|
52
- assert_equal(1, ucf.reserved_files.length)
53
- assert_equal(["mimetype"], ucf.reserved_files)
67
+ assert_equal(1, ucf.reserved_names.length)
68
+ assert_equal(["mimetype"], ucf.reserved_names)
69
+ assert_equal(6, ucf.managed_files.length)
70
+ assert_equal(["META-INF/container.xml",
71
+ "META-INF/manifest.xml", "META-INF/metadata.xml",
72
+ "META-INF/signatures.xml", "META-INF/encryption.xml",
73
+ "META-INF/rights.xml"], ucf.managed_file_names)
54
74
  assert(ucf.reserved_entry?("mimetype"))
55
75
  assert(ucf.reserved_entry?("mimetype/"))
56
76
  assert(ucf.reserved_entry?("MimeType"))
57
-
58
- assert_equal(1, ucf.reserved_directories.length)
59
- assert_equal(["META-INF"], ucf.reserved_directories)
60
- assert(ucf.reserved_entry?("META-INF"))
61
- assert(ucf.reserved_entry?("META-INF/"))
62
- assert(ucf.reserved_entry?("MeTa-iNf"))
63
- assert(ucf.reserved_entry?("MeTa-iNf/"))
64
-
65
- assert_equal(2, ucf.reserved_names.length)
66
- assert_equal(["mimetype", "META-INF"], ucf.reserved_names)
67
-
68
- refute(ucf.reserved_entry?("This_should_fail"))
69
- refute(ucf.reserved_entry?("META_INF"))
70
- refute(ucf.reserved_entry?("META_INF/"))
77
+ assert(ucf.managed_entry?("META-INF/container.xml"))
78
+ assert(ucf.managed_entry?("META-INF/manifest.xml"))
79
+ assert(ucf.managed_entry?("MeTa-INF/maniFest.XML"))
80
+
81
+ assert_equal(1, ucf.managed_directories.length)
82
+ assert_equal(["META-INF"], ucf.managed_directory_names)
83
+ assert(ucf.managed_entry?("META-INF"))
84
+ assert(ucf.managed_entry?("META-INF/"))
85
+ assert(ucf.managed_entry?("MeTa-iNf"))
86
+ assert(ucf.managed_entry?("MeTa-iNf/"))
87
+ refute(ucf.reserved_entry?("META-INF"))
88
+
89
+ assert_equal(7, ucf.managed_entries.length)
90
+ assert_equal(["META-INF/container.xml",
91
+ "META-INF/manifest.xml", "META-INF/metadata.xml",
92
+ "META-INF/signatures.xml", "META-INF/encryption.xml",
93
+ "META-INF/rights.xml", "META-INF"], ucf.managed_entry_names)
94
+
95
+ refute(ucf.managed_entry?("This_should_fail"))
96
+ refute(ucf.managed_entry?("META_INF"))
97
+ refute(ucf.managed_entry?("META_INF/"))
71
98
  end
72
99
  end
73
100
 
74
101
  # Check that overriding the reserved names in a sub-class works correctly
75
102
  def test_subclass_reserved_names
76
103
  NewUCF.open($ucf_example) do |ucf|
77
- assert_equal(2, ucf.reserved_files.length)
78
- assert_equal(["mimetype", "index.html"], ucf.reserved_files)
104
+ assert_equal(2, ucf.reserved_names.length)
105
+ assert_equal(["mimetype", "reserved_dir"], ucf.reserved_names)
106
+ assert_equal(7, ucf.managed_files.length)
107
+ assert_equal(["index.html", "META-INF/container.xml",
108
+ "META-INF/manifest.xml", "META-INF/metadata.xml",
109
+ "META-INF/signatures.xml", "META-INF/encryption.xml",
110
+ "META-INF/rights.xml"], ucf.managed_file_names)
79
111
  assert(ucf.reserved_entry?("mimetype"))
80
112
  assert(ucf.reserved_entry?("mimetype/"))
81
113
  assert(ucf.reserved_entry?("MimeType"))
82
- assert(ucf.reserved_entry?("index.html"))
83
- assert(ucf.reserved_entry?("Index.HTML"))
84
-
85
- assert_equal(4, ucf.reserved_directories.length)
86
- assert_equal(["META-INF", "src", "test", "lib"], ucf.reserved_directories)
87
- assert(ucf.reserved_entry?("META-INF"))
88
- assert(ucf.reserved_entry?("META-INF/"))
89
- assert(ucf.reserved_entry?("MeTa-iNf"))
90
- assert(ucf.reserved_entry?("src"))
91
- assert(ucf.reserved_entry?("SRC"))
92
- assert(ucf.reserved_entry?("test"))
93
- assert(ucf.reserved_entry?("lib"))
94
- assert(ucf.reserved_entry?("lIb/"))
95
-
96
- assert_equal(6, ucf.reserved_names.length)
97
- assert_equal(["mimetype", "index.html", "META-INF", "src", "test", "lib"],
98
- ucf.reserved_names)
99
-
100
- refute(ucf.reserved_entry?("This_should_fail"))
101
- refute(ucf.reserved_entry?("META_INF"))
102
- refute(ucf.reserved_entry?("META_INF/"))
103
- refute(ucf.reserved_entry?("index.htm"))
114
+ assert(ucf.managed_entry?("index.html"))
115
+ assert(ucf.managed_entry?("Index.HTML"))
116
+ refute(ucf.reserved_entry?("index.html"))
117
+
118
+ assert_equal(4, ucf.managed_directories.length)
119
+ assert_equal(["META-INF", "src", "test", "lib"],
120
+ ucf.managed_directory_names)
121
+ assert(ucf.managed_entry?("META-INF"))
122
+ assert(ucf.managed_entry?("META-INF/"))
123
+ assert(ucf.managed_entry?("MeTa-iNf"))
124
+ assert(ucf.managed_entry?("src"))
125
+ assert(ucf.managed_entry?("SRC"))
126
+ assert(ucf.managed_entry?("test"))
127
+ assert(ucf.managed_entry?("lib"))
128
+ assert(ucf.managed_entry?("lIb/"))
129
+ refute(ucf.reserved_entry?("META-INF"))
130
+ refute(ucf.reserved_entry?("src"))
131
+ refute(ucf.reserved_entry?("test"))
132
+ refute(ucf.reserved_entry?("lib"))
133
+
134
+ assert_equal(11, ucf.managed_entries.length)
135
+ assert_equal(["index.html", "META-INF/container.xml",
136
+ "META-INF/manifest.xml", "META-INF/metadata.xml",
137
+ "META-INF/signatures.xml", "META-INF/encryption.xml",
138
+ "META-INF/rights.xml", "META-INF", "src", "test", "lib"],
139
+ ucf.managed_entry_names)
140
+
141
+ refute(ucf.managed_entry?("This_should_fail"))
142
+ refute(ucf.managed_entry?("META_INF"))
143
+ refute(ucf.managed_entry?("META_INF/"))
144
+ refute(ucf.managed_entry?("index.htm"))
104
145
  end
105
146
  end
106
147
 
@@ -148,30 +189,40 @@ class TestReservedNames < Test::Unit::TestCase
148
189
  def test_subclass_add_reserved
149
190
  NewUCF.open($ucf_empty) do |ucf|
150
191
  assert_raises(UCF::ReservedNameClashError) do
151
- ucf.add("META-INF", $zip_empty)
192
+ ucf.add("mimetype", $zip_empty)
193
+ end
194
+
195
+ assert_raises(UCF::ReservedNameClashError) do
196
+ ucf.add("reserved_dir", $zip_empty)
152
197
  end
153
198
 
154
199
  assert_raises(UCF::ReservedNameClashError) do
155
- ucf.add("index.html", $zip_empty)
200
+ ucf.add("MimeType", $zip_empty)
156
201
  end
157
202
 
158
203
  assert_raises(UCF::ReservedNameClashError) do
159
- ucf.add("SRC", $zip_empty)
204
+ ucf.add("Reserved_Dir", $zip_empty)
160
205
  end
161
206
  end
162
207
  end
163
208
 
164
- # Check that nothing happens when trying to delete the META-INF directory.
209
+ # Check that the META-INF directory is detected as non-existent when trying
210
+ # to delete it.
165
211
  def test_delete_metainf
166
212
  UCF::Container.open($ucf_example) do |ucf|
167
- assert_nil(ucf.remove("META-INF"))
213
+ assert_raises(Errno::ENOENT) do
214
+ ucf.remove("META-INF")
215
+ end
168
216
  end
169
217
  end
170
218
 
171
- # Check that nothing happens when trying to rename the META-INF directory.
219
+ # Check that the META-INF directory is detected as non-existent when trying
220
+ # to rename it.
172
221
  def test_rename_metainf
173
222
  UCF::Container.open($ucf_example) do |ucf|
174
- assert_nil(ucf.rename("META-INF", "something-else"))
223
+ assert_raises(Errno::ENOENT) do
224
+ ucf.rename("META-INF", "something-else")
225
+ end
175
226
  end
176
227
  end
177
228
 
@@ -180,7 +231,11 @@ class TestReservedNames < Test::Unit::TestCase
180
231
  def test_mkdir_reserved
181
232
  UCF::Container.open($ucf_empty) do |ucf|
182
233
  assert_raises(UCF::ReservedNameClashError) do
183
- ucf.mkdir("META-INF")
234
+ ucf.mkdir("mimetype")
235
+ end
236
+
237
+ assert_raises(UCF::ReservedNameClashError) do
238
+ ucf.mkdir("META-INF/container.xml")
184
239
  end
185
240
  end
186
241
  end
@@ -190,7 +245,7 @@ class TestReservedNames < Test::Unit::TestCase
190
245
  def test_subclass_mkdir_reserved
191
246
  NewUCF.open($ucf_empty) do |ucf|
192
247
  assert_raises(UCF::ReservedNameClashError) do
193
- ucf.mkdir("META-INF")
248
+ ucf.mkdir("mimetype")
194
249
  end
195
250
 
196
251
  assert_raises(UCF::ReservedNameClashError) do
@@ -198,7 +253,15 @@ class TestReservedNames < Test::Unit::TestCase
198
253
  end
199
254
 
200
255
  assert_raises(UCF::ReservedNameClashError) do
201
- ucf.mkdir("Lib")
256
+ ucf.mkdir("reserved_dir")
257
+ end
258
+
259
+ assert_raises(UCF::ReservedNameClashError) do
260
+ ucf.mkdir("Reserved_Dir")
261
+ end
262
+
263
+ assert_raises(UCF::ReservedNameClashError) do
264
+ ucf.mkdir("META-INF/container.xml")
202
265
  end
203
266
  end
204
267
  end
@@ -209,10 +272,6 @@ class TestReservedNames < Test::Unit::TestCase
209
272
  assert_raises(UCF::ReservedNameClashError) do
210
273
  ucf.rename("dir/code.rb", "mimetype")
211
274
  end
212
-
213
- assert_raises(UCF::ReservedNameClashError) do
214
- ucf.rename("dir", "META-INF")
215
- end
216
275
  end
217
276
  end
218
277
 
@@ -225,20 +284,13 @@ class TestReservedNames < Test::Unit::TestCase
225
284
  end
226
285
 
227
286
  assert_raises(UCF::ReservedNameClashError) do
228
- ucf.rename("dir", "META-INF")
229
- end
230
-
231
- assert_raises(UCF::ReservedNameClashError) do
232
- ucf.rename("dir/code.rb", "index.html")
233
- end
234
-
235
- assert_raises(UCF::ReservedNameClashError) do
236
- ucf.rename("dir", "Test")
287
+ ucf.rename("dir", "reserved_dir")
237
288
  end
238
289
  end
239
290
  end
240
291
 
241
- # Check that the ruby-like File and Dir classes respect reserved names.
292
+ # Check that the ruby-like File and Dir classes respect reserved and managed
293
+ # names.
242
294
  def test_file_dir_ops_reserved
243
295
  UCF::Container.open($ucf_empty) do |ucf|
244
296
  assert_raises(UCF::ReservedNameClashError) do
@@ -257,10 +309,6 @@ class TestReservedNames < Test::Unit::TestCase
257
309
  ucf.file.delete("mimetype")
258
310
  assert(ucf.file.exists?("mimetype"))
259
311
  end
260
-
261
- assert_raises(UCF::ReservedNameClashError) do
262
- ucf.dir.mkdir("meta-inf")
263
- end
264
312
  end
265
313
  end
266
314
 
@@ -275,7 +323,7 @@ class TestReservedNames < Test::Unit::TestCase
275
323
  end
276
324
 
277
325
  assert_raises(UCF::ReservedNameClashError) do
278
- ucf.file.open("INDEX.HTML", "w") do |f|
326
+ ucf.file.open("TEST", "w") do |f|
279
327
  f.puts "TESTING"
280
328
  end
281
329
  end
@@ -292,15 +340,15 @@ class TestReservedNames < Test::Unit::TestCase
292
340
  end
293
341
 
294
342
  assert_raises(UCF::ReservedNameClashError) do
295
- ucf.dir.mkdir("meta-inf")
343
+ ucf.dir.mkdir("index.html")
296
344
  end
297
345
 
298
346
  assert_raises(UCF::ReservedNameClashError) do
299
- ucf.dir.mkdir("TEST")
347
+ ucf.dir.mkdir("reserved_dir")
300
348
  end
301
349
 
302
350
  assert_raises(UCF::ReservedNameClashError) do
303
- ucf.dir.mkdir("index.html")
351
+ ucf.dir.mkdir("Reserved_Dir")
304
352
  end
305
353
  end
306
354
  end
data/test/ts_ucf.rb CHANGED
@@ -43,3 +43,4 @@ $ucf_example = "test/data/example.ucf"
43
43
  require 'tc_create'
44
44
  require 'tc_read'
45
45
  require 'tc_reserved_names'
46
+ require 'tc_managed_entries'
data/ucf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ucf"
8
- s.version = "0.1.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Haines"]
12
- s.date = "2013-06-03"
12
+ s.date = "2013-06-26"
13
13
  s.description = "A Ruby library for working with Universal Container Format files. See https://learn.adobe.com/wiki/display/PDFNAV/Universal+Container+Format for the specification."
14
14
  s.email = ["support@mygrid.org.uk"]
15
15
  s.extra_rdoc_files = [
@@ -27,13 +27,20 @@ Gem::Specification.new do |s|
27
27
  "examples/verify_ucf.rb",
28
28
  "lib/ucf.rb",
29
29
  "lib/ucf/container.rb",
30
+ "lib/ucf/entries/directory.rb",
31
+ "lib/ucf/entries/entry.rb",
32
+ "lib/ucf/entries/file.rb",
33
+ "lib/ucf/entries/managed.rb",
34
+ "lib/ucf/entries/reserved.rb",
30
35
  "lib/ucf/exceptions.rb",
36
+ "lib/ucf/meta-inf.rb",
31
37
  "test/data/compressed_mimetype.ucf",
32
38
  "test/data/empty.ucf",
33
39
  "test/data/empty.zip",
34
40
  "test/data/example.ucf",
35
41
  "test/data/null.file",
36
42
  "test/tc_create.rb",
43
+ "test/tc_managed_entries.rb",
37
44
  "test/tc_read.rb",
38
45
  "test/tc_reserved_names.rb",
39
46
  "test/ts_ucf.rb",
data/version.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
3
+ :minor: 5
4
4
  :patch: 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
12
+ date: 2013-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -95,13 +95,20 @@ files:
95
95
  - examples/verify_ucf.rb
96
96
  - lib/ucf.rb
97
97
  - lib/ucf/container.rb
98
+ - lib/ucf/entries/directory.rb
99
+ - lib/ucf/entries/entry.rb
100
+ - lib/ucf/entries/file.rb
101
+ - lib/ucf/entries/managed.rb
102
+ - lib/ucf/entries/reserved.rb
98
103
  - lib/ucf/exceptions.rb
104
+ - lib/ucf/meta-inf.rb
99
105
  - test/data/compressed_mimetype.ucf
100
106
  - test/data/empty.ucf
101
107
  - test/data/empty.zip
102
108
  - test/data/example.ucf
103
109
  - test/data/null.file
104
110
  - test/tc_create.rb
111
+ - test/tc_managed_entries.rb
105
112
  - test/tc_read.rb
106
113
  - test/tc_reserved_names.rb
107
114
  - test/ts_ucf.rb