diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/zip.rs | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/tests/zip.rs b/tests/zip.rs index 1422bb3..e00789d 100644 --- a/tests/zip.rs +++ b/tests/zip.rs | |||
| @@ -90,11 +90,17 @@ 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 | |||
| 95 | #[test] | 93 | #[test] |
| 96 | fn test_zip() { | 94 | fn test_zip() { |
| 97 | assert_eq!(Archive::<Zip<_>>::read(EMPTY).unwrap().len(), 0); | 95 | assert_eq!( |
| 96 | Archive::<Zip<_>>::read(Cursor::new(&[ | ||
| 97 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 98 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 99 | ])) | ||
| 100 | .unwrap() | ||
| 101 | .len(), | ||
| 102 | 0 | ||
| 103 | ); | ||
| 98 | 104 | ||
| 99 | let mut archive = Archive::<Zip>::read_from_file("tests/files/archive.zip").unwrap(); | 105 | let mut archive = Archive::<Zip>::read_from_file("tests/files/archive.zip").unwrap(); |
| 100 | 106 | ||
| @@ -158,32 +164,49 @@ fn test_zip() { | |||
| 158 | } | 164 | } |
| 159 | } | 165 | } |
| 160 | 166 | ||
| 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 | |||
| 168 | #[test] | 167 | #[test] |
| 169 | fn test_bad_zip() { | 168 | fn test_bad_zip() { |
| 170 | assert!( | 169 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[])) |
| 171 | Archive::<Zip<_>>::read(NOT_FOUND).is_err_and(|e| e == ZipError::StructNotFound("Eocdr")) | 170 | .is_err_and(|e| e == ZipError::StructNotFound("Eocdr"))); |
| 172 | ); | ||
| 173 | 171 | ||
| 174 | assert!( | 172 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ |
| 175 | Archive::<Zip<_>>::read(INVALID).is_err_and(|e| e == ZipError::InvalidSignature("Eocdr64")) | 173 | // No Eocdr64 |
| 176 | ); | 174 | 0x50, 0x4b, 0x06, 0x07, 0, 0, 0, 0, // |
| 175 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64Locator | ||
| 176 | // | ||
| 177 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 178 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 179 | ])) | ||
| 180 | .is_err_and(|e| e == ZipError::InvalidSignature("Eocdr64"))); | ||
| 181 | |||
| 182 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ | ||
| 183 | 0x50, 0x4b, 0x06, 0x06, // Eocdr64 | ||
| 184 | // | ||
| 185 | 0x50, 0x4b, 0x06, 0x07, 0, 0, 0, 0, // | ||
| 186 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64Locator | ||
| 187 | // | ||
| 188 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 189 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 190 | ])) | ||
| 191 | .is_err_and(|e| e == ZipError::Overlapping("Eocdr64", "Eocdr64Locator"))); | ||
| 177 | 192 | ||
| 178 | assert!(Archive::<Zip<_>>::read(OVERLAP).is_err_and(|e| e | 193 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ |
| 179 | == ZipError::Overlapping( | 194 | // No records |
| 180 | "Central directory records", | 195 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // |
| 181 | "End of central directory record" | 196 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr |
| 182 | ))); | 197 | ])) |
| 198 | .is_err_and(|e| e == ZipError::Overlapping("Cdr", "Eocdr"))); | ||
| 183 | 199 | ||
| 184 | assert!(Archive::<Zip<_>>::read(OVERLAP64).is_err_and(|e| e | 200 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ |
| 185 | == ZipError::Overlapping( | 201 | 0x50, 0x4b, 0x06, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // |
| 186 | "Central directory records", | 202 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // |
| 187 | "Zip64 end of central directory record" | 203 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64 |
| 188 | ))); | 204 | // |
| 205 | 0x50, 0x4b, 0x06, 0x07, 0, 0, 0, 0, // | ||
| 206 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64Locator | ||
| 207 | // | ||
| 208 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 209 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 210 | ])) | ||
| 211 | .is_err_and(|e| e == ZipError::Overlapping("Cdr", "Eocdr64"))); | ||
| 189 | } | 212 | } |
