1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 func TestNlitOutOfRange(t
*testing
.T
) {
17 // Trying to decode this bogus flate data, which has a Huffman table
18 // with nlit=288, should not panic.
19 io
.Copy(ioutil
.Discard
, NewReader(strings
.NewReader(
20 "\xfc\xfe\x36\xe7\x5e\x1c\xef\xb3\x55\x58\x77\xb6\x56\xb5\x43\xf4"+
21 "\x6f\xf2\xd2\xe6\x3d\x99\xa0\x85\x8c\x48\xeb\xf8\xda\x83\x04\x2a"+
22 "\x75\xc4\xf8\x0f\x12\x11\xb9\xb4\x4b\x09\xa0\xbe\x8b\x91\x4c")))
30 var testfiles
= []string{
31 // Digits is the digits of the irrational number e. Its decimal representation
32 // does not repeat, but there are only 10 posible digits, so it should be
33 // reasonably compressible.
34 digits
: "../testdata/e.txt",
35 // Twain is Project Gutenberg's edition of Mark Twain's classic English novel.
36 twain
: "../testdata/Mark.Twain-Tom.Sawyer.txt",
39 func benchmarkDecode(b
*testing
.B
, testfile
, level
, n
int) {
42 buf0
, err
:= ioutil
.ReadFile(testfiles
[testfile
])
47 b
.Fatalf("test file %q has no data", testfiles
[testfile
])
49 compressed
:= new(bytes
.Buffer
)
50 w
, err
:= NewWriter(compressed
, level
)
54 for i
:= 0; i
< n
; i
+= len(buf0
) {
58 io
.Copy(w
, bytes
.NewBuffer(buf0
))
61 buf1
:= compressed
.Bytes()
62 buf0
, compressed
, w
= nil, nil, nil
65 for i
:= 0; i
< b
.N
; i
++ {
66 io
.Copy(ioutil
.Discard
, NewReader(bytes
.NewBuffer(buf1
)))
70 // These short names are so that gofmt doesn't break the BenchmarkXxx function
71 // bodies below over multiple lines.
74 default_
= DefaultCompression
75 compress
= BestCompression
78 func BenchmarkDecodeDigitsSpeed1e4(b
*testing
.B
) { benchmarkDecode(b
, digits
, speed
, 1e4
) }
79 func BenchmarkDecodeDigitsSpeed1e5(b
*testing
.B
) { benchmarkDecode(b
, digits
, speed
, 1e5
) }
80 func BenchmarkDecodeDigitsSpeed1e6(b
*testing
.B
) { benchmarkDecode(b
, digits
, speed
, 1e6
) }
81 func BenchmarkDecodeDigitsDefault1e4(b
*testing
.B
) { benchmarkDecode(b
, digits
, default_
, 1e4
) }
82 func BenchmarkDecodeDigitsDefault1e5(b
*testing
.B
) { benchmarkDecode(b
, digits
, default_
, 1e5
) }
83 func BenchmarkDecodeDigitsDefault1e6(b
*testing
.B
) { benchmarkDecode(b
, digits
, default_
, 1e6
) }
84 func BenchmarkDecodeDigitsCompress1e4(b
*testing
.B
) { benchmarkDecode(b
, digits
, compress
, 1e4
) }
85 func BenchmarkDecodeDigitsCompress1e5(b
*testing
.B
) { benchmarkDecode(b
, digits
, compress
, 1e5
) }
86 func BenchmarkDecodeDigitsCompress1e6(b
*testing
.B
) { benchmarkDecode(b
, digits
, compress
, 1e6
) }
87 func BenchmarkDecodeTwainSpeed1e4(b
*testing
.B
) { benchmarkDecode(b
, twain
, speed
, 1e4
) }
88 func BenchmarkDecodeTwainSpeed1e5(b
*testing
.B
) { benchmarkDecode(b
, twain
, speed
, 1e5
) }
89 func BenchmarkDecodeTwainSpeed1e6(b
*testing
.B
) { benchmarkDecode(b
, twain
, speed
, 1e6
) }
90 func BenchmarkDecodeTwainDefault1e4(b
*testing
.B
) { benchmarkDecode(b
, twain
, default_
, 1e4
) }
91 func BenchmarkDecodeTwainDefault1e5(b
*testing
.B
) { benchmarkDecode(b
, twain
, default_
, 1e5
) }
92 func BenchmarkDecodeTwainDefault1e6(b
*testing
.B
) { benchmarkDecode(b
, twain
, default_
, 1e6
) }
93 func BenchmarkDecodeTwainCompress1e4(b
*testing
.B
) { benchmarkDecode(b
, twain
, compress
, 1e4
) }
94 func BenchmarkDecodeTwainCompress1e5(b
*testing
.B
) { benchmarkDecode(b
, twain
, compress
, 1e5
) }
95 func BenchmarkDecodeTwainCompress1e6(b
*testing
.B
) { benchmarkDecode(b
, twain
, compress
, 1e6
) }