github.com/hongwozai/go-src-1.4.3@v0.0.0-20191127132709-dc3fce3dbccb/src/compress/flate/flate_test.go (about) 1 // Copyright 2009 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. 4 5 // This test tests some internals of the flate package. 6 // The tests in package compress/gzip serve as the 7 // end-to-end test of the decompressor. 8 9 package flate 10 11 import ( 12 "bytes" 13 "testing" 14 ) 15 16 func TestUncompressedSource(t *testing.T) { 17 decoder := NewReader(bytes.NewReader([]byte{0x01, 0x01, 0x00, 0xfe, 0xff, 0x11})) 18 output := make([]byte, 1) 19 n, error := decoder.Read(output) 20 if n != 1 || error != nil { 21 t.Fatalf("decoder.Read() = %d, %v, want 1, nil", n, error) 22 } 23 if output[0] != 0x11 { 24 t.Errorf("output[0] = %x, want 0x11", output[0]) 25 } 26 } 27 28 // The following test should not panic. 29 func TestIssue5915(t *testing.T) { 30 bits := []int{4, 0, 0, 6, 4, 3, 2, 3, 3, 4, 4, 5, 0, 0, 0, 0, 5, 5, 6, 31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 6, 0, 11, 0, 8, 0, 6, 6, 10, 8} 33 h := new(huffmanDecoder) 34 ok := h.init(bits) 35 if ok == true { 36 t.Fatalf("Given sequence of bits is bad, and should not succeed.") 37 } 38 } 39 40 // The following test should not panic. 41 func TestIssue5962(t *testing.T) { 42 bits := []int{4, 0, 0, 6, 4, 3, 2, 3, 3, 4, 4, 5, 0, 0, 0, 0, 43 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11} 44 h := new(huffmanDecoder) 45 ok := h.init(bits) 46 if ok == true { 47 t.Fatalf("Given sequence of bits is bad, and should not succeed.") 48 } 49 } 50 51 // The following test should not panic. 52 func TestIssue6255(t *testing.T) { 53 bits1 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11} 54 bits2 := []int{11, 13} 55 h := new(huffmanDecoder) 56 if !h.init(bits1) { 57 t.Fatalf("Given sequence of bits is good and should succeed.") 58 } 59 if h.init(bits2) { 60 t.Fatalf("Given sequence of bits is bad and should not succeed.") 61 } 62 }