mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Consistently use tt to name a *testing.T
This commit is contained in:
1 parent
8357a74a8c
commit
59b9dee61a
8 files changed
+150
-150
No files matched your search
+12
-12
@@ -41,7 +41,7 @@ func clone(b []byte) []byte {
|
||||
return append([]byte(nil), b...)
|
||||
}
|
||||
|
||||
func Test(t *testing.T,
|
||||
func Test(tt *testing.T,
|
||||
smallestValidMaxEncodedLen int,
|
||||
cut func(io.Writer, []byte, int) (int, int, error),
|
||||
newReader func(io.Reader) (io.ReadCloser, error),
|
||||
@@ -50,12 +50,12 @@ func Test(t *testing.T,
|
||||
for _, filename := range filenames {
|
||||
full, err := ioutil.ReadFile("../../test/data/" + filename)
|
||||
if err != nil {
|
||||
t.Errorf("f=%q: ReadFile: %v", filename, err)
|
||||
tt.Errorf("f=%q: ReadFile: %v", filename, err)
|
||||
continue
|
||||
}
|
||||
fullDecodedLen, err := calculateDecodedLen(full, newReader)
|
||||
if err != nil {
|
||||
t.Errorf("f=%q: calculateDecodedLen: %v", filename, err)
|
||||
tt.Errorf("f=%q: calculateDecodedLen: %v", filename, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -94,16 +94,16 @@ func Test(t *testing.T,
|
||||
encoded := clone(full)
|
||||
encLen, decLen, err := cut(w0, encoded, maxEncodedLen)
|
||||
if err != nil {
|
||||
t.Errorf("f=%q, mEL=%d: cut: %v", filename, maxEncodedLen, err)
|
||||
tt.Errorf("f=%q, mEL=%d: cut: %v", filename, maxEncodedLen, err)
|
||||
continue
|
||||
}
|
||||
if encLen > maxEncodedLen {
|
||||
t.Errorf("f=%q, mEL=%d: encLen vs max: got %d, want <= %d",
|
||||
tt.Errorf("f=%q, mEL=%d: encLen vs max: got %d, want <= %d",
|
||||
filename, maxEncodedLen, encLen, maxEncodedLen)
|
||||
continue
|
||||
}
|
||||
if encLen > len(encoded) {
|
||||
t.Errorf("f=%q, mEL=%d: encLen vs len: got %d, want <= %d",
|
||||
tt.Errorf("f=%q, mEL=%d: encLen vs len: got %d, want <= %d",
|
||||
filename, maxEncodedLen, encLen, len(encoded))
|
||||
continue
|
||||
}
|
||||
@@ -111,31 +111,31 @@ func Test(t *testing.T,
|
||||
w1 := &bytes.Buffer{}
|
||||
r, err := newReader(bytes.NewReader(encoded[:encLen]))
|
||||
if err != nil {
|
||||
t.Errorf("f=%q, mEL=%d: newReader: %v", filename, maxEncodedLen, err)
|
||||
tt.Errorf("f=%q, mEL=%d: newReader: %v", filename, maxEncodedLen, err)
|
||||
continue
|
||||
}
|
||||
if n, err := io.Copy(w1, r); err != nil {
|
||||
t.Errorf("f=%q, mEL=%d: io.Copy: %v", filename, maxEncodedLen, err)
|
||||
tt.Errorf("f=%q, mEL=%d: io.Copy: %v", filename, maxEncodedLen, err)
|
||||
continue
|
||||
} else if n != int64(decLen) {
|
||||
t.Errorf("f=%q, mEL=%d: io.Copy: got %d, want %d",
|
||||
tt.Errorf("f=%q, mEL=%d: io.Copy: got %d, want %d",
|
||||
filename, maxEncodedLen, n, decLen)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(w0.Bytes(), w1.Bytes()) {
|
||||
t.Errorf("f=%q, mEL=%d: decoded bytes were not equal", filename, maxEncodedLen)
|
||||
tt.Errorf("f=%q, mEL=%d: decoded bytes were not equal", filename, maxEncodedLen)
|
||||
continue
|
||||
}
|
||||
|
||||
if (maxEncodedLen == len(encoded)) && (int64(decLen) != fullDecodedLen) {
|
||||
t.Errorf("f=%q, mEL=%d: full decode: got %d, want %d",
|
||||
tt.Errorf("f=%q, mEL=%d: full decode: got %d, want %d",
|
||||
filename, maxEncodedLen, decLen, fullDecodedLen)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := r.Close(); err != nil {
|
||||
t.Errorf("f=%q, mEL=%d: r.Close: %v", filename, maxEncodedLen, err)
|
||||
tt.Errorf("f=%q, mEL=%d: r.Close: %v", filename, maxEncodedLen, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ const (
|
||||
uncompressedMore = "More!\n"
|
||||
)
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
func TestRoundTrip(tt *testing.T) {
|
||||
if !cgoEnabled {
|
||||
t.Skip("cgo is not enabled")
|
||||
tt.Skip("cgo is not enabled")
|
||||
}
|
||||
|
||||
wr := &WriterRecycler{}
|
||||
@@ -59,16 +59,16 @@ func TestRoundTrip(t *testing.T) {
|
||||
w.Reset(buf, nil, 0)
|
||||
if _, err := w.Write([]byte(uncompressedMore)); err != nil {
|
||||
w.Close()
|
||||
t.Fatalf("i=%d: Write: %v", i, err)
|
||||
tt.Fatalf("i=%d: Write: %v", i, err)
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("i=%d: Close: %v", i, err)
|
||||
tt.Fatalf("i=%d: Close: %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
compressed := buf.String()
|
||||
if compressed != compressedMore {
|
||||
t.Fatalf("i=%d: compressed\ngot % 02x\nwant % 02x", i, compressed, compressedMore)
|
||||
tt.Fatalf("i=%d: compressed\ngot % 02x\nwant % 02x", i, compressed, compressedMore)
|
||||
}
|
||||
|
||||
// Uncompress.
|
||||
@@ -77,14 +77,14 @@ func TestRoundTrip(t *testing.T) {
|
||||
gotBytes, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
r.Close()
|
||||
t.Fatalf("i=%d: ReadAll: %v", i, err)
|
||||
tt.Fatalf("i=%d: ReadAll: %v", i, err)
|
||||
}
|
||||
if got, want := string(gotBytes), uncompressedMore; got != want {
|
||||
r.Close()
|
||||
t.Fatalf("i=%d:\ngot %q\nwant %q", i, got, want)
|
||||
tt.Fatalf("i=%d:\ngot %q\nwant %q", i, got, want)
|
||||
}
|
||||
if err := r.Close(); err != nil {
|
||||
t.Fatalf("i=%d: Close: %v", i, err)
|
||||
tt.Fatalf("i=%d: Close: %v", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -47,39 +47,39 @@ func makePure() resetReadCloser {
|
||||
return r.(resetReadCloser)
|
||||
}
|
||||
|
||||
func testReadAll(t *testing.T, r resetReadCloser, src io.Reader, dict []byte, want string) {
|
||||
t.Helper()
|
||||
func testReadAll(tt *testing.T, r resetReadCloser, src io.Reader, dict []byte, want string) {
|
||||
tt.Helper()
|
||||
if !cgoEnabled {
|
||||
t.Skip("cgo is not enabled")
|
||||
tt.Skip("cgo is not enabled")
|
||||
}
|
||||
|
||||
if err := r.Reset(src, dict); err != nil {
|
||||
t.Fatalf("Reset: %v", err)
|
||||
tt.Fatalf("Reset: %v", err)
|
||||
}
|
||||
|
||||
got, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll: %v", err)
|
||||
tt.Fatalf("ReadAll: %v", err)
|
||||
}
|
||||
|
||||
if err := r.Close(); err != nil {
|
||||
t.Fatalf("Close: %v", err)
|
||||
tt.Fatalf("Close: %v", err)
|
||||
}
|
||||
|
||||
if string(got) != want {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
tt.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func testReader(t *testing.T, r resetReadCloser) {
|
||||
testReadAll(t, r, strings.NewReader(compressedMore), nil, "More!\n")
|
||||
testReadAll(t, r, strings.NewReader(compressedSheep), dictSheep, "Two sheep.\n")
|
||||
testReadAll(t, r, strings.NewReader(compressedMore), nil, "More!\n")
|
||||
testReadAll(t, r, strings.NewReader(compressedSheep), dictSheep, "Two sheep.\n")
|
||||
func testReader(tt *testing.T, r resetReadCloser) {
|
||||
testReadAll(tt, r, strings.NewReader(compressedMore), nil, "More!\n")
|
||||
testReadAll(tt, r, strings.NewReader(compressedSheep), dictSheep, "Two sheep.\n")
|
||||
testReadAll(tt, r, strings.NewReader(compressedMore), nil, "More!\n")
|
||||
testReadAll(tt, r, strings.NewReader(compressedSheep), dictSheep, "Two sheep.\n")
|
||||
}
|
||||
|
||||
func TestCgo(t *testing.T) { testReader(t, &Reader{}) }
|
||||
func TestPure(t *testing.T) { testReader(t, makePure()) }
|
||||
func TestCgo(tt *testing.T) { testReader(tt, &Reader{}) }
|
||||
func TestPure(tt *testing.T) { testReader(tt, makePure()) }
|
||||
|
||||
func benchmarkReader(b *testing.B, r resetReadCloser) {
|
||||
if !cgoEnabled {
|
||||
|
||||
@@ -42,9 +42,9 @@ const (
|
||||
uncompressedMore = "More!\n"
|
||||
)
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
func TestRoundTrip(tt *testing.T) {
|
||||
if !cgoEnabled {
|
||||
t.Skip("cgo is not enabled")
|
||||
tt.Skip("cgo is not enabled")
|
||||
}
|
||||
|
||||
wr := &WriterRecycler{}
|
||||
@@ -65,16 +65,16 @@ func TestRoundTrip(t *testing.T) {
|
||||
w.Reset(buf, nil, 0)
|
||||
if _, err := w.Write([]byte(uncompressedMore)); err != nil {
|
||||
w.Close()
|
||||
t.Fatalf("i=%d: Write: %v", i, err)
|
||||
tt.Fatalf("i=%d: Write: %v", i, err)
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("i=%d: Close: %v", i, err)
|
||||
tt.Fatalf("i=%d: Close: %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
compressed := buf.String()
|
||||
if (compressed != compressedMore0) && (compressed != compressedMore1) {
|
||||
t.Fatalf("i=%d: compressed\ngot % 02x\nwant % 02x\nor % 02x",
|
||||
tt.Fatalf("i=%d: compressed\ngot % 02x\nwant % 02x\nor % 02x",
|
||||
i, compressed, compressedMore0, compressedMore1)
|
||||
}
|
||||
|
||||
@@ -84,14 +84,14 @@ func TestRoundTrip(t *testing.T) {
|
||||
gotBytes, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
r.Close()
|
||||
t.Fatalf("i=%d: ReadAll: %v", i, err)
|
||||
tt.Fatalf("i=%d: ReadAll: %v", i, err)
|
||||
}
|
||||
if got, want := string(gotBytes), uncompressedMore; got != want {
|
||||
r.Close()
|
||||
t.Fatalf("i=%d:\ngot %q\nwant %q", i, got, want)
|
||||
tt.Fatalf("i=%d:\ngot %q\nwant %q", i, got, want)
|
||||
}
|
||||
if err := r.Close(); err != nil {
|
||||
t.Fatalf("i=%d: Close: %v", i, err)
|
||||
tt.Fatalf("i=%d: Close: %v", i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
"github.com/google/wuffs/internal/testcut"
|
||||
)
|
||||
|
||||
func TestCut(t *testing.T) {
|
||||
testcut.Test(t, SmallestValidMaxEncodedLen, Cut, newReader, []string{
|
||||
func TestCut(tt *testing.T) {
|
||||
testcut.Test(tt, SmallestValidMaxEncodedLen, Cut, newReader, []string{
|
||||
"artificial/deflate-backref-crosses-blocks.deflate",
|
||||
"artificial/deflate-distance-32768.deflate",
|
||||
"romeo.txt.deflate",
|
||||
@@ -50,7 +50,7 @@ func decodeFlate(src []byte) string {
|
||||
return string(dst)
|
||||
}
|
||||
|
||||
func TestHuffmanDecode(t *testing.T) {
|
||||
func TestHuffmanDecode(tt *testing.T) {
|
||||
// This exercises the "ABCDEFGH" example from RFC 1951 section 3.2.2,
|
||||
// discussed in the "type huffman" doc comment.
|
||||
|
||||
@@ -116,7 +116,7 @@ func TestHuffmanDecode(t *testing.T) {
|
||||
}
|
||||
|
||||
if got, want := string(decoded), src; got != want {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
tt.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,28 +140,28 @@ const (
|
||||
"\x4e\x4c\xef\x37\xf5\x44\x63\x9f\xdc\xfe\x00"
|
||||
)
|
||||
|
||||
func TestReplaceHuffmanWithStored(t *testing.T) {
|
||||
func TestReplaceHuffmanWithStored(tt *testing.T) {
|
||||
const dec = degenerateHuffmanDec
|
||||
const enc = degenerateHuffmanEnc
|
||||
if (len(dec) != 64) || (len(enc) != 59) {
|
||||
panic("inconsistent const string lengths")
|
||||
}
|
||||
if got, want := decodeFlate([]byte(enc)), dec; got != want {
|
||||
t.Fatalf("before Cut: got %q, want %q", got, want)
|
||||
tt.Fatalf("before Cut: got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
for i := 4; i <= 59; i += 5 {
|
||||
b := []byte(enc)
|
||||
encLen, decLen, err := Cut(nil, b, i)
|
||||
if err != nil {
|
||||
t.Errorf("i=%d: %v", i, err)
|
||||
tt.Errorf("i=%d: %v", i, err)
|
||||
continue
|
||||
}
|
||||
if encLen < 1 {
|
||||
t.Errorf("i=%d: encLen: got %d, want >= 1", i, encLen)
|
||||
tt.Errorf("i=%d: encLen: got %d, want >= 1", i, encLen)
|
||||
continue
|
||||
} else if encLen > len(enc) {
|
||||
t.Errorf("i=%d: encLen: got %d, want <= %d", i, encLen, len(enc))
|
||||
tt.Errorf("i=%d: encLen: got %d, want <= %d", i, encLen, len(enc))
|
||||
continue
|
||||
}
|
||||
// If we can make some progress (decLen > 0), even if the input uses a
|
||||
@@ -170,15 +170,15 @@ func TestReplaceHuffmanWithStored(t *testing.T) {
|
||||
// Regardless of whether the cut form uses a Huffman or Stored block,
|
||||
// we should be able to produce at least i-5 bytes of decoded output.
|
||||
if (decLen > 0) && (i > 5) && (decLen < i-5) {
|
||||
t.Errorf("i=%d: decLen: got %d, want >= %d", i, decLen, i-5)
|
||||
tt.Errorf("i=%d: decLen: got %d, want >= %d", i, decLen, i-5)
|
||||
continue
|
||||
} else if decLen > len(dec) {
|
||||
t.Errorf("i=%d: decLen: got %d, want <= %d", i, decLen, len(dec))
|
||||
tt.Errorf("i=%d: decLen: got %d, want <= %d", i, decLen, len(dec))
|
||||
continue
|
||||
}
|
||||
|
||||
if got, want := decodeFlate(b[:encLen]), dec[:decLen]; got != want {
|
||||
t.Errorf("i=%d: after Cut: got %q, want %q", i, got, want)
|
||||
tt.Errorf("i=%d: after Cut: got %q, want %q", i, got, want)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -199,13 +199,13 @@ func TestReplaceHuffmanWithStored(t *testing.T) {
|
||||
}
|
||||
|
||||
if got != want {
|
||||
t.Errorf("i=%d: block type: got %d, want %d", i, got, want)
|
||||
tt.Errorf("i=%d: block type: got %d, want %d", i, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDegenerateHuffmanUnused(t *testing.T) {
|
||||
func TestDegenerateHuffmanUnused(tt *testing.T) {
|
||||
const dec = degenerateHuffmanDec
|
||||
const enc = degenerateHuffmanEnc
|
||||
|
||||
@@ -218,14 +218,14 @@ func TestDegenerateHuffmanUnused(t *testing.T) {
|
||||
b := []byte(enc)
|
||||
encLen, decLen, err := Cut(nil, b, len(enc)-1)
|
||||
if err != nil {
|
||||
t.Fatalf("Cut: %v", err)
|
||||
tt.Fatalf("Cut: %v", err)
|
||||
} else if encLen != len(enc)-1 {
|
||||
t.Fatalf("encLen: got %d, want %d", encLen, len(enc)-1)
|
||||
tt.Fatalf("encLen: got %d, want %d", encLen, len(enc)-1)
|
||||
} else if decLen != len(dec)-n {
|
||||
t.Fatalf("decLen: got %d, want %d", decLen, len(dec)-n)
|
||||
tt.Fatalf("decLen: got %d, want %d", decLen, len(dec)-n)
|
||||
}
|
||||
|
||||
if got, want := decodeFlate(b[:encLen]), dec[:decLen]; got != want {
|
||||
t.Fatalf("after Cut: got %q, want %q", got, want)
|
||||
tt.Fatalf("after Cut: got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
+63
-63
@@ -121,79 +121,79 @@ const writerWantILAStartCPageSize128 = "" +
|
||||
"00000080 52 72 72 53 73 41 61 61 42 62 62 62 43 63 63 63 |RrrSsAaaBbbbCccc|\n" +
|
||||
"00000090 63 63 63 63 63 63 31 32 |cccccc12|\n"
|
||||
|
||||
func TestWriterILAEndEmpty(t *testing.T) {
|
||||
func TestWriterILAEndEmpty(tt *testing.T) {
|
||||
if err := testWriter(IndexLocationAtEnd, nil, 0, true); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAStartEmpty(t *testing.T) {
|
||||
func TestWriterILAStartEmpty(tt *testing.T) {
|
||||
tempFile := &bytes.Buffer{}
|
||||
if err := testWriter(IndexLocationAtStart, tempFile, 0, true); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAEndNoTempFile(t *testing.T) {
|
||||
func TestWriterILAEndNoTempFile(tt *testing.T) {
|
||||
if err := testWriter(IndexLocationAtEnd, nil, 0, false); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAEndMemTempFile(t *testing.T) {
|
||||
func TestWriterILAEndMemTempFile(tt *testing.T) {
|
||||
tempFile := &bytes.Buffer{}
|
||||
if err := testWriter(IndexLocationAtEnd, tempFile, 0, false); err == nil {
|
||||
t.Fatal("err: got nil, want non-nil")
|
||||
tt.Fatal("err: got nil, want non-nil")
|
||||
} else if !strings.HasPrefix(err.Error(), "rac: IndexLocationAtEnd requires") {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAStartNoTempFile(t *testing.T) {
|
||||
func TestWriterILAStartNoTempFile(tt *testing.T) {
|
||||
if err := testWriter(IndexLocationAtStart, nil, 0, false); err == nil {
|
||||
t.Fatal("err: got nil, want non-nil")
|
||||
tt.Fatal("err: got nil, want non-nil")
|
||||
} else if !strings.HasPrefix(err.Error(), "rac: IndexLocationAtStart requires") {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAStartMemTempFile(t *testing.T) {
|
||||
func TestWriterILAStartMemTempFile(tt *testing.T) {
|
||||
tempFile := &bytes.Buffer{}
|
||||
if err := testWriter(IndexLocationAtStart, tempFile, 0, false); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAStartRealTempFile(t *testing.T) {
|
||||
func TestWriterILAStartRealTempFile(tt *testing.T) {
|
||||
f, err := ioutil.TempFile("", "rac_test")
|
||||
if err != nil {
|
||||
t.Fatalf("TempFile: %v", err)
|
||||
tt.Fatalf("TempFile: %v", err)
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
defer f.Close()
|
||||
|
||||
if err := testWriter(IndexLocationAtStart, f, 0, false); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAEndCPageSize8(t *testing.T) {
|
||||
func TestWriterILAEndCPageSize8(tt *testing.T) {
|
||||
if err := testWriter(IndexLocationAtEnd, nil, 8, false); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAStartCPageSize4(t *testing.T) {
|
||||
func TestWriterILAStartCPageSize4(tt *testing.T) {
|
||||
tempFile := &bytes.Buffer{}
|
||||
if err := testWriter(IndexLocationAtStart, tempFile, 4, false); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterILAStartCPageSize128(t *testing.T) {
|
||||
func TestWriterILAStartCPageSize128(tt *testing.T) {
|
||||
tempFile := &bytes.Buffer{}
|
||||
if err := testWriter(IndexLocationAtStart, tempFile, 128, false); err != nil {
|
||||
t.Fatal(err)
|
||||
tt.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func testWriter(iloc IndexLocation, tempFile io.ReadWriter, cPageSize uint64, em
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestMultiLevelIndex(t *testing.T) {
|
||||
func TestMultiLevelIndex(tt *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
w := &ChunkWriter{
|
||||
Writer: buf,
|
||||
@@ -293,12 +293,12 @@ func TestMultiLevelIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("Close: %v", err)
|
||||
tt.Fatalf("Close: %v", err)
|
||||
}
|
||||
|
||||
encoded := buf.Bytes()
|
||||
if got, want := len(encoded), 0x13E2; got != want {
|
||||
t.Fatalf("len(encoded): got 0x%X, want 0x%X", got, want)
|
||||
tt.Fatalf("len(encoded): got 0x%X, want 0x%X", got, want)
|
||||
}
|
||||
|
||||
gotHexDump := hex.Dump(encoded)
|
||||
@@ -352,7 +352,7 @@ func TestMultiLevelIndex(t *testing.T) {
|
||||
"000013e0 30 33 |03|\n"
|
||||
|
||||
if gotHexDump != wantHexDump {
|
||||
t.Fatalf("\ngot:\n%s\nwant:\n%s", gotHexDump, wantHexDump)
|
||||
tt.Fatalf("\ngot:\n%s\nwant:\n%s", gotHexDump, wantHexDump)
|
||||
}
|
||||
|
||||
r := &ChunkReader{
|
||||
@@ -365,7 +365,7 @@ func TestMultiLevelIndex(t *testing.T) {
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
t.Fatalf("NextChunk: %v", err)
|
||||
tt.Fatalf("NextChunk: %v", err)
|
||||
}
|
||||
p0, p1 := c.CPrimary[0], c.CPrimary[1]
|
||||
if (0 <= p0) && (p0 <= p1) && (p1 <= int64(len(encoded))) {
|
||||
@@ -377,11 +377,11 @@ func TestMultiLevelIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if !bytes.Equal(gotPrimaries, primaries) {
|
||||
t.Fatalf("\ngot:\n%s\nwant:\n%s", gotPrimaries, primaries)
|
||||
tt.Fatalf("\ngot:\n%s\nwant:\n%s", gotPrimaries, primaries)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriter1000Chunks(t *testing.T) {
|
||||
func TestWriter1000Chunks(tt *testing.T) {
|
||||
loop:
|
||||
for i := 0; i < 2; i++ {
|
||||
buf := &bytes.Buffer{}
|
||||
@@ -403,7 +403,7 @@ loop:
|
||||
}
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
t.Errorf("i=%d: Close: %v", i, err)
|
||||
tt.Errorf("i=%d: Close: %v", i, err)
|
||||
continue loop
|
||||
}
|
||||
|
||||
@@ -415,12 +415,12 @@ loop:
|
||||
for n := 0; ; n++ {
|
||||
if _, err := r.NextChunk(); err == io.EOF {
|
||||
if n != 1000 {
|
||||
t.Errorf("i=%d: number of chunks: got %d, want %d", i, n, 1000)
|
||||
tt.Errorf("i=%d: number of chunks: got %d, want %d", i, n, 1000)
|
||||
continue loop
|
||||
}
|
||||
break
|
||||
} else if err != nil {
|
||||
t.Errorf("i=%d: NextChunk: %v", i, err)
|
||||
tt.Errorf("i=%d: NextChunk: %v", i, err)
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ func printChunks(chunks []Chunk) string {
|
||||
return strings.Join(ss, "\n")
|
||||
}
|
||||
|
||||
func TestChunkReader(t *testing.T) {
|
||||
func TestChunkReader(tt *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
compressed []byte
|
||||
@@ -482,10 +482,10 @@ loop:
|
||||
}
|
||||
|
||||
if gotDecompressedSize, err := r.DecompressedSize(); err != nil {
|
||||
t.Errorf("%q test case: %v", tc.name, err)
|
||||
tt.Errorf("%q test case: %v", tc.name, err)
|
||||
continue loop
|
||||
} else if gotDecompressedSize != wantDecompressedSize {
|
||||
t.Errorf("%q test case: DecompressedSize: got %d, want %d",
|
||||
tt.Errorf("%q test case: DecompressedSize: got %d, want %d",
|
||||
tc.name, gotDecompressedSize, wantDecompressedSize)
|
||||
continue loop
|
||||
}
|
||||
@@ -498,12 +498,12 @@ loop:
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
t.Errorf("%q test case: NextChunk: %v", tc.name, err)
|
||||
tt.Errorf("%q test case: NextChunk: %v", tc.name, err)
|
||||
continue loop
|
||||
}
|
||||
|
||||
if c.DRange[0] != prevDRange1 {
|
||||
t.Errorf("%q test case: NextChunk: DRange[0]: got %d, want %d",
|
||||
tt.Errorf("%q test case: NextChunk: DRange[0]: got %d, want %d",
|
||||
tc.name, c.DRange[0], prevDRange1)
|
||||
continue loop
|
||||
}
|
||||
@@ -519,41 +519,41 @@ loop:
|
||||
|
||||
if tc.name == "Empty" {
|
||||
if len(gotChunks) != 0 {
|
||||
t.Errorf("%q test case: NextChunk: got non-empty, want empty", tc.name)
|
||||
tt.Errorf("%q test case: NextChunk: got non-empty, want empty", tc.name)
|
||||
}
|
||||
continue loop
|
||||
}
|
||||
|
||||
gotDescription := description.String()
|
||||
if gotDescription != wantDescription {
|
||||
t.Errorf("%q test case: NextChunk:\n got\n%s\n which is\n%s\n want\n%s",
|
||||
tt.Errorf("%q test case: NextChunk:\n got\n%s\n which is\n%s\n want\n%s",
|
||||
tc.name, printChunks(gotChunks), gotDescription, wantDescription)
|
||||
continue loop
|
||||
}
|
||||
|
||||
// NextChunk should return io.EOF.
|
||||
if _, err := r.NextChunk(); err != io.EOF {
|
||||
t.Errorf("%q test case: NextChunk: got %v, want io.EOF", tc.name, err)
|
||||
tt.Errorf("%q test case: NextChunk: got %v, want io.EOF", tc.name, err)
|
||||
continue loop
|
||||
}
|
||||
|
||||
if err := r.SeekToChunkContaining(0x30); err != nil {
|
||||
t.Errorf("%q test case: SeekToChunkContaining: %v", tc.name, err)
|
||||
tt.Errorf("%q test case: SeekToChunkContaining: %v", tc.name, err)
|
||||
continue loop
|
||||
}
|
||||
|
||||
// NextChunk should return the "Bb..." chunk.
|
||||
if c, err := r.NextChunk(); err != nil {
|
||||
t.Errorf("%q test case: NextChunk: %v", tc.name, err)
|
||||
tt.Errorf("%q test case: NextChunk: %v", tc.name, err)
|
||||
continue loop
|
||||
} else if got, want := snippet(c.CPrimary), "Bb..."; got != want {
|
||||
t.Errorf("%q test case: NextChunk: got %q, want %q", tc.name, got, want)
|
||||
tt.Errorf("%q test case: NextChunk: got %q, want %q", tc.name, got, want)
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReaderEmpty(t *testing.T) {
|
||||
func TestReaderEmpty(tt *testing.T) {
|
||||
encoded := undoHexDump(writerWantEmpty)
|
||||
r := &Reader{
|
||||
ReadSeeker: bytes.NewReader(encoded),
|
||||
@@ -562,24 +562,24 @@ func TestReaderEmpty(t *testing.T) {
|
||||
defer r.Close()
|
||||
got, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll: %v", err)
|
||||
tt.Fatalf("ReadAll: %v", err)
|
||||
}
|
||||
if len(got) != 0 {
|
||||
t.Fatalf("got %q, want %q", got, []byte(nil))
|
||||
tt.Fatalf("got %q, want %q", got, []byte(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestReaderZeroes(t *testing.T) {
|
||||
func TestReaderZeroes(tt *testing.T) {
|
||||
const dSize = 7
|
||||
buf := &bytes.Buffer{}
|
||||
w := &ChunkWriter{
|
||||
Writer: buf,
|
||||
}
|
||||
if err := w.AddChunk(dSize, CodecZeroes, nil, 0, 0); err != nil {
|
||||
t.Fatalf("AddChunk: %v", err)
|
||||
tt.Fatalf("AddChunk: %v", err)
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("Close: %v", err)
|
||||
tt.Fatalf("Close: %v", err)
|
||||
}
|
||||
encoded := buf.Bytes()
|
||||
r := &Reader{
|
||||
@@ -589,15 +589,15 @@ func TestReaderZeroes(t *testing.T) {
|
||||
defer r.Close()
|
||||
got, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll: %v", err)
|
||||
tt.Fatalf("ReadAll: %v", err)
|
||||
}
|
||||
want := make([]byte, dSize)
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
tt.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongCodec(t *testing.T) {
|
||||
func TestLongCodec(tt *testing.T) {
|
||||
const codec = Codec(0x80000000326F646D) // "mdo2" backwards, with a high bit.
|
||||
buf := &bytes.Buffer{}
|
||||
w := &ChunkWriter{
|
||||
@@ -606,13 +606,13 @@ func TestLongCodec(t *testing.T) {
|
||||
TempFile: &bytes.Buffer{},
|
||||
}
|
||||
if err := w.AddChunk(0x66, codec, []byte{0xAA, 0xBB}, 0, 0); err != nil {
|
||||
t.Fatalf("AddChunk: %v", err)
|
||||
tt.Fatalf("AddChunk: %v", err)
|
||||
}
|
||||
if err := w.AddChunk(0x77, codec, []byte{0xCC}, 0, 0); err != nil {
|
||||
t.Fatalf("AddChunk: %v", err)
|
||||
tt.Fatalf("AddChunk: %v", err)
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("Close: %v", err)
|
||||
tt.Fatalf("Close: %v", err)
|
||||
}
|
||||
|
||||
encoded := buf.Bytes()
|
||||
@@ -626,7 +626,7 @@ func TestLongCodec(t *testing.T) {
|
||||
"00000040 aa bb cc |...|\n"
|
||||
|
||||
if gotHexDump != wantHexDump {
|
||||
t.Fatalf("\ngot:\n%s\nwant:\n%s", gotHexDump, wantHexDump)
|
||||
tt.Fatalf("\ngot:\n%s\nwant:\n%s", gotHexDump, wantHexDump)
|
||||
}
|
||||
|
||||
r := &ChunkReader{
|
||||
@@ -636,18 +636,18 @@ func TestLongCodec(t *testing.T) {
|
||||
for i := 0; i < 2; i++ {
|
||||
c, err := r.NextChunk()
|
||||
if err != nil {
|
||||
t.Fatalf("i=%d: %v", i, err)
|
||||
tt.Fatalf("i=%d: %v", i, err)
|
||||
}
|
||||
if got, want := c.Codec, codec; got != want {
|
||||
t.Fatalf("i=%d: Codec: got 0x%X, want 0x%X", i, got, want)
|
||||
tt.Fatalf("i=%d: Codec: got 0x%X, want 0x%X", i, got, want)
|
||||
}
|
||||
}
|
||||
if _, err := r.NextChunk(); err != io.EOF {
|
||||
t.Fatalf("got %v, want %v", err, io.EOF)
|
||||
tt.Fatalf("got %v, want %v", err, io.EOF)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindChunkContaining(t *testing.T) {
|
||||
func TestFindChunkContaining(tt *testing.T) {
|
||||
rng := rand.New(rand.NewSource(1))
|
||||
arity, dptrs := 0, [256]int64{}
|
||||
|
||||
@@ -694,7 +694,7 @@ func TestFindChunkContaining(t *testing.T) {
|
||||
node[5] = uint8(checksum >> 8)
|
||||
|
||||
if !node.valid() {
|
||||
t.Fatalf("i=%d: invalid node", i)
|
||||
tt.Fatalf("i=%d: invalid node", i)
|
||||
}
|
||||
|
||||
for k := 0; k < 100; k++ {
|
||||
@@ -702,7 +702,7 @@ func TestFindChunkContaining(t *testing.T) {
|
||||
got := node.findChunkContaining(dptr, 0)
|
||||
want := simpleFCC(dptr)
|
||||
if got != want {
|
||||
t.Fatalf("i=%d, k=%d: got %d, want %d", i, k, got, want)
|
||||
tt.Fatalf("i=%d, k=%d: got %d, want %d", i, k, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -89,20 +89,20 @@ func racDecompress(compressed []byte) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func testReader(t *testing.T, decoded string, encoded string) {
|
||||
func testReader(tt *testing.T, decoded string, encoded string) {
|
||||
g, err := racDecompress([]byte(encoded))
|
||||
if err != nil {
|
||||
t.Fatalf("racDecompress: %v", err)
|
||||
tt.Fatalf("racDecompress: %v", err)
|
||||
}
|
||||
if got, want := string(g), decoded; got != want {
|
||||
t.Fatalf("got:\n%s\nwant:\n%s", got, want)
|
||||
tt.Fatalf("got:\n%s\nwant:\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReaderSansDictionary(t *testing.T) { testReader(t, decodedMore, encodedMore) }
|
||||
func TestReaderWithDictionary(t *testing.T) { testReader(t, decodedSheep, encodedSheep) }
|
||||
func TestReaderSansDictionary(tt *testing.T) { testReader(tt, decodedMore, encodedMore) }
|
||||
func TestReaderWithDictionary(tt *testing.T) { testReader(tt, decodedSheep, encodedSheep) }
|
||||
|
||||
func TestReaderConcatenation(t *testing.T) {
|
||||
func TestReaderConcatenation(tt *testing.T) {
|
||||
// Create a RAC file whose decoding is the concatenation of two other RAC
|
||||
// file's decoding. The resultant RAC file's contents (the encoded form) is
|
||||
// the concatenation of the two RAC files, plus a new root node.
|
||||
@@ -171,13 +171,13 @@ func TestReaderConcatenation(t *testing.T) {
|
||||
buf[0x05] = byte(checksum >> 8)
|
||||
|
||||
// Test the concatenation.
|
||||
testReader(t,
|
||||
testReader(tt,
|
||||
decodedSheep+decodedMore,
|
||||
encodedSheep+encodedMore+string(buf[:]),
|
||||
)
|
||||
}
|
||||
|
||||
func TestZeroedBytes(t *testing.T) {
|
||||
func TestZeroedBytes(tt *testing.T) {
|
||||
original := make([]byte, 32)
|
||||
original[0] = 'a'
|
||||
original[1] = 'b'
|
||||
@@ -195,7 +195,7 @@ func TestZeroedBytes(t *testing.T) {
|
||||
|
||||
compressed, err := racCompress(original, cChunkSize, dChunkSize, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("i=%d: racCompress: %v", i, err)
|
||||
tt.Fatalf("i=%d: racCompress: %v", i, err)
|
||||
}
|
||||
|
||||
r := &rac.Reader{
|
||||
@@ -212,22 +212,22 @@ func TestZeroedBytes(t *testing.T) {
|
||||
}
|
||||
|
||||
if _, err := r.Seek(int64(j), io.SeekStart); err != nil {
|
||||
t.Errorf("i=%d, j=%d: Seek: %v", i, j, err)
|
||||
tt.Errorf("i=%d, j=%d: Seek: %v", i, j, err)
|
||||
continue
|
||||
}
|
||||
if _, err := io.ReadFull(r, got); err != nil {
|
||||
t.Errorf("i=%d, j=%d: ReadFull: %v", i, j, err)
|
||||
tt.Errorf("i=%d, j=%d: ReadFull: %v", i, j, err)
|
||||
continue
|
||||
}
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Errorf("i=%d, j=%d: got\n% 02x\nwant\n% 02x", i, j, got, want)
|
||||
tt.Errorf("i=%d, j=%d: got\n% 02x\nwant\n% 02x", i, j, got, want)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedDictionary(t *testing.T) {
|
||||
func TestSharedDictionary(tt *testing.T) {
|
||||
// Make some "dictionary" data that, as an independent chunk, does not
|
||||
// compress very well.
|
||||
const n = 256
|
||||
@@ -254,20 +254,20 @@ func TestSharedDictionary(t *testing.T) {
|
||||
// Compress.
|
||||
compressed, err := racCompress(original, 0, n, resourcesData)
|
||||
if err != nil {
|
||||
t.Fatalf("i=%d: racCompress: %v", i, err)
|
||||
tt.Fatalf("i=%d: racCompress: %v", i, err)
|
||||
}
|
||||
if len(compressed) == 0 {
|
||||
t.Fatalf("i=%d: compressed form is empty", i)
|
||||
tt.Fatalf("i=%d: compressed form is empty", i)
|
||||
}
|
||||
compressedLengths[i] = len(compressed)
|
||||
|
||||
// Decompress.
|
||||
decompressed, err := racDecompress(compressed)
|
||||
if err != nil {
|
||||
t.Fatalf("i=%d: racDecompress: %v", i, err)
|
||||
tt.Fatalf("i=%d: racDecompress: %v", i, err)
|
||||
}
|
||||
if !bytes.Equal(decompressed, original) {
|
||||
t.Fatalf("i=%d: racDecompress: round trip did not match original", i)
|
||||
tt.Fatalf("i=%d: racDecompress: round trip did not match original", i)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ func TestSharedDictionary(t *testing.T) {
|
||||
// exact value depends on the Zlib compression algorithm, but we should
|
||||
// expect at least a 4x improvement.
|
||||
if ratio := compressedLengths[0] / compressedLengths[1]; ratio < 4 {
|
||||
t.Fatalf("ratio: got %dx, want at least 4x", ratio)
|
||||
tt.Fatalf("ratio: got %dx, want at least 4x", ratio)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ func (r *rsWithReadAt) ReadAt(p []byte, o int64) (int, error) { return r.r.ReadA
|
||||
// testReadSeeker tests that decoding from rs works, regardless of whether rs
|
||||
// implements the optional ReadAt method. If rs does implement io.ReaderAt then
|
||||
// its Read and Seek methods should never be called.
|
||||
func testReadSeeker(t *testing.T, rs io.ReadSeeker) {
|
||||
func testReadSeeker(tt *testing.T, rs io.ReadSeeker) {
|
||||
buf := &bytes.Buffer{}
|
||||
r := &rac.Reader{
|
||||
ReadSeeker: rs,
|
||||
@@ -310,17 +310,17 @@ func testReadSeeker(t *testing.T, rs io.ReadSeeker) {
|
||||
}
|
||||
defer r.Close()
|
||||
if _, err := io.Copy(buf, r); err != nil {
|
||||
t.Fatalf("io.Copy: %v", err)
|
||||
tt.Fatalf("io.Copy: %v", err)
|
||||
}
|
||||
if got, want := buf.String(), decodedSheep; got != want {
|
||||
t.Fatalf("got:\n%s\nwant:\n%s", got, want)
|
||||
tt.Fatalf("got:\n%s\nwant:\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadSeekerSansReadAt(t *testing.T) {
|
||||
testReadSeeker(t, &rsSansReadAt{strings.NewReader(encodedSheep)})
|
||||
func TestReadSeekerSansReadAt(tt *testing.T) {
|
||||
testReadSeeker(tt, &rsSansReadAt{strings.NewReader(encodedSheep)})
|
||||
}
|
||||
|
||||
func TestReadSeekerWithReadAt(t *testing.T) {
|
||||
testReadSeeker(t, &rsWithReadAt{strings.NewReader(encodedSheep)})
|
||||
func TestReadSeekerWithReadAt(tt *testing.T) {
|
||||
testReadSeeker(tt, &rsWithReadAt{strings.NewReader(encodedSheep)})
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"github.com/google/wuffs/internal/testcut"
|
||||
)
|
||||
|
||||
func TestCut(t *testing.T) {
|
||||
testcut.Test(t, SmallestValidMaxEncodedLen, Cut, zlib.NewReader, []string{
|
||||
func TestCut(tt *testing.T) {
|
||||
testcut.Test(tt, SmallestValidMaxEncodedLen, Cut, zlib.NewReader, []string{
|
||||
"midsummer.txt.zlib",
|
||||
"pi.txt.zlib",
|
||||
"romeo.txt.zlib",
|
||||
|
||||
Reference in new issue
Block a user