aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorigorechek06 <me@igorek.dev>2024-08-10 22:58:27 +0900
committerigorechek06 <me@igorek.dev>2024-08-10 23:00:37 +0900
commita24ae8622cc2f829a8101a7f812fc98297053cc3 (patch)
tree2a5cc78829976c60a28cc597a7df4cdd24f862fb /tests
parent1bb400dcb258f135a3f92f6242e728f0475325c1 (diff)
downloadarchivator-a24ae8622cc2f829a8101a7f812fc98297053cc3.tar.gz
archivator-a24ae8622cc2f829a8101a7f812fc98297053cc3.zip
Add more tests
Diffstat (limited to 'tests')
-rw-r--r--tests/files/blank0
-rw-r--r--tests/files/empty.zipbin22 -> 0 bytes
-rw-r--r--tests/zip.rs39
3 files changed, 30 insertions, 9 deletions
diff --git a/tests/files/blank b/tests/files/blank
deleted file mode 100644
index e69de29..0000000
--- a/tests/files/blank
+++ /dev/null
diff --git a/tests/files/empty.zip b/tests/files/empty.zip
deleted file mode 100644
index 15cb0ec..0000000
--- a/tests/files/empty.zip
+++ /dev/null
Binary files differ
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 @@
1use archivator::zip::ZipError; 1use archivator::zip::ZipError;
2use archivator::{Archive, Zip}; 2use archivator::{Archive, Zip};
3use std::io::{Read, Seek, SeekFrom}; 3use std::io::{Cursor, Read, Seek, SeekFrom};
4 4
5#[test] 5#[test]
6fn test_zip_aes() { 6fn test_zip_aes() {
@@ -90,14 +90,11 @@ fn test_zip_weak() {
90 } 90 }
91} 91}
92 92
93const 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]
94fn test_zip() { 96fn 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
161const NOT_FOUND: Cursor<&[u8]> = Cursor::new(b"");
162const 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);
165const 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");
166const 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]
165fn test_bad_zip() { 169fn 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}