1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
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::<ImageInfoHeader>();
assert_eq!(16, file_header_size);
}
#[test]
fn compression() {
let mut img = Image::new(50, 5);
img.use_compression(CompressionType::RLE);
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::RLE
);
}
#[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);
}
#[test]
fn size_compressed() {
let mut img = Image::new(100, 80);
img.use_compression(CompressionType::RLE);
let encoded = img.encode().unwrap();
// 26 - headers
// 4 - first and only length
// 4 - separator zero
// 1 - first and only data point
assert_eq!(encoded.len(), 26 + 4 + 4 + 1);
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);
assert!(decoded.data.iter().all(|x| !*x));
}
|