37 lines
1.5 KiB
Rust
37 lines
1.5 KiB
Rust
//! Random mutations of valid books never panic and finish in bounded time.
|
|
|
|
mod common;
|
|
use common::*;
|
|
use liber_format::{Limits, open};
|
|
use proptest::prelude::*;
|
|
|
|
fn seeds() -> Vec<Vec<u8>> {
|
|
let mut m =
|
|
Mobi::new("<html><body><h1>A</h1><p>Text ž</p><img recindex=\"1\"/><mbp:pagebreak/><p>B</p></body></html>");
|
|
m.images.push(PNG.to_vec());
|
|
vec![
|
|
Epub::new("Fuzz").chapter("One", "<p>Hello <em>world</em> <a href=\"#x\">x</a></p><aside id=\"x\">n</aside>").file("OEBPS/a.png", PNG).build(),
|
|
m.build(),
|
|
br#"<?xml version="1.0"?><FictionBook><description><title-info><book-title>F</book-title></title-info></description><body><section><p>t</p></section></body></FictionBook>"#.to_vec(),
|
|
]
|
|
}
|
|
|
|
proptest! {
|
|
#![proptest_config(ProptestConfig { cases: 256, ..ProptestConfig::default() })]
|
|
#[test]
|
|
fn mutations_never_panic(which in 0usize..3, flips in prop::collection::vec((any::<usize>(), any::<u8>()), 1..16), cut in any::<Option<usize>>()) {
|
|
let mut b = seeds().swap_remove(which);
|
|
for (at, v) in flips {
|
|
let i = at % b.len();
|
|
b[i] = v;
|
|
}
|
|
if let Some(c) = cut {
|
|
b.truncate(c % (b.len() + 1));
|
|
}
|
|
let limits = Limits { max_total: 16 << 20, max_entry: 8 << 20, max_xml: 4 << 20, max_text: 8 << 20, ..Limits::default() };
|
|
let t = std::time::Instant::now();
|
|
let _ = open(&b, None, &limits);
|
|
prop_assert!(t.elapsed().as_secs() < 5);
|
|
}
|
|
}
|