// Copyright 2015, Joe Tsai. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE.md file. package meta import ( "bytes" "io" "io/ioutil" "math/rand" "strings" "testing" "github.com/dsnet/compress/internal/errors" "github.com/dsnet/compress/internal/testutil" ) // TestReader tests that the reader is able to properly decode a set of valid // input strings or properly detect corruption in a set of invalid input // strings. A third-party decoder should verify that it has the same behavior // when processing these input vectors. func TestReader(t *testing.T) { db := testutil.MustDecodeBitGen dh := testutil.MustDecodeHex errFuncs := map[string]func(error) bool{ "IsEOF": func(err error) bool { return err == io.EOF }, "IsUnexpectedEOF": func(err error) bool { return err == io.ErrUnexpectedEOF }, "IsCorrupted": errors.IsCorrupted, } vectors := []struct { desc string // Description of the test input []byte // Test input string output []byte // Expected output string final FinalMode // Expected FinalMode value errf string // Name of error checking callback }{{ desc: "empty string", input: dh(""), output: dh(""), errf: "IsEOF", }, { desc: "bad empty meta block (FinalNil, first symbol not symZero)", input: db(`<<< < (0 10) (00100 00000 1010) (011 000 011 001 000 (000 000)*4 010) > (111 (111 10 (111 10 0*14 10 0*13 (110 10 0 10 0*4 10 0*4 10*2 (111 10 0*2 10 0*3 10 0*4 10*2 0*2 10 0*3 10*2 (111 10 0 10*2 0*3 10 0*4 10*2 0*2 10 0*3 10*2 0 10*2 0*3 10*2 (111 10 0 10 0 10*2 0*4 10 0*2 10 0 10 0 10 0*2 10*2 0*3 10*2 0 10*2 0*3 10*2 0 10*2 0 10 (110 10 0*3 10 (111 10 0*4 10 (111 10 0*5 10 (111 10*2 0*2 10 (111 10*2 0*3 10 (111 10*2 0*4 10 (111 10 0*4 10 0 10 0*3 10 0*2 10 (110 10*2 0*3 10 0 10 0*4 10 0 (110 10 (111 10 (111 10 (111 10 (111 10 (111 10 (111 10 (111 (111 0*2 (110 10*7 (111 10 0*4 10 0 10 0*3 10 0*2 10 (110 10 0*4 10 0 10 0*3 10 0*2 10 (110 10 0*4 10 0 10 0*3 10 0*2 10 (110 10 0*4 10 0 10 0*3 10 0*2 10 (110 0*34 10 0 10 (111 10 (111 10 (111 (110 10 (111 10 (111 10 (111 0 10 (111 10 (111 10 (111 10 (111 10 (111 (110 10 0 10 0*3 10 0 10*2 0 10*3 0 10 0 10 0*2 10*2 0*2 10 0*2 10*3 0 (110 (110 10 0*3 10 (110 0*2 10 0 10*3 0*2 10 0*3 10 0 10 (110 0*2 10 0 10*3 0 (110 0 10*3 0*2 10 0 10*2 0 (110