MCPcopy
hub / github.com/klauspost/compress / TestWithDecodeAllCapLimit

Function TestWithDecodeAllCapLimit

zstd/decoder_test.go:2164–2215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2162}
2163
2164func TestWithDecodeAllCapLimit(t *testing.T) {
2165 var encs []*Encoder
2166 var decs []*Decoder
2167 addEnc := func(e *Encoder, _ error) {
2168 encs = append(encs, e)
2169 }
2170 addDec := func(d *Decoder, _ error) {
2171 decs = append(decs, d)
2172 }
2173 addEnc(NewWriter(nil, WithZeroFrames(true), WithWindowSize(4<<10)))
2174 addEnc(NewWriter(nil, WithEncoderConcurrency(1), WithWindowSize(4<<10)))
2175 addEnc(NewWriter(nil, WithZeroFrames(false), WithWindowSize(4<<10)))
2176 addEnc(NewWriter(nil, WithWindowSize(128<<10)))
2177 addDec(NewReader(nil, WithDecodeAllCapLimit(true)))
2178 addDec(NewReader(nil, WithDecodeAllCapLimit(true), WithDecoderConcurrency(1)))
2179 addDec(NewReader(nil, WithDecodeAllCapLimit(true), WithDecoderLowmem(true)))
2180 addDec(NewReader(nil, WithDecodeAllCapLimit(true), WithDecoderMaxWindow(128<<10)))
2181 addDec(NewReader(nil, WithDecodeAllCapLimit(true), WithDecoderMaxMemory(1<<20)))
2182 for sz := 0; sz < 1<<20; sz = (sz + 1) * 2 {
2183 sz := sz
2184 t.Run(strconv.Itoa(sz), func(t *testing.T) {
2185 t.Parallel()
2186 for ei, enc := range encs {
2187 for di, dec := range decs {
2188 t.Run(fmt.Sprintf("e%d:d%d", ei, di), func(t *testing.T) {
2189 encoded := enc.EncodeAll(make([]byte, sz), nil)
2190 for i := sz - 1; i < sz+1; i++ {
2191 if i < 0 {
2192 continue
2193 }
2194 const existinglen = 5
2195 got, err := dec.DecodeAll(encoded, make([]byte, existinglen, i+existinglen))
2196 if i < sz {
2197 if err != ErrDecoderSizeExceeded {
2198 t.Errorf("cap: %d, want %v, got %v", i, ErrDecoderSizeExceeded, err)
2199 }
2200 } else {
2201 if err != nil {
2202 t.Errorf("cap: %d, want %v, got %v", i, nil, err)
2203 continue
2204 }
2205 if len(got) != existinglen+i {
2206 t.Errorf("cap: %d, want output size %d, got %d", i, existinglen+i, len(got))
2207 }
2208 }
2209 }
2210 })
2211 }
2212 }
2213 })
2214 }
2215}
2216
2217func TestDecoderResetWithOptions(t *testing.T) {
2218 dec, err := NewReader(nil, WithDecoderConcurrency(1), WithDecoderLowmem(true))

Callers

nothing calls this directly

Calls 12

WithZeroFramesFunction · 0.85
WithWindowSizeFunction · 0.85
WithEncoderConcurrencyFunction · 0.85
WithDecodeAllCapLimitFunction · 0.85
WithDecoderConcurrencyFunction · 0.85
WithDecoderLowmemFunction · 0.85
WithDecoderMaxWindowFunction · 0.85
WithDecoderMaxMemoryFunction · 0.85
EncodeAllMethod · 0.80
DecodeAllMethod · 0.80
NewWriterFunction · 0.70
NewReaderFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…