av/stream/flac/flac_test.go

102 lines
2.3 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"
)
func TestWriteSeekerWrite(t *testing.T) {
writerSeeker := &writeSeeker{}
var ws io.WriteSeeker = writerSeeker
ws.Write([]byte("hello"))
if string(writerSeeker.buf) != "hello" {
t.Fail()
}
ws.Write([]byte(" world"))
if string(writerSeeker.buf) != "hello world" {
t.Fail()
}
}
func TestWriteSeekerSeek(t *testing.T) {
writerSeeker := &writeSeeker{}
var ws io.WriteSeeker = writerSeeker
ws.Write([]byte("hello"))
if string(writerSeeker.buf) != "hello" {
t.Fail()
}
ws.Write([]byte(" world"))
if string(writerSeeker.buf) != "hello world" {
t.Fail()
}
ws.Seek(-2, io.SeekEnd)
ws.Write([]byte("k!"))
if string(writerSeeker.buf) != "hello work!" {
t.Fail()
}
ws.Seek(6, io.SeekStart)
ws.Write([]byte("gopher"))
if string(writerSeeker.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())
}
}