From 3d25a69b686c68f463ba313b2da112df135f1f0c Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 7 Mar 2021 10:27:45 +0530 Subject: add integration tests --- tests/integration.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/integration.rs (limited to 'tests') diff --git a/tests/integration.rs b/tests/integration.rs new file mode 100644 index 0000000..d355a47 --- /dev/null +++ b/tests/integration.rs @@ -0,0 +1,38 @@ +use std::io::Cursor; + +use obi::{error::OBIResult, Image}; + +#[test] +fn encode_modify_decode() { + let mut img = Image::new(50, 5); + img.set(2, 3, true).expect("Indexing error"); + let encoded = img.encode().unwrap(); + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor).unwrap(); + assert!(decoded.get(2, 3).unwrap()); +} + +#[test] +fn encode_modify_decode_padded_byte_edge_case() -> OBIResult<()> { + let mut img = Image::new(1, 4); + img.set(0, 2, true)?; + let encoded = img.encode()?; + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor)?; + assert!(!decoded.get(0, 0)?); + assert!(!decoded.get(0, 1)?); + assert!(decoded.get(0, 2)?); + assert!(!decoded.get(0, 3)?); + Ok(()) +} + +#[test] +fn encode_modify_decode_padded_byte_edge_case_big_image() -> OBIResult<()> { + let mut img = Image::new(25, 10); + img.set(24, 9, true)?; + let encoded = img.encode()?; + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor)?; + assert!(decoded.get(24, 9)?); + Ok(()) +} -- cgit v1.2.3