origami-docspring 2.2.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/examples/attachments/attachment.rb +7 -8
- data/examples/attachments/nested_document.rb +6 -5
- data/examples/encryption/encryption.rb +5 -4
- data/examples/events/events.rb +7 -6
- data/examples/flash/flash.rb +10 -9
- data/examples/forms/javascript.rb +14 -13
- data/examples/forms/xfa.rb +67 -66
- data/examples/javascript/hello_world.rb +6 -5
- data/examples/javascript/js_emulation.rb +26 -26
- data/examples/loop/goto.rb +12 -11
- data/examples/loop/named.rb +17 -16
- data/examples/signature/signature.rb +11 -11
- data/examples/uri/javascript.rb +25 -24
- data/examples/uri/open-uri.rb +5 -4
- data/examples/uri/submitform.rb +11 -10
- data/lib/origami/3d.rb +330 -334
- data/lib/origami/acroform.rb +267 -268
- data/lib/origami/actions.rb +266 -278
- data/lib/origami/annotations.rb +659 -670
- data/lib/origami/array.rb +192 -196
- data/lib/origami/boolean.rb +66 -70
- data/lib/origami/catalog.rb +360 -363
- data/lib/origami/collections.rb +132 -133
- data/lib/origami/compound.rb +125 -129
- data/lib/origami/destinations.rb +226 -237
- data/lib/origami/dictionary.rb +155 -154
- data/lib/origami/encryption.rb +967 -923
- data/lib/origami/extensions/fdf.rb +270 -275
- data/lib/origami/extensions/ppklite.rb +323 -328
- data/lib/origami/filespec.rb +170 -173
- data/lib/origami/filters/ascii.rb +162 -167
- data/lib/origami/filters/ccitt/tables.rb +248 -252
- data/lib/origami/filters/ccitt.rb +309 -312
- data/lib/origami/filters/crypt.rb +31 -34
- data/lib/origami/filters/dct.rb +47 -50
- data/lib/origami/filters/flate.rb +57 -60
- data/lib/origami/filters/jbig2.rb +50 -53
- data/lib/origami/filters/jpx.rb +40 -43
- data/lib/origami/filters/lzw.rb +151 -155
- data/lib/origami/filters/predictors.rb +250 -255
- data/lib/origami/filters/runlength.rb +111 -115
- data/lib/origami/filters.rb +319 -325
- data/lib/origami/font.rb +173 -177
- data/lib/origami/functions.rb +62 -66
- data/lib/origami/graphics/colors.rb +203 -208
- data/lib/origami/graphics/instruction.rb +79 -81
- data/lib/origami/graphics/path.rb +141 -144
- data/lib/origami/graphics/patterns.rb +156 -160
- data/lib/origami/graphics/render.rb +51 -47
- data/lib/origami/graphics/state.rb +144 -142
- data/lib/origami/graphics/text.rb +185 -188
- data/lib/origami/graphics/xobject.rb +818 -804
- data/lib/origami/graphics.rb +25 -26
- data/lib/origami/header.rb +63 -65
- data/lib/origami/javascript.rb +718 -651
- data/lib/origami/linearization.rb +284 -285
- data/lib/origami/metadata.rb +156 -135
- data/lib/origami/name.rb +98 -100
- data/lib/origami/null.rb +49 -51
- data/lib/origami/numeric.rb +133 -135
- data/lib/origami/obfuscation.rb +180 -182
- data/lib/origami/object.rb +634 -631
- data/lib/origami/optionalcontent.rb +147 -149
- data/lib/origami/outline.rb +46 -48
- data/lib/origami/outputintents.rb +76 -77
- data/lib/origami/page.rb +637 -596
- data/lib/origami/parser.rb +214 -221
- data/lib/origami/parsers/fdf.rb +44 -45
- data/lib/origami/parsers/pdf/lazy.rb +147 -154
- data/lib/origami/parsers/pdf/linear.rb +104 -109
- data/lib/origami/parsers/pdf.rb +109 -107
- data/lib/origami/parsers/ppklite.rb +44 -46
- data/lib/origami/pdf.rb +886 -896
- data/lib/origami/reference.rb +116 -120
- data/lib/origami/signature.rb +617 -625
- data/lib/origami/stream.rb +560 -558
- data/lib/origami/string.rb +366 -368
- data/lib/origami/template/patterns.rb +50 -52
- data/lib/origami/template/widgets.rb +111 -114
- data/lib/origami/trailer.rb +153 -157
- data/lib/origami/tree.rb +55 -57
- data/lib/origami/version.rb +19 -19
- data/lib/origami/webcapture.rb +87 -90
- data/lib/origami/xfa/config.rb +409 -414
- data/lib/origami/xfa/connectionset.rb +113 -117
- data/lib/origami/xfa/datasets.rb +38 -42
- data/lib/origami/xfa/localeset.rb +33 -37
- data/lib/origami/xfa/package.rb +49 -52
- data/lib/origami/xfa/pdf.rb +54 -59
- data/lib/origami/xfa/signature.rb +33 -37
- data/lib/origami/xfa/sourceset.rb +34 -38
- data/lib/origami/xfa/stylesheet.rb +35 -39
- data/lib/origami/xfa/template.rb +1630 -1634
- data/lib/origami/xfa/xdc.rb +33 -37
- data/lib/origami/xfa/xfa.rb +132 -123
- data/lib/origami/xfa/xfdf.rb +34 -38
- data/lib/origami/xfa/xmpmeta.rb +34 -38
- data/lib/origami/xfa.rb +50 -53
- data/lib/origami/xreftable.rb +462 -462
- data/lib/origami.rb +37 -38
- data/test/test_actions.rb +22 -20
- data/test/test_annotations.rb +54 -52
- data/test/test_forms.rb +23 -21
- data/test/test_native_types.rb +82 -78
- data/test/test_object_tree.rb +25 -24
- data/test/test_pages.rb +43 -41
- data/test/test_pdf.rb +2 -0
- data/test/test_pdf_attachment.rb +23 -21
- data/test/test_pdf_create.rb +16 -15
- data/test/test_pdf_encrypt.rb +69 -66
- data/test/test_pdf_parse.rb +131 -129
- data/test/test_pdf_parse_lazy.rb +53 -53
- data/test/test_pdf_sign.rb +67 -67
- data/test/test_streams.rb +145 -143
- data/test/test_xrefs.rb +46 -45
- metadata +64 -8
data/test/test_pdf_attachment.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestAttachment < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def setup
|
8
|
+
@target = PDF.new
|
9
|
+
@attachment = StringIO.new("test")
|
10
|
+
@output = StringIO.new
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
def test_attach_file
|
14
|
+
@target.attach_file(@attachment, name: "foo.bar", filter: :A85)
|
13
15
|
|
14
|
-
|
16
|
+
@target.save(@output)
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
@output = @output.reopen(@output.string, "r")
|
19
|
+
pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
assert_equal pdf.each_named_embedded_file.count, 1
|
22
|
+
assert_nil pdf.get_embedded_file_by_name("foo.baz")
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
file = pdf.get_embedded_file_by_name('foo.bar')
|
25
|
+
refute_equal file, nil
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
assert file.key?(:EF)
|
28
|
+
assert file.EF.key?(:F)
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
stream = file.EF.F
|
31
|
+
assert stream.is_a?(Stream)
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
assert_equal stream.dictionary.Filter, :A85
|
34
|
+
assert_equal stream.data, "test"
|
35
|
+
end
|
34
36
|
end
|
data/test/test_pdf_create.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestPDFCreate < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@output = StringIO.new
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_pdf_create
|
11
|
-
pdf = PDF.new
|
11
|
+
def test_pdf_create
|
12
|
+
pdf = PDF.new
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
null = Null.new
|
15
|
+
pdf << null
|
15
16
|
|
16
|
-
|
17
|
+
pdf.save(@output)
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
assert null.indirect?
|
20
|
+
assert_equal null.reference.solve, null
|
21
|
+
assert pdf.root_objects.include?(null)
|
22
|
+
assert_equal pdf.revisions.first.body[null.reference], null
|
23
|
+
assert_equal null.reference.solve, null
|
24
|
+
end
|
24
25
|
end
|
data/test/test_pdf_encrypt.rb
CHANGED
@@ -1,95 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestEncryption < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
include Origami
|
8
|
+
def setup
|
9
|
+
@target = PDF.read(File.join(__dir__, "dataset/calc.pdf"),
|
10
|
+
ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
11
|
+
@output = StringIO.new
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
def test_encrypt_rc4_40b
|
15
|
+
@output = StringIO.new
|
16
|
+
@target.encrypt(cipher: 'rc4', key_size: 40).save(@output)
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
def test_encrypt_rc4_128b
|
20
|
+
@output = StringIO.new
|
21
|
+
@target.encrypt(cipher: 'rc4').save(@output)
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
def test_encrypt_aes_128b
|
25
|
+
@output = StringIO.new
|
26
|
+
@target.encrypt(cipher: 'aes').save(@output)
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
def test_decrypt_rc4_40b
|
30
|
+
@output = StringIO.new
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
pdf = PDF.new.encrypt(cipher: 'rc4', key_size: 40)
|
33
|
+
pdf.Catalog[:Test] = "test"
|
34
|
+
pdf.save(@output)
|
32
35
|
|
33
|
-
|
36
|
+
refute_equal pdf.Catalog[:Test], "test"
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
@output = @output.reopen(@output.string, "r")
|
39
|
+
pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
37
40
|
|
38
|
-
|
39
|
-
|
41
|
+
assert_equal pdf.Catalog[:Test], "test"
|
42
|
+
end
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def test_decrypt_rc4_128b
|
45
|
+
@output = StringIO.new
|
46
|
+
pdf = PDF.new.encrypt(cipher: 'rc4')
|
47
|
+
pdf.Catalog[:Test] = "test"
|
48
|
+
pdf.save(@output)
|
46
49
|
|
47
|
-
|
50
|
+
refute_equal pdf.Catalog[:Test], "test"
|
48
51
|
|
49
|
-
|
50
|
-
|
52
|
+
@output.reopen(@output.string, "r")
|
53
|
+
pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
51
54
|
|
52
|
-
|
53
|
-
|
55
|
+
assert_equal pdf.Catalog[:Test], "test"
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
def test_decrypt_aes_128b
|
59
|
+
@output = StringIO.new
|
60
|
+
pdf = PDF.new.encrypt(cipher: 'aes')
|
61
|
+
pdf.Catalog[:Test] = "test"
|
62
|
+
pdf.save(@output)
|
60
63
|
|
61
|
-
|
64
|
+
refute_equal pdf.Catalog[:Test], "test"
|
62
65
|
|
63
|
-
|
64
|
-
|
66
|
+
@output = @output.reopen(@output.string, "r")
|
67
|
+
pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
assert_equal pdf.Catalog[:Test], "test"
|
70
|
+
end
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def test_decrypt_aes_256b
|
73
|
+
@output = StringIO.new
|
74
|
+
pdf = PDF.new.encrypt(cipher: 'aes', key_size: 256)
|
75
|
+
pdf.Catalog[:Test] = "test"
|
76
|
+
pdf.save(@output)
|
74
77
|
|
75
|
-
|
78
|
+
refute_equal pdf.Catalog[:Test], "test"
|
76
79
|
|
77
|
-
|
78
|
-
|
80
|
+
@output = @output.reopen(@output.string, "r")
|
81
|
+
pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
79
82
|
|
80
|
-
|
81
|
-
|
83
|
+
assert_equal pdf.Catalog[:Test], "test"
|
84
|
+
end
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
def test_crypt_filter
|
87
|
+
@output = StringIO.new
|
88
|
+
pdf = PDF.new.encrypt(cipher: 'aes', key_size: 128)
|
86
89
|
|
87
|
-
|
88
|
-
|
90
|
+
pdf.Catalog[:S1] = Stream.new("test", Filter: :Crypt)
|
91
|
+
pdf.Catalog[:S2] = Stream.new("test")
|
89
92
|
|
90
|
-
|
93
|
+
pdf.save(@output)
|
91
94
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
+
assert_equal pdf.Catalog.S1.encoded_data, "test"
|
96
|
+
refute_equal pdf.Catalog.S2.encoded_data, "test"
|
97
|
+
end
|
95
98
|
end
|
data/test/test_pdf_parse.rb
CHANGED
@@ -1,134 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
|
3
5
|
class TestPDFParser < Minitest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_parse_dictionary
|
26
|
-
dict = Dictionary.parse("<</Ref 2 0 R/N null/Pi 3.14 /D <<>>>>")
|
27
|
-
|
28
|
-
assert_instance_of Dictionary, dict
|
29
|
-
assert_instance_of Dictionary, dict[:D]
|
30
|
-
assert_instance_of Null, dict[:N]
|
31
|
-
assert_instance_of Reference, dict[:Ref]
|
32
|
-
assert_equal dict.size, 4
|
33
|
-
assert_raises(InvalidReferenceError) { dict[:Ref].solve }
|
34
|
-
assert dict[:Pi] == 3.14
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_parse_array
|
38
|
-
array = Origami::Array.parse("[/Test (abc) .2 \n 799 [<<>>]]")
|
39
|
-
|
40
|
-
assert array.all?{|e| e.is_a?(Origami::Object)}
|
41
|
-
assert_equal array.length, 5
|
42
|
-
assert_raises(InvalidArrayObjectError) { Origami::Array.parse("[1 ") }
|
43
|
-
assert_raises(InvalidArrayObjectError) { Origami::Array.parse("") }
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_parse_string
|
47
|
-
str = LiteralString.parse("(\\122\\125by\\n)")
|
48
|
-
assert_instance_of LiteralString, str
|
49
|
-
assert_equal str.value, "RUby\n"
|
50
|
-
|
51
|
-
assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("") }
|
52
|
-
assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("(test") }
|
53
|
-
assert_equal "((O))", LiteralString.parse("(((O)))").value
|
54
|
-
assert_equal LiteralString.parse("(ABC\\\nDEF\\\r\nGHI)").value, "ABCDEFGHI"
|
55
|
-
assert_equal LiteralString.parse('(\r\n\b\t\f\\(\\)\\x\\\\)').value, "\r\n\b\t\f()x\\"
|
56
|
-
assert_equal LiteralString.parse('(\r\n\b\t\f\\\\\\(\\))').to_s, '(\r\n\b\t\f\\\\\\(\\))'
|
57
|
-
|
58
|
-
str = HexaString.parse("<52 55 62 79 0A>")
|
59
|
-
assert_instance_of HexaString, str
|
60
|
-
assert_equal str.value, "RUby\n"
|
61
|
-
|
62
|
-
assert_equal HexaString.parse("<4>").value, 0x40.chr
|
63
|
-
|
64
|
-
assert_raises(InvalidHexaStringObjectError) { HexaString.parse("") }
|
65
|
-
assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12") }
|
66
|
-
assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12X>") }
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_parse_bool
|
70
|
-
b_true = Boolean.parse("true")
|
71
|
-
b_false = Boolean.parse("false")
|
72
|
-
|
73
|
-
assert_instance_of Boolean, b_true
|
74
|
-
assert_instance_of Boolean, b_false
|
75
|
-
|
76
|
-
assert b_false.false?
|
77
|
-
refute b_true.false?
|
78
|
-
|
79
|
-
assert_raises(InvalidBooleanObjectError) { Boolean.parse("") }
|
80
|
-
assert_raises(InvalidBooleanObjectError) { Boolean.parse("tru") }
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_parse_real
|
84
|
-
real = Real.parse("-3.141592653")
|
85
|
-
assert_instance_of Real, real
|
86
|
-
assert_equal real, -3.141592653
|
87
|
-
|
88
|
-
real = Real.parse("+.00200")
|
89
|
-
assert_instance_of Real, real
|
90
|
-
assert_equal real, 0.002
|
91
|
-
|
92
|
-
assert_raises(InvalidRealObjectError) { Real.parse("") }
|
93
|
-
assert_raises(InvalidRealObjectError) { Real.parse(".") }
|
94
|
-
assert_raises(InvalidRealObjectError) { Real.parse("+0x1") }
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_parse_int
|
98
|
-
int = Origami::Integer.parse("02000000000000")
|
99
|
-
assert_instance_of Origami::Integer, int
|
100
|
-
assert_equal int, 2000000000000
|
101
|
-
|
102
|
-
int = Origami::Integer.parse("-98")
|
103
|
-
assert_instance_of Origami::Integer, int
|
104
|
-
assert_equal int, -98
|
105
|
-
|
106
|
-
assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("") }
|
107
|
-
assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("+-1") }
|
108
|
-
assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("ABC") }
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_parse_name
|
112
|
-
name = Name.parse("/#52#55#62#79#0A")
|
113
|
-
assert_instance_of Name, name
|
114
|
-
assert_equal name.value, :"RUby\n"
|
115
|
-
|
116
|
-
name = Name.parse("/")
|
117
|
-
assert_instance_of Name, name
|
118
|
-
assert_equal :"", name.value
|
119
|
-
|
120
|
-
assert_raises(Origami::InvalidNameObjectError) { Name.parse("") }
|
121
|
-
assert_raises(Origami::InvalidNameObjectError) { Name.parse("test") }
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_parse_reference
|
125
|
-
ref = Reference.parse("199 1 R")
|
126
|
-
assert_instance_of Reference, ref
|
127
|
-
|
128
|
-
assert_equal [199, 1], ref.to_a
|
129
|
-
assert_raises(InvalidReferenceError) { ref.solve }
|
130
|
-
assert_raises(InvalidReferenceError) { Reference.parse("-2 0 R") }
|
131
|
-
assert_raises(InvalidReferenceError) { Reference.parse("0 R") }
|
132
|
-
assert_raises(InvalidReferenceError) { Reference.parse("") }
|
6
|
+
def setup
|
7
|
+
@files =
|
8
|
+
%w[
|
9
|
+
dataset/empty.pdf
|
10
|
+
dataset/calc.pdf
|
11
|
+
dataset/crypto.pdf
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_parse_pdf
|
16
|
+
@files.each do |file|
|
17
|
+
pdf = PDF.read(File.join(__dir__, file), ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
18
|
+
|
19
|
+
assert_instance_of PDF, pdf
|
20
|
+
|
21
|
+
pdf.each_object do |object|
|
22
|
+
assert_kind_of Origami::Object, object
|
23
|
+
end
|
133
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_parse_dictionary
|
28
|
+
dict = Dictionary.parse("<</Ref 2 0 R/N null/Pi 3.14 /D <<>>>>")
|
29
|
+
|
30
|
+
assert_instance_of Dictionary, dict
|
31
|
+
assert_instance_of Dictionary, dict[:D]
|
32
|
+
assert_instance_of Null, dict[:N]
|
33
|
+
assert_instance_of Reference, dict[:Ref]
|
34
|
+
assert_equal dict.size, 4
|
35
|
+
assert_raises(InvalidReferenceError) { dict[:Ref].solve }
|
36
|
+
assert dict[:Pi] == 3.14
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parse_array
|
40
|
+
array = Origami::Array.parse("[/Test (abc) .2 \n 799 [<<>>]]")
|
41
|
+
|
42
|
+
assert array.all? { |e| e.is_a?(Origami::Object) }
|
43
|
+
assert_equal array.length, 5
|
44
|
+
assert_raises(InvalidArrayObjectError) { Origami::Array.parse("[1 ") }
|
45
|
+
assert_raises(InvalidArrayObjectError) { Origami::Array.parse("") }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_parse_string
|
49
|
+
str = LiteralString.parse("(\\122\\125by\\n)")
|
50
|
+
assert_instance_of LiteralString, str
|
51
|
+
assert_equal str.value, "RUby\n"
|
52
|
+
|
53
|
+
assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("") }
|
54
|
+
assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("(test") }
|
55
|
+
assert_equal "((O))", LiteralString.parse("(((O)))").value
|
56
|
+
assert_equal LiteralString.parse("(ABC\\\nDEF\\\r\nGHI)").value, "ABCDEFGHI"
|
57
|
+
assert_equal LiteralString.parse('(\r\n\b\t\f\\(\\)\\x\\\\)').value, "\r\n\b\t\f()x\\"
|
58
|
+
assert_equal LiteralString.parse('(\r\n\b\t\f\\\\\\(\\))').to_s, '(\r\n\b\t\f\\\\\\(\\))'
|
59
|
+
|
60
|
+
str = HexaString.parse("<52 55 62 79 0A>")
|
61
|
+
assert_instance_of HexaString, str
|
62
|
+
assert_equal str.value, "RUby\n"
|
63
|
+
|
64
|
+
assert_equal HexaString.parse("<4>").value, 0x40.chr
|
65
|
+
|
66
|
+
assert_raises(InvalidHexaStringObjectError) { HexaString.parse("") }
|
67
|
+
assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12") }
|
68
|
+
assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12X>") }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_parse_bool
|
72
|
+
b_true = Boolean.parse("true")
|
73
|
+
b_false = Boolean.parse("false")
|
74
|
+
|
75
|
+
assert_instance_of Boolean, b_true
|
76
|
+
assert_instance_of Boolean, b_false
|
77
|
+
|
78
|
+
assert b_false.false?
|
79
|
+
refute b_true.false?
|
80
|
+
|
81
|
+
assert_raises(InvalidBooleanObjectError) { Boolean.parse("") }
|
82
|
+
assert_raises(InvalidBooleanObjectError) { Boolean.parse("tru") }
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_parse_real
|
86
|
+
real = Real.parse("-3.141592653")
|
87
|
+
assert_instance_of Real, real
|
88
|
+
assert_equal real, -3.141592653
|
89
|
+
|
90
|
+
real = Real.parse("+.00200")
|
91
|
+
assert_instance_of Real, real
|
92
|
+
assert_equal real, 0.002
|
93
|
+
|
94
|
+
assert_raises(InvalidRealObjectError) { Real.parse("") }
|
95
|
+
assert_raises(InvalidRealObjectError) { Real.parse(".") }
|
96
|
+
assert_raises(InvalidRealObjectError) { Real.parse("+0x1") }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_parse_int
|
100
|
+
int = Origami::Integer.parse("02000000000000")
|
101
|
+
assert_instance_of Origami::Integer, int
|
102
|
+
assert_equal int, 2000000000000
|
103
|
+
|
104
|
+
int = Origami::Integer.parse("-98")
|
105
|
+
assert_instance_of Origami::Integer, int
|
106
|
+
assert_equal int, -98
|
107
|
+
|
108
|
+
assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("") }
|
109
|
+
assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("+-1") }
|
110
|
+
assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("ABC") }
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_parse_name
|
114
|
+
name = Name.parse("/#52#55#62#79#0A")
|
115
|
+
assert_instance_of Name, name
|
116
|
+
assert_equal name.value, :"RUby\n"
|
117
|
+
|
118
|
+
name = Name.parse("/")
|
119
|
+
assert_instance_of Name, name
|
120
|
+
assert_equal :"", name.value
|
121
|
+
|
122
|
+
assert_raises(Origami::InvalidNameObjectError) { Name.parse("") }
|
123
|
+
assert_raises(Origami::InvalidNameObjectError) { Name.parse("test") }
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_parse_reference
|
127
|
+
ref = Reference.parse("199 1 R")
|
128
|
+
assert_instance_of Reference, ref
|
129
|
+
|
130
|
+
assert_equal [199, 1], ref.to_a
|
131
|
+
assert_raises(InvalidReferenceError) { ref.solve }
|
132
|
+
assert_raises(InvalidReferenceError) { Reference.parse("-2 0 R") }
|
133
|
+
assert_raises(InvalidReferenceError) { Reference.parse("0 R") }
|
134
|
+
assert_raises(InvalidReferenceError) { Reference.parse("") }
|
135
|
+
end
|
134
136
|
end
|
data/test/test_pdf_parse_lazy.rb
CHANGED
@@ -1,69 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestPDFLazyParser < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
def setup
|
8
|
+
@files =
|
9
|
+
%w[
|
10
|
+
dataset/empty.pdf
|
11
|
+
dataset/calc.pdf
|
12
|
+
dataset/crypto.pdf
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_parse_pdf_lazy
|
17
|
+
@files.each do |file|
|
18
|
+
pdf = PDF.read(File.join(__dir__, file),
|
19
|
+
ignore_errors: false,
|
20
|
+
lazy: true,
|
21
|
+
verbosity: Parser::VERBOSE_QUIET)
|
22
|
+
|
23
|
+
assert_instance_of PDF, pdf
|
24
|
+
|
25
|
+
pdf.each_object do |object|
|
26
|
+
assert_kind_of Origami::Object, object
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_instance_of Catalog, pdf.Catalog
|
30
|
+
|
31
|
+
pdf.each_page do |page|
|
32
|
+
assert_kind_of Page, page
|
33
|
+
end
|
14
34
|
end
|
35
|
+
end
|
15
36
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_instance_of PDF, pdf
|
24
|
-
|
25
|
-
pdf.each_object do |object|
|
26
|
-
assert_kind_of Origami::Object, object
|
27
|
-
end
|
37
|
+
def test_save_pdf_lazy
|
38
|
+
@files.each do |file|
|
39
|
+
pdf = PDF.read(File.join(__dir__, file),
|
40
|
+
ignore_errors: false,
|
41
|
+
lazy: true,
|
42
|
+
verbosity: Parser::VERBOSE_QUIET)
|
28
43
|
|
29
|
-
|
30
|
-
|
31
|
-
pdf.each_page do |page|
|
32
|
-
assert_kind_of Page, page
|
33
|
-
end
|
34
|
-
end
|
44
|
+
pdf.save(StringIO.new)
|
35
45
|
end
|
46
|
+
end
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
ignore_errors: false,
|
41
|
-
lazy: true,
|
42
|
-
verbosity: Parser::VERBOSE_QUIET)
|
48
|
+
def test_random_access
|
49
|
+
io = StringIO.new
|
50
|
+
stream = Stream.new("abc")
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
PDF.create(io) do |pdf|
|
53
|
+
pdf.insert(stream)
|
46
54
|
end
|
47
55
|
|
48
|
-
|
49
|
-
io = StringIO.new
|
50
|
-
stream = Stream.new("abc")
|
51
|
-
|
52
|
-
PDF.create(io) do |pdf|
|
53
|
-
pdf.insert(stream)
|
54
|
-
end
|
56
|
+
io = io.reopen(io.string, 'r')
|
55
57
|
|
56
|
-
|
58
|
+
pdf = PDF.read(io, ignore_errors: false,
|
59
|
+
lazy: true,
|
60
|
+
verbosity: Parser::VERBOSE_QUIET)
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
verbosity: Parser::VERBOSE_QUIET)
|
62
|
+
non_existent = pdf[42]
|
63
|
+
existent = pdf[stream.reference]
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
assert_instance_of Stream, existent
|
67
|
-
assert_equal stream.data, existent.data
|
68
|
-
end
|
65
|
+
assert_nil non_existent
|
66
|
+
assert_instance_of Stream, existent
|
67
|
+
assert_equal stream.data, existent.data
|
68
|
+
end
|
69
69
|
end
|