示例#1
0
func TestBlockFullWrite(t *testing.T) {
	block := newBlock(1000)

	_, err := block.Write(testhelpers.NoRunData(block.size))
	if err == nil {
		t.Error("Block full size write should return size reached error")
	}
	if err != errBlockSizeReached {
		t.Fatal(err)
	}
}
示例#2
0
func TestBlockMultiWrite(t *testing.T) {
	block := newBlock(1000)

	n, err := block.Write(testhelpers.NoRunData(block.size / 2))
	if err != nil {
		t.Fatal(err)
	}

	if n != block.size/2 {
		t.Error("Block half write wrote unexpected number of bytes. Got", n,
			"wanted", block.size/2)
	}

	_, err = block.Write(testhelpers.NoRunData(block.size / 2))
	if err == nil {
		t.Error("Block full size write should return size reached error")
	}
	if err != errBlockSizeReached {
		t.Fatal(err)
	}
}
示例#3
0
func TestFilledNoRunsBlock(t *testing.T) {
	var buf bytes.Buffer
	var out bytes.Buffer
	expected := testhelpers.NoRunData(baseBlockSize)

	writer, _ := NewWriterLevel(&buf, 1)
	_, err := writer.Write(expected)
	if err == nil {
		err = writer.Close()
	}
	if err != nil {
		t.Fatal(err)
	}

	reader := bzip2.NewReader(&buf)
	_, err = io.Copy(&out, reader)
	if err != nil {
		t.Fatal(err)
	}

	if out.String() != string(expected) {
		t.Error("Output is incorrect.")
	}
}