Skip to content

Commit

Permalink
test encoder_compress function
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrh committed Oct 2, 2024
1 parent cf3276a commit 08a4a9a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "brotli"
version = "6.0.0"
version = "7.0.0"
authors = ["Daniel Reiter Horn <[email protected]>", "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"
Expand Down
33 changes: 32 additions & 1 deletion src/enc/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params);
}
Expand Down Expand Up @@ -3040,3 +3040,34 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
ret
}
}

#[cfg(feature = "std")]
mod test {
#[cfg(test)]
use alloc_stdlib::StandardAlloc;

#[test]
fn test_encoder_compress() {
let 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);
}
}
2 changes: 1 addition & 1 deletion src/enc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 08a4a9a

Please sign in to comment.