Skip to content

Commit 90c8d41

Browse files
authored
Add edge case and success tests for compress_zlib_into (#421)
- Added `test_compress_zlib_into_success` to verify successful compression into a provided buffer. - Added `test_compress_zlib_into_insufficient_space` to verify correct error handling when the output buffer is too small. - Mirrored existing gzip compression testing patterns for consistency. - Verified decompression of zlib-compressed data in the success case.
1 parent 7ce16e4 commit 90c8d41

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/unit_tests.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,25 @@ fn test_compress_gzip_into_success() {
182182
assert_eq!(data.to_vec(), decompressed);
183183
}
184184

185+
#[test]
186+
fn test_compress_zlib_into_success() {
187+
let mut compressor = Compressor::new(6).unwrap();
188+
let mut decompressor = Decompressor::new();
189+
let data = b"Hello world! This is a test string for zlib compression into buffer.";
190+
191+
let bound = compressor.zlib_compress_bound(data.len());
192+
let mut output = vec![0u8; bound];
193+
194+
let size = compressor.compress_zlib_into(data, &mut output).unwrap();
195+
assert!(size > 0);
196+
assert!(size <= bound);
197+
198+
let decompressed = decompressor
199+
.decompress_zlib(&output[..size], data.len())
200+
.unwrap();
201+
assert_eq!(data.to_vec(), decompressed);
202+
}
203+
185204
#[test]
186205
fn test_compress_gzip_into_insufficient_space() {
187206
let mut compressor = Compressor::new(6).unwrap();
@@ -192,6 +211,16 @@ fn test_compress_gzip_into_insufficient_space() {
192211
assert!(result.is_err());
193212
}
194213

214+
#[test]
215+
fn test_compress_zlib_into_insufficient_space() {
216+
let mut compressor = Compressor::new(6).unwrap();
217+
let data = b"Hello world! This is a test string for zlib compression.";
218+
219+
let mut output = vec![0u8; 10];
220+
let result = compressor.compress_zlib_into(data, &mut output);
221+
assert!(result.is_err());
222+
}
223+
195224
#[test]
196225
fn test_new_compressor_invalid_level() {
197226
let res = Compressor::new(-1);

0 commit comments

Comments
 (0)