test/hexapdf/test_writer.rb in hexapdf-0.22.0 vs test/hexapdf/test_writer.rb in hexapdf-0.23.0
- old
+ new
@@ -38,17 +38,17 @@
<</Size 3/Prev 54>>
startxref
219
%%EOF
3 0 obj
- <</Producer(HexaPDF version 0.22.0)>>
+ <</Producer(HexaPDF version 0.23.0)>>
endobj
xref
3 1
0000000296 00000 n
trailer
- <</Prev 219/Size 4/Root<</Type/Catalog>>/Info 3 0 R>>
+ <</Size 4/Root<</Type/Catalog>>/Info 3 0 R/Prev 219>>
startxref
349
%%EOF
EOF
@@ -62,27 +62,27 @@
endobj
2 0 obj
20
endobj
3 0 obj
- <</Size 6/Type/XRef/W[1 1 2]/Index[0 4 5 1]/Filter/FlateDecode/DecodeParms<</Columns 4/Predictor 12>>/Length 31>>stream
+ <</Type/XRef/Size 6/W[1 1 2]/Index[0 4 5 1]/Filter/FlateDecode/DecodeParms<</Columns 4/Predictor 12>>/Length 31>>stream
x\xDAcb`\xF8\xFF\x9F\x89\x89\x95\x91\x91\xE9\x7F\x19\x03\x03\x13\x83\x10\x88he`\x00\x00B4\x04\x1E
endstream
endobj
startxref
141
%%EOF
6 0 obj
- <</Producer(HexaPDF version 0.22.0)>>
+ <</Producer(HexaPDF version 0.23.0)>>
endobj
2 0 obj
<</Length 10>>stream
Some data!
endstream
endobj
4 0 obj
- <</Size 7/Prev 141/Root<</Type/Catalog>>/Info 6 0 R/Type/XRef/W[1 2 2]/Index[2 1 4 1 6 1]/Filter/FlateDecode/DecodeParms<</Columns 5/Predictor 12>>/Length 22>>stream
+ <</Type/XRef/Size 7/Root<</Type/Catalog>>/Info 6 0 R/Prev 141/W[1 2 2]/Index[2 1 4 1 6 1]/Filter/FlateDecode/DecodeParms<</Columns 5/Predictor 12>>/Length 22>>stream
x\xDAcbdlg``b`\xB0\x04\x93\x93\x18\x18\x00\f\e\x01[
endstream
endobj
startxref
448
@@ -110,11 +110,11 @@
doc.pages.add
output_io = StringIO.new
HexaPDF::Writer.write(doc, output_io, incremental: true)
assert_equal(output_io.string[0, @std_input_io.string.length], @std_input_io.string)
doc = HexaPDF::Document.new(io: output_io)
- assert_equal(4, doc.revisions.size)
+ assert_equal(4, doc.revisions.count)
assert_equal(2, doc.revisions.current.each.to_a.size)
end
it "uses an xref stream if the document already contains at least one" do
doc = HexaPDF::Document.new(io: @compressed_input_io)
@@ -134,32 +134,61 @@
doc.encrypt(owner_password: 'test')
assert_raises(HexaPDF::Error) { doc.write('notused', incremental: true) }
end
end
+ it "moves modified objects into the last revision" do
+ io = StringIO.new
+ io2 = StringIO.new
+
+ document = HexaPDF::Document.new
+ document.pages.add
+ HexaPDF::Writer.new(document, io).write
+
+ document = HexaPDF::Document.new(io: io)
+ document.pages.add
+ HexaPDF::Writer.new(document, io2).write_incremental
+
+ document = HexaPDF::Document.new(io: io2)
+ document.revisions.add
+ document.pages.add
+ HexaPDF::Writer.new(document, io).write
+
+ document = HexaPDF::Document.new(io: io)
+ assert_equal(3, document.revisions.count)
+ assert_equal(1, document.revisions.all[0].object(2)[:Kids].length)
+ assert_equal(2, document.revisions.all[1].object(2)[:Kids].length)
+ assert_equal(3, document.revisions.all[2].object(2)[:Kids].length)
+ end
+
it "creates an xref stream if no xref stream is in a revision but object streams are" do
document = HexaPDF::Document.new
document.add({Type: :ObjStm})
HexaPDF::Writer.new(document, StringIO.new).write
- assert(:XRef, document.object(2).type)
+ assert_equal(:XRef, document.object(4).type)
end
it "creates an xref stream if a previous revision had one" do
document = HexaPDF::Document.new
document.pages.add
- document.revisions.add
+ io = StringIO.new
+ HexaPDF::Writer.new(document, io).write
+
+ document = HexaPDF::Document.new(io: io)
document.pages.add
document.add({Type: :ObjStm})
- document.revisions.add
+ io2 = StringIO.new
+ HexaPDF::Writer.new(document, io2).write_incremental
+
+ document = HexaPDF::Document.new(io: io2)
document.pages.add
- io = StringIO.new
- HexaPDF::Writer.new(document, io).write
+ HexaPDF::Writer.new(document, io).write_incremental
document = HexaPDF::Document.new(io: io)
assert_equal(3, document.revisions.count)
- assert(document.revisions[0].none? {|obj| obj.type == :XRef })
- assert(document.revisions[1].one? {|obj| obj.type == :XRef })
- assert(document.revisions[2].one? {|obj| obj.type == :XRef })
+ assert(document.revisions.all[0].none? {|obj| obj.type == :XRef })
+ assert(document.revisions.all[1].one? {|obj| obj.type == :XRef })
+ assert(document.revisions.all[2].one? {|obj| obj.type == :XRef })
end
it "raises an error if the class is misused and an xref section contains invalid entries" do
document = HexaPDF::Document.new
io = StringIO.new