From c1f6dd6c265e1bf794b477fb327d77b66fb60a19 Mon Sep 17 00:00:00 2001 From: Daniel Reiter Horn Date: Wed, 2 Oct 2024 00:04:31 -0700 Subject: [PATCH] test encoder_compress function --- Cargo.toml | 2 +- src/enc/encode.rs | 33 ++++++++++++++++++++++++++++++++- src/enc/test.rs | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 26adb17b..a6479f2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brotli" -version = "6.0.0" +version = "7.0.0" authors = ["Daniel Reiter Horn ", "The Brotli Authors"] description = "A brotli compressor and decompressor that with an interface avoiding the rust stdlib. This makes it suitable for embedded devices and kernels. It is designed with a pluggable allocator so that the standard lib's allocator may be employed. The default build also includes a stdlib allocator and stream interface. Disable this with --features=no-stdlib. All included code is safe." license = "BSD-3-Clause AND MIT" diff --git a/src/enc/encode.rs b/src/enc/encode.rs index 1d51d9d5..b9601c39 100644 --- a/src/enc/encode.rs +++ b/src/enc/encode.rs @@ -1475,7 +1475,7 @@ pub(crate) fn encoder_compress< if is_9_5 { let mut params = BrotliEncoderParams::default(); params.q9_5 = true; - params.quality = 9; + params.quality = 10; ChooseHasher(&mut params); s_orig.hasher_ = BrotliMakeHasher(m8, ¶ms); } @@ -3040,3 +3040,34 @@ impl BrotliEncoderStateStruct { ret } } + +#[cfg(feature = "std")] +mod test { + #[cfg(test)] + use alloc_stdlib::StandardAlloc; + + #[test] + fn test_encoder_compress() { + let mut input = include_bytes!("../../testdata/alice29.txt"); + let mut output_buffer = [0; 100000]; + let mut output_len = output_buffer.len(); + let ret = super::encoder_compress( + StandardAlloc::default(), + &mut StandardAlloc::default(), + 9, + 16, + super::BrotliEncoderMode::BROTLI_MODE_GENERIC, + input.len(), + input, + &mut output_len, + &mut output_buffer, + &mut |_,_,_,_|(), + ); + assert!(ret); + assert_eq!(output_len,51737); + let mut roundtrip = [0u8; 200000]; + let (_, s, t) = super::super::test::oneshot_decompress(&output_buffer[..output_len], &mut roundtrip[..]); + assert_eq!(roundtrip[..t], input[..]); + assert_eq!(s, output_len); + } +} diff --git a/src/enc/test.rs b/src/enc/test.rs index ce983d9b..a9d5577b 100755 --- a/src/enc/test.rs +++ b/src/enc/test.rs @@ -217,7 +217,7 @@ fn oneshot_compress( (true, next_out_offset) } -fn oneshot_decompress(compressed: &[u8], output: &mut [u8]) -> (BrotliResult, usize, usize) { +pub(crate) fn oneshot_decompress(compressed: &[u8], output: &mut [u8]) -> (BrotliResult, usize, usize) { let mut available_in: usize = compressed.len(); let mut available_out: usize = output.len(); let mut stack_u8_buffer = define_allocator_memory_pool!(128, u8, [0; 100 * 1024], stack);