chore: refactor ahead of supporting more conversion types
All checks were successful
Checking Renovate configuration / validate (pull_request) Successful in 1m5s
Build and test / Clippy (pull_request) Successful in 3m25s
Checking yaml / Run yamllint (pull_request) Successful in 11s
Build and test / Tests (pull_request) Successful in 4m12s
Build and test / Build AMD64 (pull_request) Successful in 4m12s
Build and test / Generate Documentation (pull_request) Successful in 3m52s

This commit is contained in:
Marc Plano-Lesay 2025-10-10 16:34:52 +11:00
parent 48b560d85e
commit 034f0b142c
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
12 changed files with 468 additions and 150 deletions

38
tests/pdf_writer_smoke.rs Normal file
View file

@ -0,0 +1,38 @@
use std::fs;
use std::io::Read;
use cbz2pdf::formats::pdf::PdfWriter;
use cbz2pdf::formats::FormatWriter;
use cbz2pdf::model::{Document, ImagePage};
#[test]
fn pdf_writer_writes_valid_pdf_header() {
// Build a simple 2x2 red image page
let mut img = image::DynamicImage::new_rgb8(2, 2).to_rgb8();
for p in img.pixels_mut() {
*p = image::Rgb([255, 0, 0]);
}
let page = ImagePage {
name: "page1.jpg".to_string(),
image: image::DynamicImage::ImageRgb8(img),
jpeg_dct: None,
};
let doc = Document::new(vec![page]);
let temp_dir = tempfile::tempdir().expect("create temp dir");
let output = temp_dir.path().join("out.pdf");
let writer = PdfWriter;
writer.write(&doc, &output).expect("failed to write PDF");
// Assert file exists and has PDF header
let mut f = fs::File::open(&output).expect("pdf not created");
let mut header = [0u8; 5];
f.read_exact(&mut header).expect("cannot read header");
assert_eq!(&header, b"%PDF-", "missing PDF header");
let meta = fs::metadata(&output).unwrap();
assert!(meta.len() > 0, "empty pdf");
// temp_dir cleans up automatically on drop
}