aboutsummaryrefslogtreecommitdiff
path: root/vendor/flate2/tests/gunzip.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/flate2/tests/gunzip.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/flate2/tests/gunzip.rs')
-rw-r--r--vendor/flate2/tests/gunzip.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/flate2/tests/gunzip.rs b/vendor/flate2/tests/gunzip.rs
new file mode 100644
index 0000000..f7d4132
--- /dev/null
+++ b/vendor/flate2/tests/gunzip.rs
@@ -0,0 +1,75 @@
+use flate2::read::GzDecoder;
+use flate2::read::MultiGzDecoder;
+use std::fs::File;
+use std::io::prelude::*;
+use std::io::{self, BufReader};
+use std::path::Path;
+
+// test extraction of a gzipped file
+#[test]
+fn test_extract_success() {
+ let content = extract_file(Path::new("tests/good-file.gz")).unwrap();
+ let mut expected = Vec::new();
+ File::open("tests/good-file.txt")
+ .unwrap()
+ .read_to_end(&mut expected)
+ .unwrap();
+ assert_eq!(content, expected);
+}
+//
+// test partial extraction of a multistream gzipped file
+#[test]
+fn test_extract_success_partial_multi() {
+ let content = extract_file(Path::new("tests/multi.gz")).unwrap();
+ let mut expected = String::new();
+ BufReader::new(File::open("tests/multi.txt").unwrap())
+ .read_line(&mut expected)
+ .unwrap();
+ assert_eq!(content, expected.as_bytes());
+}
+
+// test extraction fails on a corrupt file
+#[test]
+fn test_extract_failure() {
+ let result = extract_file(Path::new("tests/corrupt-gz-file.bin"));
+ assert_eq!(result.err().unwrap().kind(), io::ErrorKind::InvalidInput);
+}
+
+//test complete extraction of a multistream gzipped file
+#[test]
+fn test_extract_success_multi() {
+ let content = extract_file_multi(Path::new("tests/multi.gz")).unwrap();
+ let mut expected = Vec::new();
+ File::open("tests/multi.txt")
+ .unwrap()
+ .read_to_end(&mut expected)
+ .unwrap();
+ assert_eq!(content, expected);
+}
+
+// Tries to extract path into memory (assuming a .gz file).
+fn extract_file(path_compressed: &Path) -> io::Result<Vec<u8>> {
+ let mut v = Vec::new();
+ let f = File::open(path_compressed)?;
+ GzDecoder::new(f).read_to_end(&mut v)?;
+ Ok(v)
+}
+
+// Tries to extract path into memory (decompressing all members in case
+// of a multi member .gz file).
+fn extract_file_multi(path_compressed: &Path) -> io::Result<Vec<u8>> {
+ let mut v = Vec::new();
+ let f = File::open(path_compressed)?;
+ MultiGzDecoder::new(f).read_to_end(&mut v)?;
+ Ok(v)
+}
+
+#[test]
+fn empty_error_once() {
+ let data: &[u8] = &[];
+ let cbjson = GzDecoder::new(data);
+ let reader = BufReader::new(cbjson);
+ let mut stream = reader.lines();
+ assert!(stream.next().unwrap().is_err());
+ assert!(stream.next().is_none());
+}