av/stream/flac: saving progress

This commit is contained in:
saxon 2019-01-22 11:15:39 +10:30
parent b5611bb2b4
commit 99b7f4a44b
1 changed files with 21 additions and 15 deletions

View File

@ -38,45 +38,51 @@ const (
outFile = "testOut.wav"
)
// TestWriteSeekerWrite checks that basic writing to the ws works as expected.
func TestWriteSeekerWrite(t *testing.T) {
writerSeeker := &writeSeeker{}
var ws io.WriteSeeker = writerSeeker
ws := &writeSeeker{}
ws.Write([]byte("hello"))
if string(writerSeeker.buf) != "hello" {
t.Fail()
const tstStr1 = "hello"
ws.Write([]byte(tstStr1))
got := string(ws.buf)
if got != tstStr1 {
t.Errorf("Write failed, got: %v, want: %v", got, tstStr1)
}
ws.Write([]byte(" world"))
if string(writerSeeker.buf) != "hello world" {
t.Fail()
const tstStr2 = " world"
const want = "hello world"
ws.Write([]byte(tstStr2))
got = string(ws.buf)
if got != want {
t.Errorf("Second write failed, got: %v, want: %v", got, want)
}
}
// TestWriteSeekerSeek checks that writing and seeking works as expected, i.e. we
// can write, then seek to a knew place in the buf, and write again, either replacing
// bytes, or appending bytes.
func TestWriteSeekerSeek(t *testing.T) {
writerSeeker := &writeSeeker{}
var ws io.WriteSeeker = writerSeeker
ws := &writeSeeker{}
ws.Write([]byte("hello"))
if string(writerSeeker.buf) != "hello" {
if string(ws.buf) != "hello" {
t.Fail()
}
ws.Write([]byte(" world"))
if string(writerSeeker.buf) != "hello world" {
if string(ws.buf) != "hello world" {
t.Fail()
}
ws.Seek(-2, io.SeekEnd)
ws.Write([]byte("k!"))
if string(writerSeeker.buf) != "hello work!" {
if string(ws.buf) != "hello work!" {
t.Fail()
}
ws.Seek(6, io.SeekStart)
ws.Write([]byte("gopher"))
if string(writerSeeker.buf) != "hello gopher" {
if string(ws.buf) != "hello gopher" {
t.Fail()
}
}