From 7c67b40e4dc9c652449b5eb55b363f8016bf7cbf Mon Sep 17 00:00:00 2001 From: 404Setup <153366651+404Setup@users.noreply.github.com> Date: Sun, 12 Apr 2026 02:24:16 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20for=20compress=5Fz?= =?UTF-8?q?lib=5Finto=20with=20success=20and=20insufficient=20space=20scen?= =?UTF-8?q?arios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- tests/unit_tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit_tests.rs b/tests/unit_tests.rs index 107ccb2..21d4a93 100644 --- a/tests/unit_tests.rs +++ b/tests/unit_tests.rs @@ -182,6 +182,25 @@ fn test_compress_gzip_into_success() { assert_eq!(data.to_vec(), decompressed); } +#[test] +fn test_compress_zlib_into_success() { + let mut compressor = Compressor::new(6).unwrap(); + let mut decompressor = Decompressor::new(); + let data = b"Hello world! This is a test string for zlib compression into buffer."; + + let bound = compressor.zlib_compress_bound(data.len()); + let mut output = vec![0u8; bound]; + + let size = compressor.compress_zlib_into(data, &mut output).unwrap(); + assert!(size > 0); + assert!(size <= bound); + + let decompressed = decompressor + .decompress_zlib(&output[..size], data.len()) + .unwrap(); + assert_eq!(data.to_vec(), decompressed); +} + #[test] fn test_compress_gzip_into_insufficient_space() { let mut compressor = Compressor::new(6).unwrap(); @@ -192,6 +211,16 @@ fn test_compress_gzip_into_insufficient_space() { assert!(result.is_err()); } +#[test] +fn test_compress_zlib_into_insufficient_space() { + let mut compressor = Compressor::new(6).unwrap(); + let data = b"Hello world! This is a test string for zlib compression."; + + let mut output = vec![0u8; 10]; + let result = compressor.compress_zlib_into(data, &mut output); + assert!(result.is_err()); +} + #[test] fn test_new_compressor_invalid_level() { let res = Compressor::new(-1);