Skip to content

Commit 23b3ed7

Browse files
committed
Add test cases
1 parent 8bd2212 commit 23b3ed7

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

src/lib.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl Pdf {
342342
}
343343
XRefFilter::Multiple(filters) => {
344344
let mut arr = stream.insert(Name(b"Filter")).array();
345-
345+
346346
for filter in filters {
347347
arr.item(filter.to_name());
348348
}
@@ -495,15 +495,13 @@ impl XRefStreamWriter {
495495
fn write(&mut self, entry_type: u8, offset: usize, gen_number: u16) {
496496
let offset_bytes = (offset as u64).to_be_bytes();
497497

498-
let start = self.buf.len();
499498
self.buf.push(entry_type);
500499
self.buf.extend(
501500
offset_bytes
502501
.iter()
503502
.skip(offset_bytes.len() - self.field_width as usize),
504503
);
505504
self.buf.extend_from_slice(&gen_number.to_be_bytes());
506-
eprintln!("{:?}", &self.buf[start..]);
507505
}
508506
}
509507

@@ -701,4 +699,36 @@ mod tests {
701699
b"startxref\n70\n%%EOF",
702700
)
703701
}
702+
703+
#[test]
704+
fn test_xref_stream_single_filter() {
705+
let mut w = Pdf::new();
706+
w.indirect(Ref::new(1)).primitive(1);
707+
test!(
708+
w.finish_with_xref_stream(Ref::new(2), Some(Box::new(|_| (b"ABCDEFGH".to_vec(), XRefFilter::Single(Filter::FlateDecode))))),
709+
b"%PDF-1.7\n%\x80\x80\x80\x80\n",
710+
b"1 0 obj\n1\nendobj\n",
711+
b"2 0 obj\n<<\n /Length 8\n /Type /XRef\n /Filter /FlateDecode\n /Size 3\n /W [1 1 2]\n>>\nstream",
712+
// [0, 0, 255, 255], [1, 16, 0, 0], [1, 34, 0, 0]
713+
b"ABCDEFGH",
714+
b"endstream\nendobj\n",
715+
b"startxref\n34\n%%EOF",
716+
)
717+
}
718+
719+
#[test]
720+
fn test_xref_stream_multiple_filters() {
721+
let mut w = Pdf::new();
722+
w.indirect(Ref::new(1)).primitive(1);
723+
test!(
724+
w.finish_with_xref_stream(Ref::new(2), Some(Box::new(|_| (b"ABCDEFGH".to_vec(), XRefFilter::Multiple(vec![Filter::AsciiHexDecode, Filter::FlateDecode]))))),
725+
b"%PDF-1.7\n%\x80\x80\x80\x80\n",
726+
b"1 0 obj\n1\nendobj\n",
727+
b"2 0 obj\n<<\n /Length 8\n /Type /XRef\n /Filter [/ASCIIHexDecode /FlateDecode]\n /Size 3\n /W [1 1 2]\n>>\nstream",
728+
// [0, 0, 255, 255], [1, 16, 0, 0], [1, 34, 0, 0]
729+
b"ABCDEFGH",
730+
b"endstream\nendobj\n",
731+
b"startxref\n34\n%%EOF",
732+
)
733+
}
704734
}

0 commit comments

Comments
 (0)