Skip to content

Commit

Permalink
Add nonsparse to the tested set of files
Browse files Browse the repository at this point in the history
libvorbis can't handle it but libnogg
regards it as valid file, as do we.
So we can just add it to testing.
  • Loading branch information
est31 committed Sep 13, 2018
1 parent 95fa236 commit 10c479d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
19 changes: 19 additions & 0 deletions dev/cmp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ macro_rules! ensure_malformed {
}}
}

/// Ensures that a file decodes without errors
#[macro_export]
macro_rules! ensure_okay {
($name:expr) => {{
use std::fs::File;
use lewton::inside_ogg::OggStreamReader;
// Read the file to memory
let f = File::open(format!("test-assets/{}", $name)).unwrap();
if let Some(mut ogg_rdr) = OggStreamReader::new(f).map(|v| Some(v)).unwrap() {
loop {
match ogg_rdr.read_dec_packet_itl().unwrap() {
Some(_) => (),
None => break,
};
}
}
}}
}

use self::test_assets::TestAssetDef;

pub fn get_asset_defs() -> [TestAssetDef; 6] {
Expand Down
27 changes: 0 additions & 27 deletions dev/cmp/tests/fuzzed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ extern crate test_assets;
extern crate cmp;
extern crate lewton;

macro_rules! try {
($expr:expr) => (match $expr {
$crate::std::result::Result::Ok(val) => val,
$crate::std::result::Result::Err(err) => {
panic!("Error: {:?}", err)
}
})
}

#[test]
fn test_malformed_fuzzed() {
println!();
Expand All @@ -35,24 +26,6 @@ fn test_malformed_fuzzed() {
ensure_malformed!("32_minimized_crash_testcase.ogg", BadHeader(HeaderBadFormat));
}

// Ensures that a file is okay
macro_rules! ensure_okay {
($name:expr) => {{
use std::fs::File;
use lewton::inside_ogg::OggStreamReader;
// Read the file to memory
let f = try!(File::open(format!("test-assets/{}", $name)));
if let Some(mut ogg_rdr) = try!(OggStreamReader::new(f).map(|v| Some(v))) {
loop {
match try!(ogg_rdr.read_dec_packet_itl()) {
Some(_) => (),
None => break,
};
}
}
}}
}

#[test]
fn test_okay_fuzzed() {
println!();
Expand Down
6 changes: 3 additions & 3 deletions dev/cmp/tests/vals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ fn test_libnogg_vals() {
cmp_output!("partial-granule-position.ogg", 2);
cmp_output!("sample-rate-max.ogg", 0);
ensure_malformed!("single-code-2bits.ogg", BadHeader(HeaderBadFormat));
// TODO we are getting Error: BadHeader here.
// is that expected?
//cmp_output!("single-code-nonsparse.ogg", 0);
// We can't cmp the output here because native
// libvorbis doesn't accept the file as valid
ensure_okay!("single-code-nonsparse.ogg");
//cmp_output!("single-code-ordered.ogg", 0);
// TODO fix this
//cmp_output!("single-code-sparse.ogg", 0);
Expand Down

0 comments on commit 10c479d

Please sign in to comment.