mirror of https://bitbucket.org/ausocean/av.git
108 lines
2.6 KiB
Go
108 lines
2.6 KiB
Go
/*
|
|
NAME
|
|
flac_test.go
|
|
|
|
DESCRIPTION
|
|
flac_test.go provides utilities to test FLAC audio decoding
|
|
|
|
AUTHOR
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
|
|
|
LICENSE
|
|
flac_test.go is Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
option) any later version.
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
*/
|
|
package flac
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
testFile = "/home/saxon/Desktop/robot.flac"
|
|
outFile = "testOut.wav"
|
|
)
|
|
|
|
// TestWriteSeekerWrite checks that basic writing to the ws works as expected.
|
|
func TestWriteSeekerWrite(t *testing.T) {
|
|
ws := &writeSeeker{}
|
|
|
|
const tstStr1 = "hello"
|
|
ws.Write([]byte(tstStr1))
|
|
got := string(ws.buf)
|
|
if got != tstStr1 {
|
|
t.Errorf("Write failed, got: %v, want: %v", got, tstStr1)
|
|
}
|
|
|
|
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) {
|
|
ws := &writeSeeker{}
|
|
|
|
ws.Write([]byte("hello"))
|
|
if string(ws.buf) != "hello" {
|
|
t.Fail()
|
|
}
|
|
|
|
ws.Write([]byte(" world"))
|
|
if string(ws.buf) != "hello world" {
|
|
t.Fail()
|
|
}
|
|
|
|
ws.Seek(-2, io.SeekEnd)
|
|
ws.Write([]byte("k!"))
|
|
if string(ws.buf) != "hello work!" {
|
|
t.Fail()
|
|
}
|
|
|
|
ws.Seek(6, io.SeekStart)
|
|
ws.Write([]byte("gopher"))
|
|
if string(ws.buf) != "hello gopher" {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestDecodeFlac(t *testing.T) {
|
|
b, err := ioutil.ReadFile(testFile)
|
|
if err != nil {
|
|
t.Fatalf("Could not read test file, failed with err: %v", err.Error())
|
|
}
|
|
out, err := Decode(b)
|
|
if err != nil {
|
|
t.Errorf("Could not decode, failed with err: %v", err.Error())
|
|
}
|
|
f, err := os.Create(outFile)
|
|
if err != nil {
|
|
t.Fatalf("Could not create output file, failed with err: %v", err.Error())
|
|
}
|
|
_, err = f.Write(out)
|
|
if err != nil {
|
|
t.Fatalf("Could not write to output file, failed with err: %v", err.Error())
|
|
}
|
|
}
|