@@ -108,11 +108,9 @@ impl<Blocks: BlockCodec, Tail: AnyLenCodec> AnyLenCodec for CompositeCodec<Block
108108#[ cfg( test) ]
109109mod tests {
110110 use super :: * ;
111- use crate :: FastPForError ;
111+ use crate :: FastPFor256 ;
112112 use crate :: rust:: { FastPForBlock128 , FastPForBlock256 , JustCopy , VariableByte } ;
113- use crate :: test_utils:: { compress, decompress, roundtrip_composite} ;
114-
115- type Comp256Vb = CompositeCodec < FastPForBlock256 , VariableByte > ;
113+ use crate :: test_utils:: { compress, decompress, roundtrip_composite, roundtrip_expected} ;
116114
117115 #[ test]
118116 fn test_fastpfor256_vbyte_exact_two_blocks ( ) {
@@ -140,20 +138,20 @@ mod tests {
140138 #[ test]
141139 fn test_decode_truly_empty_input ( ) {
142140 // Decoding a zero-length slice (not even a header word) must succeed with empty output.
143- assert ! ( decompress:: <Comp256Vb >( & [ ] , None ) . unwrap( ) . is_empty( ) ) ;
141+ assert ! ( decompress:: <FastPFor256 >( & [ ] , None ) . unwrap( ) . is_empty( ) ) ;
144142 }
145143
146144 #[ test]
147145 fn test_decode_empty_input_with_expected_zero ( ) {
148146 // Empty input with expected_len=0 must succeed.
149- assert ! ( decompress:: <Comp256Vb >( & [ ] , Some ( 0 ) ) . unwrap( ) . is_empty( ) ) ;
147+ assert ! ( decompress:: <FastPFor256 >( & [ ] , Some ( 0 ) ) . unwrap( ) . is_empty( ) ) ;
150148 }
151149
152150 #[ test]
153151 fn test_decode_empty_input_with_nonzero_expected_errors ( ) {
154152 // Empty input: max_decompressed_len(0) == 0, so any expected_len > 0 fails
155153 // with ExpectedCountExceedsMax before decoding begins.
156- decompress :: < CompositeCodec < FastPForBlock256 , VariableByte > > ( & [ ] , Some ( 5 ) ) . unwrap_err ( ) ;
154+ decompress :: < FastPFor256 > ( & [ ] , Some ( 5 ) ) . unwrap_err ( ) ;
157155 }
158156
159157 #[ test]
@@ -163,7 +161,7 @@ mod tests {
163161 // Regression: fuzzer found bytes [0x04, 0x35, 0x19] → u32 LE 0x00193504 = 1_651_460
164162 // fed to FastPFor256.decode caused an OOM via a ~2.5 GB Vec::resize.
165163 let input = & [ 0x0019_3504u32 ] ; // n_blocks = 1_651_460, rest is empty
166- decompress :: < CompositeCodec < FastPForBlock256 , VariableByte > > ( input, None ) . unwrap_err ( ) ;
164+ decompress :: < FastPFor256 > ( input, None ) . unwrap_err ( ) ;
167165 }
168166
169167 #[ test]
@@ -175,36 +173,21 @@ mod tests {
175173 #[ test]
176174 fn test_decode_with_expected_len ( ) {
177175 let data: Vec < u32 > = ( 0 ..600 ) . collect ( ) ;
178- let encoded = compress :: < Comp256Vb > ( & data) . unwrap ( ) ;
179- let decoded = decompress :: < Comp256Vb > ( & encoded, Some ( 600 ) ) . unwrap ( ) ;
180- assert_eq ! ( decoded, data) ;
176+ roundtrip_expected :: < FastPFor256 > ( & data, Some ( 600 ) ) ;
181177 }
182178
183179 #[ test]
184180 fn test_decode_expected_len_mismatch_errors ( ) {
185181 let data: Vec < u32 > = ( 0 ..100 ) . collect ( ) ;
186- let encoded = compress :: < Comp256Vb > ( & data) . unwrap ( ) ;
187- let mut codec = Comp256Vb :: default ( ) ;
188- let err = codec
189- . decode ( & encoded, & mut Vec :: new ( ) , Some ( 50 ) )
190- . unwrap_err ( ) ;
191- assert ! ( matches!(
192- err,
193- FastPForError :: DecodedCountMismatch {
194- actual: 100 ,
195- expected: 50
196- }
197- ) ) ;
182+ let encoded = compress :: < FastPFor256 > ( & data) . unwrap ( ) ;
183+ decompress :: < FastPFor256 > ( & encoded, Some ( 50 ) ) . unwrap_err ( ) ;
198184 }
199185
200186 #[ test]
201187 fn test_decode_expected_len_exceeds_max_errors ( ) {
202188 let data: Vec < u32 > = ( 0 ..10 ) . collect ( ) ;
203- let encoded = compress :: < Comp256Vb > ( & data) . unwrap ( ) ;
204- let huge = ( Comp256Vb :: max_decompressed_len ( encoded. len ( ) ) + 1 ) as u32 ;
205- let err = Comp256Vb :: default ( )
206- . decode ( & encoded, & mut Vec :: new ( ) , Some ( huge) )
207- . unwrap_err ( ) ;
208- assert ! ( matches!( err, FastPForError :: ExpectedCountExceedsMax { .. } ) ) ;
189+ let encoded = compress :: < FastPFor256 > ( & data) . unwrap ( ) ;
190+ let huge = ( FastPFor256 :: max_decompressed_len ( encoded. len ( ) ) + 1 ) as u32 ;
191+ decompress :: < FastPFor256 > ( & encoded, Some ( huge) ) . unwrap_err ( ) ;
209192 }
210193}
0 commit comments