diff options
author | Akshay <[email protected]> | 2021-04-18 10:50:13 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-18 10:50:13 +0100 |
commit | 869fe69fdf947230ca4129d3d1f9749360035e64 (patch) | |
tree | d6bdbd525fa16b1b5260ab1d47aef4eda85a6931 /tests | |
parent | 7d2924015e691fa229c6b6fd96240ef47b3a9e5f (diff) |
add RLE compression functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/serde.rs | 22 |
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] |
13 | fn compression() { | 13 | fn 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] | ||
48 | fn 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 | } | ||