From 93f676fa5772ca3c4b481cfbb08720539cb016d8 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Tue, 14 Mar 2017 19:41:48 +0100 Subject: [PATCH] Add two simple tests. --- src/write.rs | 37 +++++++++++++++++++++++++++++++++++++ tests/data/mimetype.zip | Bin 0 -> 159 bytes 2 files changed, 37 insertions(+) create mode 100644 tests/data/mimetype.zip diff --git a/src/write.rs b/src/write.rs index 173eff97..6e25e13e 100644 --- a/src/write.rs +++ b/src/write.rs @@ -497,3 +497,40 @@ fn build_extra_field(_file: &ZipFileData) -> ZipResult> // Future work Ok(writer) } + +#[cfg(test)] +mod test { + use std::io; + use std::io::Write; + use time; + use write::{FileOptions, CompressionMethod, ZipWriter}; + + #[test] + fn write_empty_zip() { + let mut writer = ZipWriter::new(io::Cursor::new(Vec::new())); + let result = writer.finish().unwrap(); + assert_eq!(result.get_ref().len(), 28); + let v: Vec = vec![80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 122, 105, 112, 45, 114, 115]; + assert_eq!(result.get_ref(), &v); + } + + #[test] + fn write_mimetype_zip() { + let mut writer = ZipWriter::new(io::Cursor::new(Vec::new())); + let mut mtime = time::empty_tm(); + mtime.tm_year = 80; + mtime.tm_mday = 1; + let options = FileOptions { + compression_method: CompressionMethod::Stored, + last_modified_time: mtime, + permissions: Some(33188), + }; + writer.start_file("mimetype", options).unwrap(); + writer.write(b"application/vnd.oasis.opendocument.text").unwrap(); + let result = writer.finish().unwrap(); + assert_eq!(result.get_ref().len(), 159); + let mut v = Vec::new(); + v.extend_from_slice(include_bytes!("../tests/data/mimetype.zip")); + assert_eq!(result.get_ref(), &v); + } +} diff --git a/tests/data/mimetype.zip b/tests/data/mimetype.zip new file mode 100644 index 0000000000000000000000000000000000000000..d303463d84290caea2eebbb36d709a9739640e99 GIT binary patch literal 159 zcmWIWW@Zs#W&i_4hPY!!JnBF;2y*~&Zf0(3No7H5VnIPpW^!UlW`3T2Szd}>eqwQE zv0i>bYFvk2HQ1_n&ypb`vA8bK_W;Q`*PY#=@(5SjsL PUm#{ literal 0 HcmV?d00001