From a4db0628a0377b39be02f0e83832b0c3527933e1 Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Wed, 2 Mar 2016 12:57:36 +0100 Subject: Merging of any number of logs --- tests/files/mod.rs | 25 +++++++++++++++++++++++++ tests/lib.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/files/mod.rs create mode 100644 tests/lib.rs (limited to 'tests') diff --git a/tests/files/mod.rs b/tests/files/mod.rs new file mode 100644 index 0000000..5b25e90 --- /dev/null +++ b/tests/files/mod.rs @@ -0,0 +1,25 @@ +extern crate flate2; + +use std::fs::File; +use std::path::Path; +use std::io::{BufReader, Read, Write}; + +use self::flate2::FlateReadExt; + +#[allow(dead_code)] +pub fn read(path: &str) -> Vec { + let path = Path::new("tests").join("input").join(&format!("{}.gz", path)); + let size = path.metadata().expect("Couldn't determine filesize").len(); + let mut out = Vec::with_capacity(size as usize); + let mut input = BufReader::new(File::open(path).expect("Couldn't open file")) + .gz_decode() + .expect("Couldn't decode GZ stream"); + input.read_to_end(&mut out).expect("Couldn't read data"); + out +} + +#[allow(dead_code)] +pub fn write>(p: P, b: &[u8]) { + let mut out = File::create(p).expect("Couldn't create file"); + out.write_all(b).expect("Couldn't write data"); +} diff --git a/tests/lib.rs b/tests/lib.rs new file mode 100644 index 0000000..d236f49 --- /dev/null +++ b/tests/lib.rs @@ -0,0 +1,46 @@ +extern crate ilc; + +use std::default::Default; +use std::io::Cursor; + +use ilc::*; + +mod files; + +#[test] +fn identity() { + let original = files::read("2016-02-26.log"); + let mut output = Vec::new(); + + convert(&Context::default(), + &mut (&original as &[u8]), + &mut Energymech, + &mut output, + &Energymech) + .expect("Conversion failed"); + + files::write("identity.out", &output); + + // don't assert_eq!, as the failed ouput doesn't help anyone + assert!(&original == &output); +} + +/* #[test] + * fn merge() { + * let part1 = Cursor::new(files::read("2016-02-26.log.1")); + * let part2 = Cursor::new(files::read("2016-02-26.log.2")); + * + * let mut output = Vec::new(); + * + * merge(&Context::default(), + * vec![&mut part1, &mut part2], + * &mut Energymech, + * &mut output, + * &Energymech) + * .expect("Merge failed"); + * + * files::write("merged.out", &output); + * + * let original = files::read("2016-02-26.log"); + * assert!(&original == &output); + * } */ -- cgit v1.2.3