diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/serde.rs | 44 |
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 @@ | |||
1 | use std::io::Cursor; | ||
2 | use std::mem::size_of; | ||
3 | |||
4 | use obi::{CompressionType, Image, ImageInfoHeader}; | ||
5 | |||
6 | #[test] | ||
7 | fn size_of_image_info_header() { | ||
8 | let file_header_size = size_of::<ImageInfoHeader>(); | ||
9 | assert_eq!(16, file_header_size); | ||
10 | } | ||
11 | |||
12 | #[test] | ||
13 | fn 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] | ||
25 | fn 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] | ||
36 | fn 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 | } | ||