aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-03-03 13:41:26 +0000
committerAkshay <[email protected]>2021-03-03 13:41:26 +0000
commit7c0b4374c1c6f049a6fe68d07bed87e7c22431d4 (patch)
tree08b7297c09bb7aa1433e9692e7348ec4fdd75997
parent654be91de3768f7c01acb36ab82460765927493a (diff)
add basic tests
-rw-r--r--tests/serde.rs44
1 files changed, 44 insertions, 0 deletions
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 @@
1use std::io::Cursor;
2use std::mem::size_of;
3
4use obi::{CompressionType, Image, ImageInfoHeader};
5
6#[test]
7fn size_of_image_info_header() {
8 let file_header_size = size_of::<ImageInfoHeader>();
9 assert_eq!(16, file_header_size);
10}
11
12#[test]
13fn compression() {
14 let img = Image::new(50, 5);
15 let encoded = img.encode().unwrap();
16 let mut cursor = Cursor::new(encoded);
17 let decoded = Image::decode(&mut cursor).unwrap();
18 assert_eq!(
19 CompressionType::from_u32(decoded.image_info_header.compression_type),
20 CompressionType::None
21 );
22}
23
24#[test]
25fn size_no_rounding() {
26 let img = Image::new(100, 80);
27 let encoded = img.encode().unwrap();
28 assert_eq!(encoded.len(), 26 + 100 * 80 / 8);
29 let mut cursor = Cursor::new(encoded);
30 let decoded = Image::decode(&mut cursor).unwrap();
31 assert_eq!(decoded.image_info_header.width, 100);
32 assert_eq!(decoded.image_info_header.height, 80);
33}
34
35#[test]
36fn size_round_nearest() {
37 let img = Image::new(50, 5);
38 let encoded = img.encode().unwrap();
39 assert_eq!(encoded.len(), 26 + 256 / 8);
40 let mut cursor = Cursor::new(encoded);
41 let decoded = Image::decode(&mut cursor).unwrap();
42 assert_eq!(decoded.image_info_header.width, 50);
43 assert_eq!(decoded.image_info_header.height, 5);
44}