69 lines
1.9 KiB
Rust
69 lines
1.9 KiB
Rust
use maraiah::marathon::defl;
|
|
|
|
include!("data/rand.rs");
|
|
|
|
#[test]
|
|
fn defl_alice()
|
|
{
|
|
const IN_1: &[u8] = include_bytes!("data/alice1.in");
|
|
const IN_2: &[u8] = include_bytes!("data/alice2.in");
|
|
const OUT: &[u8] = include_bytes!("data/alice.out");
|
|
|
|
let p = defl::load_gzip_header(IN_1).unwrap();
|
|
assert_eq!(p, 0x14);
|
|
|
|
let b = &IN_1[p..];
|
|
assert_eq!(defl::load_deflate(b).unwrap().1, OUT.to_vec());
|
|
|
|
let p = defl::load_gzip_header(IN_2).unwrap();
|
|
assert_eq!(p, 0x14);
|
|
|
|
let b = &IN_2[p..];
|
|
assert_eq!(defl::load_deflate(b).unwrap().1, OUT.to_vec());
|
|
}
|
|
|
|
#[test]
|
|
fn defl_shapes()
|
|
{
|
|
const INPUT: &[u8] = include_bytes!("data/Shapes.in");
|
|
const OUTPUT: &[u8] = include_bytes!("data/Shapes.out");
|
|
|
|
let b = &INPUT[defl::load_gzip_header(INPUT).unwrap()..];
|
|
assert_eq!(defl::load_deflate(b).unwrap().1, OUTPUT.to_vec());
|
|
}
|
|
|
|
#[test]
|
|
fn defl_must_succeed()
|
|
{
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzipok1.bin")).is_ok());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzipok2.bin")).is_ok());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzipok3.bin")).is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn defl_must_not_succeed()
|
|
{
|
|
for inp in &RANDOM {
|
|
assert!(defl::load_gzip_header(inp).is_err());
|
|
}
|
|
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad1.bin")).is_err());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad2.bin")).is_err());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad3.bin")).is_err());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad4.bin")).is_err());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad5.bin")).is_err());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad6.bin")).is_err());
|
|
assert!(defl::load_gzip_header(include_bytes!("data/gzbad7.bin")).is_err());
|
|
}
|
|
|
|
#[test]
|
|
#[allow(unused_must_use)]
|
|
fn defl_must_not_panic()
|
|
{
|
|
for inp in &RANDOM {
|
|
defl::load_deflate(inp);
|
|
}
|
|
}
|
|
|
|
// EOF
|