add random data tests

png-branch
an 2019-03-04 21:55:49 -05:00
parent 1d6aa0c14e
commit 6e3fff0080
11 changed files with 87 additions and 7 deletions

View File

@ -16,7 +16,8 @@ pub fn read_group(b: &[u8], text: &[u8]) -> ResultS<Group>
lines = u16[10]; lines = u16[10];
} }
let text = mac_roman_cstr(&text[start..start + size])?; let text = ok!(text.get(start..start + size), "not enough data")?;
let text = mac_roman_cstr(text)?;
let flags = flag_ok!(GroupFlags, flags)?; let flags = flag_ok!(GroupFlags, flags)?;
let ttype = match ttype { let ttype = match ttype {
0 => GroupType::Logon(pdata), 0 => GroupType::Logon(pdata),
@ -78,7 +79,7 @@ pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
let mut p = 10; let mut p = 10;
let text_st = p + SIZE_GROUP * group_n + SIZE_FACE * face_n; let text_st = p + SIZE_GROUP * group_n + SIZE_FACE * face_n;
let text = &b[text_st..end]; let text = ok!(b.get(text_st..end), "bad offset")?;
let text = if encoded { let text = if encoded {
fuck_string(text) fuck_string(text)
} else { } else {
@ -86,12 +87,12 @@ pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
}; };
for _ in 0..group_n { for _ in 0..group_n {
groups.push(read_group(&b[p..], &text)?); groups.push(read_group(ok!(b.get(p..), "not enough data")?, &text)?);
p += SIZE_GROUP; p += SIZE_GROUP;
} }
for _ in 0..face_n { for _ in 0..face_n {
faces.push(read_face(&b[p..])?); faces.push(read_face(ok!(b.get(p..), "not enough data")?)?);
p += SIZE_FACE; p += SIZE_FACE;
} }

11
tests/data/rand.rs Normal file
View File

@ -0,0 +1,11 @@
const RANDOM: [&[u8]; 7] = [
include_bytes!("random1.bin"),
include_bytes!("random2.bin"),
include_bytes!("random3.bin"),
include_bytes!("random4.bin"),
include_bytes!("random5.bin"),
include_bytes!("random6.bin"),
include_bytes!("random7.bin")
];
// EOF

BIN
tests/data/random1.bin Normal file

Binary file not shown.

BIN
tests/data/random2.bin Normal file

Binary file not shown.

BIN
tests/data/random3.bin Normal file

Binary file not shown.

2
tests/data/random4.bin Normal file
View File

@ -0,0 +1,2 @@
7rÓE/¨j„Ìü…üP" ³þçñ…<C3B1>»sxtúþÍP4é=Ì>³z<05>ê‡
®¹tÏÒéHœȶšl°k<C2B0><6B>Ô4@À~ŠÙ±)<29>¿’/…ÜåáfYÌðiω3Zû Ò¥7õ

1
tests/data/random5.bin Normal file
View File

@ -0,0 +1 @@
浮齡

BIN
tests/data/random6.bin Normal file

Binary file not shown.

BIN
tests/data/random7.bin Normal file

Binary file not shown.

View File

@ -1,5 +1,7 @@
use maraiah::{durandal::{bin, fixed::*}, marathon::{map, trm}}; use maraiah::{durandal::{bin, fixed::*}, marathon::{map, trm}};
include!("data/rand.rs");
#[test] #[test]
fn read_term_must_process() fn read_term_must_process()
{ {
@ -24,6 +26,14 @@ fn read_term_must_process()
} }
} }
#[test]
fn trm_must_not_process()
{
for inp in &RANDOM {
assert!(bin::rd_array(inp, trm::read_term).is_err());
}
}
#[test] #[test]
fn read_minf_must_process() fn read_minf_must_process()
{ {
@ -49,4 +59,39 @@ fn read_epnt_must_process()
assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(), OUTPUT.to_vec()); assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(), OUTPUT.to_vec());
} }
#[test]
fn map_must_not_process()
{
// these functions must not succeed
for inp in &RANDOM {
assert!(map::read_minf(inp).is_err());
assert!(map::read_old_minf(inp).is_err());
assert!(bin::rd_array(inp, map::read_lins).is_err());
assert!(bin::rd_array(inp, map::read_lite).is_err());
assert!(bin::rd_array(inp, map::read_medi).is_err());
assert!(bin::rd_array(inp, map::read_note).is_err());
assert!(bin::rd_array(inp, map::read_objs).is_err());
assert!(bin::rd_array(inp, map::read_plat).is_err());
assert!(bin::rd_array(inp, map::read_poly).is_err());
assert!(bin::rd_array(inp, map::read_sids).is_err());
assert!(bin::rd_array(inp, map::read_old_lite).is_err());
assert!(bin::rd_array(inp, map::read_old_poly).is_err());
assert!(bin::rd_array(inp, map::read_old_sids).is_err());
}
}
#[test]
#[allow(unused_must_use)]
fn map_wont_panic()
{
// these functions can succeed but must never panic
for inp in &RANDOM {
bin::rd_array(inp, map::read_ambi);
bin::rd_array(inp, map::read_bonk);
bin::rd_array(inp, map::read_epnt);
bin::rd_array(inp, map::read_iidx);
bin::rd_array(inp, map::read_plac);
}
}
// EOF // EOF

View File

@ -1,7 +1,9 @@
use maraiah::{durandal::image::Color8, marathon::{machdr, pict}}; use maraiah::{durandal::image::Color8, marathon::{machdr, pict}};
include!("data/rand.rs");
#[test] #[test]
fn get_clut_must_process_this() fn get_clut_must_process()
{ {
const INPUT: &[u8] = include_bytes!("data/clut.in"); const INPUT: &[u8] = include_bytes!("data/clut.in");
const OUTPUT: [Color8; 256] = include!("data/clut.out"); const OUTPUT: [Color8; 256] = include!("data/clut.out");
@ -10,14 +12,32 @@ fn get_clut_must_process_this()
} }
#[test] #[test]
fn macbin_must_process_this() fn get_clut_must_not_process()
{
for inp in &RANDOM {
assert!(pict::get_clut(inp).is_err());
}
}
#[test]
fn machdr_must_process()
{ {
const INPUT: &[u8] = include_bytes!("data/macbin.in"); const INPUT: &[u8] = include_bytes!("data/macbin.in");
assert_eq!(machdr::check_macbin(INPUT), Some(128)); assert_eq!(machdr::check_macbin(INPUT), Some(128));
assert_eq!(machdr::try_mac_header(INPUT), 128); assert_eq!(machdr::try_mac_header(INPUT), 128);
// TODO: missing test data for applesingle
} }
// TODO: missing test data for applesingle #[test]
fn machdr_must_not_process()
{
for inp in &RANDOM {
assert_eq!(machdr::check_macbin(inp), None);
assert_eq!(machdr::check_apple_single(inp), None);
assert_eq!(machdr::try_mac_header(inp), 0);
}
}
// EOF // EOF