add random data tests
parent
1d6aa0c14e
commit
6e3fff0080
|
@ -16,7 +16,8 @@ pub fn read_group(b: &[u8], text: &[u8]) -> ResultS<Group>
|
|||
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 ttype = match ttype {
|
||||
0 => GroupType::Logon(pdata),
|
||||
|
@ -78,7 +79,7 @@ pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
|
|||
let mut p = 10;
|
||||
|
||||
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 {
|
||||
fuck_string(text)
|
||||
} else {
|
||||
|
@ -86,12 +87,12 @@ pub fn read_term(b: &[u8]) -> ResultS<(Terminal, usize)>
|
|||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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õ
|
|
@ -0,0 +1 @@
|
|||
浮齡
|
Binary file not shown.
Binary file not shown.
45
tests/map.rs
45
tests/map.rs
|
@ -1,5 +1,7 @@
|
|||
use maraiah::{durandal::{bin, fixed::*}, marathon::{map, trm}};
|
||||
|
||||
include!("data/rand.rs");
|
||||
|
||||
#[test]
|
||||
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]
|
||||
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());
|
||||
}
|
||||
|
||||
#[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
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use maraiah::{durandal::image::Color8, marathon::{machdr, pict}};
|
||||
|
||||
include!("data/rand.rs");
|
||||
|
||||
#[test]
|
||||
fn get_clut_must_process_this()
|
||||
fn get_clut_must_process()
|
||||
{
|
||||
const INPUT: &[u8] = include_bytes!("data/clut.in");
|
||||
const OUTPUT: [Color8; 256] = include!("data/clut.out");
|
||||
|
@ -10,14 +12,32 @@ fn get_clut_must_process_this()
|
|||
}
|
||||
|
||||
#[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");
|
||||
|
||||
assert_eq!(machdr::check_macbin(INPUT), Some(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
|
||||
|
|
Loading…
Reference in New Issue