Added round-trip testing

This commit is contained in:
G2-Games 2024-09-10 11:41:07 -05:00
parent e9963afa4d
commit d972dc0161
5 changed files with 268 additions and 0 deletions

51
cz/tests/round_trip.rs Normal file
View file

@ -0,0 +1,51 @@
use std::io::Cursor;
use cz::{common::CzVersion, DynamicCz};
const KODIM03: (u16, u16, &[u8]) = (128, 128, include_bytes!("test_images/kodim03.rgba"));
const KODIM23: (u16, u16, &[u8]) = (225, 225, include_bytes!("test_images/kodim23.rgba"));
const SQPTEXT: (u16, u16, &[u8]) = (2048, 810, include_bytes!("test_images/sqp_text.rgba"));
const DPFLOGO: (u16, u16, &[u8]) = (1123, 639, include_bytes!("test_images/dpf_logo.rgba"));
type TestImage = (u16, u16, &'static [u8]);
const TEST_IMAGES: &[TestImage] = &[KODIM03, KODIM23, SQPTEXT, DPFLOGO];
#[test]
fn cz0_round_trip() {
for image in TEST_IMAGES {
let original_cz = DynamicCz::from_raw(
CzVersion::CZ0,
image.0,
image.1,
image.2.to_vec()
);
let mut cz_bytes = Vec::new();
original_cz.encode(&mut cz_bytes).unwrap();
let mut cz_bytes = Cursor::new(cz_bytes);
let decoded_cz = DynamicCz::decode(&mut cz_bytes).unwrap();
assert_eq!(original_cz.as_raw(), decoded_cz.as_raw());
}
}
#[test]
fn cz1_round_trip() {
for image in TEST_IMAGES {
let original_cz = DynamicCz::from_raw(
CzVersion::CZ1,
image.0,
image.1,
image.2.to_vec()
);
let mut cz_bytes = Vec::new();
original_cz.encode(&mut cz_bytes).unwrap();
let mut cz_bytes = Cursor::new(cz_bytes);
let decoded_cz = DynamicCz::decode(&mut cz_bytes).unwrap();
assert_eq!(original_cz.as_raw(), decoded_cz.as_raw());
}
}

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.