Skip to content

Commit

Permalink
Start addressing the leptonica 1.83.0 private fields change
Browse files Browse the repository at this point in the history
#5

```bash
LD_LIBRARY_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib" PKG_CONFIG_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib/pkgconfig" cargo test
```
  • Loading branch information
ccouzens committed Jan 15, 2023
1 parent 4bb9d74 commit 2194748
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 32 deletions.
19 changes: 19 additions & 0 deletions src/borrowed_pix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
extern crate leptonica_sys;
use self::leptonica_sys::{l_int32, pixGetHeight, pixGetWidth};
use std::marker::PhantomData;

pub trait BorrowedPixMethods {
/// Wrapper for [`pixGetHeight`](https://tpgit.github.io/Leptonica/pix1_8c.html#ae40704b3acbd343639e9aed696da531f)
fn get_height(&self) -> l_int32;
/// Wrapper for [`pixGetWidth`](https://tpgit.github.io/Leptonica/leptprotos_8h.html#aa71e0b02548a56e723c76996ab145257)
fn get_width(&self) -> l_int32;
}

impl BorrowedPixMethods for leptonica_sys::Pix {
fn get_height(&self) -> l_int32 {
unsafe { pixGetHeight(self) }
}

fn get_width(&self) -> l_int32 {
unsafe { pixGetWidth(self) }
}
}

/// Borrowed wrapper around Leptonica's [`Pix`](https://tpgit.github.io/Leptonica/struct_pix.html) structure
#[derive(Debug, PartialEq)]
pub struct BorrowedPix<'a> {
Expand Down
49 changes: 27 additions & 22 deletions src/pix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,34 @@ impl Pix {
}
}

#[test]
fn read_error_test() {
let path = std::ffi::CString::new("fail").unwrap();
assert!(Pix::read(&path).is_err());
}
#[cfg(test)]
mod tests {
use super::*;
use crate::borrowed_pix::BorrowedPixMethods;

#[test]
fn read_mem_error_test() {
assert_eq!(Pix::read_mem(&[]).err(), Some(PixReadMemError::NullPtr));
}
#[test]
fn read_error_test() {
let path = std::ffi::CString::new("fail").unwrap();
assert!(Pix::read(&path).is_err());
}

#[test]
fn read_test() {
let path = std::ffi::CString::new("image.png").unwrap();
let pix = Pix::read(&path).unwrap();
let lpix: &leptonica_sys::Pix = pix.as_ref();
assert_eq!(lpix.w, 200);
}
#[test]
fn read_mem_error_test() {
assert_eq!(Pix::read_mem(&[]).err(), Some(PixReadMemError::NullPtr));
}

#[test]
fn read_test() {
let path = std::ffi::CString::new("image.png").unwrap();
let pix = Pix::read(&path).unwrap();
let lpix: &leptonica_sys::Pix = pix.as_ref();
assert_eq!(lpix.get_width(), 200);
}

#[test]
fn read_memory_test() -> Result<(), Box<dyn std::error::Error>> {
let pix = Pix::read_mem(include_bytes!("../image.png"))?;
let lpix: &leptonica_sys::Pix = pix.as_ref();
assert_eq!(lpix.h, 23);
Ok(())
#[test]
fn read_memory_test() {
let pix = Pix::read_mem(include_bytes!("../image.png")).unwrap();
let lpix: &leptonica_sys::Pix = pix.as_ref();
assert_eq!(lpix.get_height(), 23);
}
}
27 changes: 17 additions & 10 deletions src/pixa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ impl Pixa {
}
}

#[test]
fn read_multipage_tiff_test() {
let pixa =
Pixa::read_multipage_tiff(CStr::from_bytes_with_nul(b"multipage.tiff\0").unwrap()).unwrap();
assert_eq!(pixa.as_ref().n, 2);
assert_eq!(pixa.get_pix(0).unwrap().as_ref().w, 165);
assert_eq!(pixa.get_pix(0).unwrap().as_ref().h, 67);
assert_eq!(pixa.get_pix(1).unwrap().as_ref().w, 165);
assert_eq!(pixa.get_pix(1).unwrap().as_ref().h, 67);
assert_eq!(pixa.get_pix(2), None);
#[cfg(test)]
mod tests {
use super::*;
use crate::borrowed_pix::BorrowedPixMethods;

#[test]
fn read_multipage_tiff_test() {
let pixa =
Pixa::read_multipage_tiff(CStr::from_bytes_with_nul(b"multipage.tiff\0").unwrap())
.unwrap();
assert_eq!(pixa.as_ref().n, 2);
assert_eq!(pixa.get_pix(0).unwrap().as_ref().get_width(), 165);
assert_eq!(pixa.get_pix(0).unwrap().as_ref().get_height(), 67);
assert_eq!(pixa.get_pix(1).unwrap().as_ref().get_width(), 165);
assert_eq!(pixa.get_pix(1).unwrap().as_ref().get_height(), 67);
assert_eq!(pixa.get_pix(2), None);
}
}

0 comments on commit 2194748

Please sign in to comment.