Skip to content

Commit c1f6dd6

Browse files
committed
test encoder_compress function
1 parent cf3276a commit c1f6dd6

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "brotli"
3-
version = "6.0.0"
3+
version = "7.0.0"
44
authors = ["Daniel Reiter Horn <[email protected]>", "The Brotli Authors"]
55
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."
66
license = "BSD-3-Clause AND MIT"

src/enc/encode.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ pub(crate) fn encoder_compress<
14751475
if is_9_5 {
14761476
let mut params = BrotliEncoderParams::default();
14771477
params.q9_5 = true;
1478-
params.quality = 9;
1478+
params.quality = 10;
14791479
ChooseHasher(&mut params);
14801480
s_orig.hasher_ = BrotliMakeHasher(m8, &params);
14811481
}
@@ -3040,3 +3040,34 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
30403040
ret
30413041
}
30423042
}
3043+
3044+
#[cfg(feature = "std")]
3045+
mod test {
3046+
#[cfg(test)]
3047+
use alloc_stdlib::StandardAlloc;
3048+
3049+
#[test]
3050+
fn test_encoder_compress() {
3051+
let mut input = include_bytes!("../../testdata/alice29.txt");
3052+
let mut output_buffer = [0; 100000];
3053+
let mut output_len = output_buffer.len();
3054+
let ret = super::encoder_compress(
3055+
StandardAlloc::default(),
3056+
&mut StandardAlloc::default(),
3057+
9,
3058+
16,
3059+
super::BrotliEncoderMode::BROTLI_MODE_GENERIC,
3060+
input.len(),
3061+
input,
3062+
&mut output_len,
3063+
&mut output_buffer,
3064+
&mut |_,_,_,_|(),
3065+
);
3066+
assert!(ret);
3067+
assert_eq!(output_len,51737);
3068+
let mut roundtrip = [0u8; 200000];
3069+
let (_, s, t) = super::super::test::oneshot_decompress(&output_buffer[..output_len], &mut roundtrip[..]);
3070+
assert_eq!(roundtrip[..t], input[..]);
3071+
assert_eq!(s, output_len);
3072+
}
3073+
}

src/enc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn oneshot_compress(
217217
(true, next_out_offset)
218218
}
219219

220-
fn oneshot_decompress(compressed: &[u8], output: &mut [u8]) -> (BrotliResult, usize, usize) {
220+
pub(crate) fn oneshot_decompress(compressed: &[u8], output: &mut [u8]) -> (BrotliResult, usize, usize) {
221221
let mut available_in: usize = compressed.len();
222222
let mut available_out: usize = output.len();
223223
let mut stack_u8_buffer = define_allocator_memory_pool!(128, u8, [0; 100 * 1024], stack);

0 commit comments

Comments
 (0)