diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ecf466b..028f0f5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,13 +15,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install libpoppler-glib-dev - run: sudo apt-get update && sudo apt-get install libpoppler-glib-dev + - uses: actions/checkout@v4 + - name: Install libpoppler-glib-dev libcairo-dev + run: sudo apt-get update && sudo apt-get install libpoppler-glib-dev libcairo-dev - name: Build - run: cargo build --verbose + run: cargo build --verbose --all-features - name: Run tests - run: cargo test --verbose + run: cargo test --verbose --all-features - name: Publish to Cargo Registry if: github.ref == 'refs/heads/master' env: diff --git a/.gitignore b/.gitignore index 7a5a1ea..bd85949 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ .idea/ Cargo.lock output.pdf -out.png +out*.png *.swp diff --git a/Cargo.toml b/Cargo.toml index 55597b2..f691736 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,6 @@ edition = "2018" render = ["dep:cairo-rs"] [dependencies] -cairo-rs = { version = "0.18.5", features = ["png", "pdf"], optional = true } -glib = "0.18.5" -gobject-sys = "0.15" +cairo-rs = { version = "0.20.5", features = ["png", "pdf"], optional = true } +glib = "0.20.6" +gobject-sys = "0.20" diff --git a/src/lib.rs b/src/lib.rs index fda5319..175c6f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -341,37 +341,40 @@ mod tests { for (index, p) in doc.pages().enumerate() { let (w, h) = p.get_size(); - assert!(w == src_w); - assert!(h == src_h); + assert_eq!(w, src_w); + assert_eq!(h, src_h); println!("page {}/{} -- {}x{}", index + 1, total, w, h); count += 1; } - assert!(count == 1); + assert_eq!(count, 1); #[cfg(feature = "render")] - let count = 0; + let mut count = 0; #[cfg(feature = "render")] for (index, p) in doc.pages().enumerate() { let (w, h) = p.get_size(); - assert!(w == src_w); - assert!(h == src_h); + assert_eq!(w, src_w); + assert_eq!(h, src_h); - let surface = ImageSurface::create(Format::ARgb32, w as i32, h as i32).unwrap(); + let surface = ImageSurface::create(Format::ARgb32, w as i32, h as i32).expect("failed to create image surface"); + let context = Context::new(&surface).expect("failed to create cairo context"); (|page: &PopplerPage, ctx: &Context| { ctx.save().unwrap(); page.render(ctx); ctx.restore().unwrap(); ctx.show_page().unwrap(); - })(&page, &ctx); + })(&p, &context); let mut f: File = File::create(format!("out{}.png", index)).unwrap(); surface.write_to_png(&mut f).expect("Unable to write PNG"); + + count += 1; } #[cfg(feature = "render")] - assert!(count == 1) + assert_eq!(count, 1) } }