From 7c0b4374c1c6f049a6fe68d07bed87e7c22431d4 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 3 Mar 2021 19:11:26 +0530 Subject: add basic tests --- tests/serde.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/serde.rs diff --git a/tests/serde.rs b/tests/serde.rs new file mode 100644 index 0000000..295b8d0 --- /dev/null +++ b/tests/serde.rs @@ -0,0 +1,44 @@ +use std::io::Cursor; +use std::mem::size_of; + +use obi::{CompressionType, Image, ImageInfoHeader}; + +#[test] +fn size_of_image_info_header() { + let file_header_size = size_of::(); + assert_eq!(16, file_header_size); +} + +#[test] +fn compression() { + let img = Image::new(50, 5); + let encoded = img.encode().unwrap(); + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor).unwrap(); + assert_eq!( + CompressionType::from_u32(decoded.image_info_header.compression_type), + CompressionType::None + ); +} + +#[test] +fn size_no_rounding() { + let img = Image::new(100, 80); + let encoded = img.encode().unwrap(); + assert_eq!(encoded.len(), 26 + 100 * 80 / 8); + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor).unwrap(); + assert_eq!(decoded.image_info_header.width, 100); + assert_eq!(decoded.image_info_header.height, 80); +} + +#[test] +fn size_round_nearest() { + let img = Image::new(50, 5); + let encoded = img.encode().unwrap(); + assert_eq!(encoded.len(), 26 + 256 / 8); + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor).unwrap(); + assert_eq!(decoded.image_info_header.width, 50); + assert_eq!(decoded.image_info_header.height, 5); +} -- cgit v1.2.3