Skip to content

Commit 57425a6

Browse files
committed
Make partial decompression test work with both zlib and miniz_oxide
1 parent 8769362 commit 57425a6

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tests/decompress_chunk.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[test]
22
fn deflate_decoder_partial() {
3-
// Decompresses to
4-
// "* QUOTAROOT INBOX \"User quota\"\r\n* QUOTA \"User quota\" (STORAGE 76 307200)\r\nA0001 OK Getquotaroot completed (0.001 + 0.000 secs).\r\n"
53
let input = vec![
64
210, 82, 8, 12, 245, 15, 113, 12, 242, 247, 15, 81, 240, 244, 115, 242, 143, 80, 80, 10,
75
45, 78, 45, 82, 40, 44, 205, 47, 73, 84, 226, 229, 210, 130, 200, 163, 136, 42, 104, 4,
@@ -10,19 +8,32 @@ fn deflate_decoder_partial() {
108
231, 22, 228, 164, 150, 164, 166, 40, 104, 24, 232, 129, 20, 104, 43, 128, 104, 3, 133,
119
226, 212, 228, 98, 77, 61, 94, 46, 0, 0, 0, 0, 255, 255,
1210
];
11+
let expected_output = b"* QUOTAROOT INBOX \"User quota\"\r\n* QUOTA \"User quota\" (STORAGE 76 307200)\r\nA0001 OK Getquotaroot completed (0.001 + 0.000 secs).\r\n";
1312

1413
// Create very small output buffer.
15-
let mut output = vec![0; 8];
14+
let mut output_buf = [0; 8];
15+
let mut output: Vec<u8> = Vec::new();
1616

1717
let zlib_header = false;
1818
let mut decompress = flate2::Decompress::new(zlib_header);
1919

2020
let flush_decompress = flate2::FlushDecompress::None;
21-
let status = decompress
22-
.decompress(&input, &mut output, flush_decompress)
23-
.unwrap();
24-
assert_eq!(status, flate2::Status::Ok);
21+
loop {
22+
let prev_out = decompress.total_out();
23+
let status = decompress
24+
.decompress(&input[decompress.total_in() as usize..], &mut output_buf, flush_decompress)
25+
.unwrap();
26+
let output_len = decompress.total_out() - prev_out;
27+
output.extend_from_slice(&output_buf[..output_len as usize]);
28+
eprintln!("{}", output.len());
2529

26-
// Should not consume everything, there is not enough space in the buffer for the output.
27-
assert_ne!(decompress.total_in(), input.len() as u64);
30+
// IMAP stream never ends.
31+
assert_ne!(status, flate2::Status::StreamEnd);
32+
33+
if status == flate2::Status::BufError && output_len == 0 {
34+
break;
35+
}
36+
}
37+
38+
assert_eq!(output.as_slice(), expected_output);
2839
}

0 commit comments

Comments
 (0)