,
}
impl TestSuite {
fn run_test(test: &Test) {
let rawfile = libopenraw::rawfile_from_file(test.file.clone(), None);
match rawfile {
Ok(rawfile) => {
print!("Test '{}'", &test.name);
let count = test.results.run(rawfile.as_ref(), &test.file);
println!(" produced {count} results");
}
Err(err) => println!("Test '{}' skipped ({}): {}", &test.name, test.file, err),
}
}
fn run(&mut self) {
self.tests.iter().for_each(TestSuite::run_test);
}
/// Load the overrides to, notably, change the local path of the files.
fn load_overrides(&mut self, path: P)
where
P: AsRef,
{
if let Ok(file) = std::fs::File::open(path) {
let overrides: Overrides = from_reader(file).expect("Deserialization of overrides");
for override_ in overrides.tests {
let name = &override_.name;
if let Some(ref file) = override_.file {
let index = self.tests.iter().position(|t| &t.name == name);
if let Some(index) = index {
self.tests[index].file = file.to_string();
}
}
}
}
}
/// Load test fragment as generated by test gen.
fn load_fragments(&mut self, path: P) -> Option
where
P: AsRef,
{
let path = path.as_ref();
if !path.is_dir() {
return None;
}
let mut count = 0;
for entry in path.read_dir().ok()? {
if let Some(test) = entry.ok().and_then(|entry| {
let path = entry.path();
let file = std::fs::File::open(path).ok()?;
let config = serde_xml_rs::ParserConfig::new().trim_whitespace(false);
let event_reader = serde_xml_rs::EventReader::new_with_config(file, config);
Test::deserialize(&mut Deserializer::new(event_reader)).ok()
}) {
self.tests.push(test);
count += 1;
}
}
Some(count)
}
}
/// Test statistics
#[derive(Default, Debug, PartialEq)]
struct TestStats {
passed: u32,
failed: u32,
skipped: u32,
}
fn load_testsuite(path: P) -> Option
where
P: AsRef,
{
let file = std::fs::File::open(path).expect("Failed to open");
// By default serde will trim the whitespace at the end of CDATA.
// We need it not to for the testsuite.
let config = serde_xml_rs::ParserConfig::new().trim_whitespace(false);
let event_reader = serde_xml_rs::EventReader::new_with_config(file, config);
let testsuite =
TestSuite::deserialize(&mut Deserializer::new(event_reader)).expect("Deserialization");
Some(testsuite)
}
#[test]
fn test_regression_suite() {
use log::LevelFilter;
use simple_logger::SimpleLogger;
SimpleLogger::new()
.with_module_level("serde_xml_rs", LevelFilter::Error)
.with_module_level("mp4parse", LevelFilter::Error)
.with_module_level("libopenraw", LevelFilter::Error)
.init()
.unwrap();
let testsuite = load_testsuite("testsuite/testsuite.xml");
assert!(testsuite.is_some(), "Expected testsuite to load");
let mut testsuite = testsuite.unwrap();
testsuite.load_overrides("testsuite/testsuite.xml.overrides");
testsuite.load_fragments("testsuite/testsuite.d");
testsuite.run();
println!(
"Test suite, passed: {} failed: {} skipped: {}",
testsuite.stats.passed, testsuite.stats.failed, testsuite.stats.skipped
);
}