Skip to content

Commit

Permalink
Merge branch 'issue22'
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalholm committed Jul 15, 2021
2 parents 5376c15 + 177b8ac commit e073f0d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions brotli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ package brotli

import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"math"
"math/rand"
"os"
"testing"
"time"
)
Expand Down Expand Up @@ -105,6 +107,46 @@ func TestWriter(t *testing.T) {
}
}

func TestIssue22(t *testing.T) {
f, err := os.Open("testdata/issue22.gz")
if err != nil {
t.Fatalf("Error opening test data file: %v", err)
}
defer f.Close()

zr, err := gzip.NewReader(f)
if err != nil {
t.Fatalf("Error creating gzip reader: %v", err)
}

data, err := io.ReadAll(zr)
if err != nil {
t.Fatalf("Error reading test data: %v", err)
}

if len(data) != 2851073 {
t.Fatalf("Wrong length for test data: got %d, want 2851073", len(data))
}

for level := BestSpeed; level <= BestCompression; level++ {
out := bytes.Buffer{}
e := NewWriterOptions(&out, WriterOptions{Quality: level})
n, err := e.Write(data)
if err != nil {
t.Errorf("Error compressing data: %v", err)
}
if int(n) != len(data) {
t.Errorf("Write() n=%v, want %v", n, len(data))
}
if err := e.Close(); err != nil {
t.Errorf("Close Error after writing %d bytes: %v", n, err)
}
if err := checkCompressedData(out.Bytes(), data); err != nil {
t.Errorf("Error decompressing data at level %d: %v", level, err)
}
}
}

func TestEncoderStreams(t *testing.T) {
// Test that output is streamed.
// Adjust window size to ensure the encoder outputs at least enough bytes
Expand Down
Binary file added testdata/issue22.gz
Binary file not shown.

0 comments on commit e073f0d

Please sign in to comment.