aboutsummaryrefslogtreecommitdiff
path: root/tests/serde.rs
blob: 295b8d06defdf9dd86ca636c92cb9bf428fce33e (plain)
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
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 img = Image::new(50, 5);
    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::None
    );
}

#[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);
}