//! Smoke test of the vendored library through the crate's own helpers: the
//! bundled OpenZL is the version the crate claims, and a frame round-trips at
//! both the newest format and the older format 25 that 0.3.x readers decode.
use openzl_sys_rs::*;
fn sample() -> Vec<u8> {
(0..100_000u32).map(|x| ((x * 31 + x / 7) % 253) as u8).collect()
}
fn round_trip(format: i32) {
let src = sample();
let mut c = ZlCCtx::new().expect("ZL_CCtx_create");
c.set_parameter(ZL_CParam_ZL_CParam_formatVersion, format).unwrap();
c.set_parameter(ZL_CParam_ZL_CParam_compressionLevel, 3).unwrap();
let mut frame = vec![0u8; zl_compress_bound(src.len())];
let n = c.compress(&mut frame, &src).unwrap();
frame.truncate(n);
let r = unsafe { ZL_getFormatVersionFromFrame(frame.as_ptr() as *const _, frame.len()) };
assert!(!zl_is_error(r));
assert_eq!(zl_report_value(r), format as usize);
assert_eq!(zl_get_decompressed_size(&frame).unwrap(), src.len());
let mut out = vec![0u8; src.len()];
assert_eq!(zl_decompress(&mut out, &frame).unwrap(), src.len());
assert_eq!(out, src);
let mut d = ZlDCtx::new().expect("ZL_DCtx_create");
let mut out2 = vec![0u8; src.len()];
assert_eq!(d.decompress(&mut out2, &frame).unwrap(), src.len());
assert_eq!(out2, src);
}
#[test]
fn bundled_openzl_is_0_3_0() {
assert_eq!(
(ZL_LIBRARY_VERSION_MAJOR, ZL_LIBRARY_VERSION_MINOR, ZL_LIBRARY_VERSION_PATCH),
(0, 3, 0)
);
assert_eq!(ZL_MAX_FORMAT_VERSION, 27);
assert_eq!(unsafe { ZL_getDefaultEncodingVersion() }, 27);
}
#[test]
fn round_trips_at_the_default_format() {
round_trip(unsafe { ZL_getDefaultEncodingVersion() } as i32);
}
#[test]
fn round_trips_at_format_25() {
round_trip(25);
}