aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/serde.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/serde.rs b/tests/serde.rs
index 295b8d0..3701707 100644
--- a/tests/serde.rs
+++ b/tests/serde.rs
@@ -11,13 +11,14 @@ fn size_of_image_info_header() {
11 11
12#[test] 12#[test]
13fn compression() { 13fn compression() {
14 let img = Image::new(50, 5); 14 let mut img = Image::new(50, 5);
15 img.use_compression(CompressionType::RLE);
15 let encoded = img.encode().unwrap(); 16 let encoded = img.encode().unwrap();
16 let mut cursor = Cursor::new(encoded); 17 let mut cursor = Cursor::new(encoded);
17 let decoded = Image::decode(&mut cursor).unwrap(); 18 let decoded = Image::decode(&mut cursor).unwrap();
18 assert_eq!( 19 assert_eq!(
19 CompressionType::from_u32(decoded.image_info_header.compression_type), 20 CompressionType::from_u32(decoded.image_info_header.compression_type),
20 CompressionType::None 21 CompressionType::RLE
21 ); 22 );
22} 23}
23 24
@@ -42,3 +43,20 @@ fn size_round_nearest() {
42 assert_eq!(decoded.image_info_header.width, 50); 43 assert_eq!(decoded.image_info_header.width, 50);
43 assert_eq!(decoded.image_info_header.height, 5); 44 assert_eq!(decoded.image_info_header.height, 5);
44} 45}
46
47#[test]
48fn size_compressed() {
49 let mut img = Image::new(100, 80);
50 img.use_compression(CompressionType::RLE);
51 let encoded = img.encode().unwrap();
52 // 26 - headers
53 // 4 - first and only length
54 // 4 - separator zero
55 // 1 - first and only data point
56 assert_eq!(encoded.len(), 26 + 4 + 4 + 1);
57 let mut cursor = Cursor::new(encoded);
58 let decoded = Image::decode(&mut cursor).unwrap();
59 assert_eq!(decoded.image_info_header.width, 100);
60 assert_eq!(decoded.image_info_header.height, 80);
61 assert!(decoded.data.iter().all(|x| !*x));
62}