diff options
| author | igorechek06 <me@igorek.dev> | 2024-08-10 22:58:27 +0900 |
|---|---|---|
| committer | igorechek06 <me@igorek.dev> | 2024-08-10 23:00:37 +0900 |
| commit | a24ae8622cc2f829a8101a7f812fc98297053cc3 (patch) | |
| tree | 2a5cc78829976c60a28cc597a7df4cdd24f862fb /tests/zip.rs | |
| parent | 1bb400dcb258f135a3f92f6242e728f0475325c1 (diff) | |
| download | archivator-a24ae8622cc2f829a8101a7f812fc98297053cc3.tar.gz archivator-a24ae8622cc2f829a8101a7f812fc98297053cc3.zip | |
Add more tests
Diffstat (limited to 'tests/zip.rs')
| -rw-r--r-- | tests/zip.rs | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/tests/zip.rs b/tests/zip.rs index e2b5c20..1422bb3 100644 --- a/tests/zip.rs +++ b/tests/zip.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use archivator::zip::ZipError; | 1 | use archivator::zip::ZipError; |
| 2 | use archivator::{Archive, Zip}; | 2 | use archivator::{Archive, Zip}; |
| 3 | use std::io::{Read, Seek, SeekFrom}; | 3 | use std::io::{Cursor, Read, Seek, SeekFrom}; |
| 4 | 4 | ||
| 5 | #[test] | 5 | #[test] |
| 6 | fn test_zip_aes() { | 6 | fn test_zip_aes() { |
| @@ -90,14 +90,11 @@ fn test_zip_weak() { | |||
| 90 | } | 90 | } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | const EMPTY: Cursor<&[u8]> = Cursor::new(b"PK\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); | ||
| 94 | |||
| 93 | #[test] | 95 | #[test] |
| 94 | fn test_zip() { | 96 | fn test_zip() { |
| 95 | assert_eq!( | 97 | assert_eq!(Archive::<Zip<_>>::read(EMPTY).unwrap().len(), 0); |
| 96 | Archive::<Zip>::read_from_file("tests/files/empty.zip") | ||
| 97 | .unwrap() | ||
| 98 | .len(), | ||
| 99 | 0 | ||
| 100 | ); | ||
| 101 | 98 | ||
| 102 | let mut archive = Archive::<Zip>::read_from_file("tests/files/archive.zip").unwrap(); | 99 | let mut archive = Archive::<Zip>::read_from_file("tests/files/archive.zip").unwrap(); |
| 103 | 100 | ||
| @@ -161,8 +158,32 @@ fn test_zip() { | |||
| 161 | } | 158 | } |
| 162 | } | 159 | } |
| 163 | 160 | ||
| 161 | const NOT_FOUND: Cursor<&[u8]> = Cursor::new(b""); | ||
| 162 | const INVALID: Cursor<&[u8]> = Cursor::new( | ||
| 163 | b"PK\x06\x07\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PK\x05\x06\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0", | ||
| 164 | ); | ||
| 165 | const OVERLAP: Cursor<&[u8]> = Cursor::new(b"PK\x05\x06\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0"); | ||
| 166 | const OVERLAP64: Cursor<&[u8]> = Cursor::new(b"PK\x06\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PK\x06\x07\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PK\x05\x06\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0"); | ||
| 167 | |||
| 164 | #[test] | 168 | #[test] |
| 165 | fn test_bad_zip() { | 169 | fn test_bad_zip() { |
| 166 | assert!(Archive::<Zip>::read_from_file("tests/files/blank") | 170 | assert!( |
| 167 | .is_err_and(|e| e == ZipError::StructNotFound("Eocdr"))); | 171 | Archive::<Zip<_>>::read(NOT_FOUND).is_err_and(|e| e == ZipError::StructNotFound("Eocdr")) |
| 172 | ); | ||
| 173 | |||
| 174 | assert!( | ||
| 175 | Archive::<Zip<_>>::read(INVALID).is_err_and(|e| e == ZipError::InvalidSignature("Eocdr64")) | ||
| 176 | ); | ||
| 177 | |||
| 178 | assert!(Archive::<Zip<_>>::read(OVERLAP).is_err_and(|e| e | ||
| 179 | == ZipError::Overlapping( | ||
| 180 | "Central directory records", | ||
| 181 | "End of central directory record" | ||
| 182 | ))); | ||
| 183 | |||
| 184 | assert!(Archive::<Zip<_>>::read(OVERLAP64).is_err_and(|e| e | ||
| 185 | == ZipError::Overlapping( | ||
| 186 | "Central directory records", | ||
| 187 | "Zip64 end of central directory record" | ||
| 188 | ))); | ||
| 168 | } | 189 | } |
