|
|
@@ -3,9 +3,9 @@
|
|
|
package lz4_test
|
|
|
|
|
|
import (
|
|
|
+ "bytes"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
- "reflect"
|
|
|
"testing"
|
|
|
|
|
|
"github.com/pierrec/lz4"
|
|
|
@@ -26,12 +26,13 @@ var rawFiles = []testcase{
|
|
|
{"testdata/pi.txt", true, nil},
|
|
|
{"testdata/random.data", false, nil},
|
|
|
{"testdata/repeat.txt", true, nil},
|
|
|
+ {"testdata/pg1661.txt", true, nil},
|
|
|
}
|
|
|
|
|
|
func TestCompressUncompressBlock(t *testing.T) {
|
|
|
type compressor func(s, d []byte) (int, error)
|
|
|
|
|
|
- run := func(tc testcase, compress compressor) int {
|
|
|
+ run := func(t *testing.T, tc testcase, compress compressor) int {
|
|
|
t.Helper()
|
|
|
src := tc.src
|
|
|
|
|
|
@@ -59,10 +60,25 @@ func TestCompressUncompressBlock(t *testing.T) {
|
|
|
n, err = lz4.UncompressBlock(zbuf, buf)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
+ } else if n < 0 || n > len(buf) {
|
|
|
+ t.Fatalf("returned written bytes > len(buf): n=%d available=%d", n, len(buf))
|
|
|
+ } else if n != len(src) {
|
|
|
+ t.Errorf("expected to decompress into %d bytes got %d", len(src), n)
|
|
|
}
|
|
|
+
|
|
|
buf = buf[:n]
|
|
|
- if !reflect.DeepEqual(src, buf) {
|
|
|
- t.Error("uncompressed compressed data not matching initial input")
|
|
|
+ if !bytes.Equal(src, buf) {
|
|
|
+ var c int
|
|
|
+ for i, b := range buf {
|
|
|
+ if c > 10 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if src[i] != b {
|
|
|
+ t.Errorf("%d: exp(%x) != got(%x)", i, src[i], buf[i])
|
|
|
+ c++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ t.Fatal("uncompressed compressed data not matching initial input")
|
|
|
return 0
|
|
|
}
|
|
|
|
|
|
@@ -80,20 +96,22 @@ func TestCompressUncompressBlock(t *testing.T) {
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
tc := tc
|
|
|
t.Run(tc.file, func(t *testing.T) {
|
|
|
- t.Parallel()
|
|
|
- n = run(tc, func(src, dst []byte) (int, error) {
|
|
|
+ // t.Parallel()
|
|
|
+ n = run(t, tc, func(src, dst []byte) (int, error) {
|
|
|
var ht [1 << 16]int
|
|
|
return lz4.CompressBlock(src, dst, ht[:])
|
|
|
})
|
|
|
})
|
|
|
t.Run(fmt.Sprintf("%s HC", tc.file), func(t *testing.T) {
|
|
|
- t.Parallel()
|
|
|
- nhc = run(tc, func(src, dst []byte) (int, error) {
|
|
|
+ // t.Parallel()
|
|
|
+ nhc = run(t, tc, func(src, dst []byte) (int, error) {
|
|
|
return lz4.CompressBlockHC(src, dst, -1)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
- fmt.Printf("%-40s: %8d / %8d / %8d\n", tc.file, n, nhc, len(src))
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Logf("%-40s: %8d / %8d / %8d\n", tc.file, n, nhc, len(src))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|