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 00000000..d303463d Binary files /dev/null and b/tests/data/mimetype.zip differ