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

Function TestCompressRegression

huff0/compress_test.go:93–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestCompressRegression(t *testing.T) {
94 // Match the fuzz function
95 var testInput = func(t *testing.T, data []byte) int {
96 var enc Scratch
97 enc.WantLogLess = 5
98 comp, _, err := Compress1X(data, &enc)
99 if err == ErrIncompressible || err == ErrUseRLE || err == ErrTooBig {
100 return 0
101 }
102 if err != nil {
103 panic(err)
104 }
105 if len(comp) >= len(data)-len(data)>>enc.WantLogLess {
106 panic(fmt.Errorf("too large output provided. got %d, but should be < %d", len(comp), len(data)-len(data)>>enc.WantLogLess))
107 }
108
109 dec, remain, err := ReadTable(comp, nil)
110 if err != nil {
111 panic(err)
112 }
113 out, err := dec.Decompress1X(remain)
114 if err != nil {
115 t.Error(err)
116 }
117 if !bytes.Equal(out, data) {
118 t.Error("decompression 1x mismatch")
119 }
120 // Reuse as 4X
121 enc.Reuse = ReusePolicyAllow
122 comp, reUsed, err := Compress4X(data, &enc)
123 if err == ErrIncompressible || err == ErrUseRLE || err == ErrTooBig {
124 return 0
125 }
126 if err != nil {
127 panic(err)
128 }
129 if len(comp) >= len(data)-len(data)>>enc.WantLogLess {
130 panic(fmt.Errorf("too large output provided. got %d, but should be < %d", len(comp), len(data)-len(data)>>enc.WantLogLess))
131 }
132
133 remain = comp
134 if !reUsed {
135 dec, remain, err = ReadTable(comp, dec)
136 if err != nil {
137 panic(err)
138 }
139 }
140 out, err = dec.Decompress4X(remain, len(data))
141 if err != nil {
142 t.Error(err)
143 }
144 if !bytes.Equal(out, data) {
145 t.Error("decompression 4x with reuse mismatch")
146 }
147
148 enc.Reuse = ReusePolicyNone
149 comp, reUsed, err = Compress4X(data, &enc)
150 if err == ErrIncompressible || err == ErrUseRLE || err == ErrTooBig {

Callers

nothing calls this directly

Calls 7

Compress1XFunction · 0.85
ReadTableFunction · 0.85
Compress4XFunction · 0.85
FatalMethod · 0.80
Decompress1XMethod · 0.45
ErrorMethod · 0.45
Decompress4XMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…