You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.0 KiB
91 lines
2.0 KiB
3 years ago
|
package v1
|
||
3 years ago
|
|
||
|
import (
|
||
|
"os"
|
||
3 years ago
|
"path/filepath"
|
||
3 years ago
|
"testing"
|
||
|
)
|
||
|
|
||
3 years ago
|
var TESTDATAPATH string = filepath.Join("..", "testData")
|
||
|
|
||
3 years ago
|
var TESTv1TAG = &ID3v1Tag{
|
||
3 years ago
|
SongName: "testsong",
|
||
|
Artist: "testartist",
|
||
|
Album: "testalbum",
|
||
|
Year: 727,
|
||
|
Comment: "testcomment",
|
||
|
Genre: "Blues",
|
||
|
}
|
||
|
|
||
3 years ago
|
func TestGetv1Tags(t *testing.T) {
|
||
3 years ago
|
testfile, err := os.OpenFile(filepath.Join(TESTDATAPATH, "testreadv1.mp3"), os.O_CREATE|os.O_RDONLY, os.ModePerm)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("could not open file for testing: %s", err)
|
||
|
}
|
||
3 years ago
|
tag, err := Getv1Tag(testfile)
|
||
3 years ago
|
if err != nil {
|
||
3 years ago
|
t.Errorf("GetID3v1Tag failed: %s", err)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
if tag.Version != V1_1 {
|
||
|
t.Errorf("GetID3v1Tag failed: expected version to be %s; got %s", V1_1, tag.Version)
|
||
|
}
|
||
|
|
||
3 years ago
|
if tag.Comment != "Comment here " {
|
||
3 years ago
|
t.Errorf("GetID3v1Tag failed: expected comment to be %s; got %s", "Comment here ", tag.Comment)
|
||
|
}
|
||
|
|
||
|
if tag.Genre != "Soundtrack" {
|
||
|
t.Errorf("GetID3v1Tag failed: expected genre to be %s; got %s", "Soundtrack", tag.Genre)
|
||
|
}
|
||
|
|
||
|
if tag.Track != 8 {
|
||
|
t.Errorf("GetID3v1Tag failed: expected track number to be %d; got %d", 8, tag.Track)
|
||
3 years ago
|
}
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
func TestWritev1Tags(t *testing.T) {
|
||
3 years ago
|
f, err := os.OpenFile(filepath.Join(TESTDATAPATH, "testwritev1.mp3"), os.O_CREATE|os.O_RDWR, os.ModePerm)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("%s", err)
|
||
|
}
|
||
|
defer f.Close()
|
||
|
|
||
3 years ago
|
tag := TESTv1TAG
|
||
3 years ago
|
|
||
3 years ago
|
// writing a tag
|
||
3 years ago
|
err = tag.write(f)
|
||
3 years ago
|
if err != nil {
|
||
3 years ago
|
t.Errorf("WriteID3v1Tag failed: %s", err)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
// reading a tag
|
||
3 years ago
|
readTag, err := Getv1Tag(f)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("%s", err)
|
||
|
}
|
||
|
|
||
3 years ago
|
if readTag.Album != "testalbum" {
|
||
|
t.Errorf("WriteID3v1Tag failed: expected %s; got %s", "testalbum", readTag.Album)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
if readTag.Year != 727 {
|
||
|
t.Errorf("WriteID3v1Tag failed: expected %d; got %d", 727, readTag.Year)
|
||
3 years ago
|
}
|
||
|
}
|
||
3 years ago
|
|
||
|
func TestWriteID3v1ToFile(t *testing.T) {
|
||
3 years ago
|
f, err := os.OpenFile(filepath.Join(TESTDATAPATH, "testwritev1.mp3"), os.O_CREATE|os.O_RDWR, os.ModePerm)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("%s", err)
|
||
|
}
|
||
|
|
||
3 years ago
|
tag := TESTv1TAG
|
||
3 years ago
|
|
||
3 years ago
|
err = tag.WriteToFile(f)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("WriteID3v1ToFile failed: %s", err)
|
||
|
}
|
||
|
|
||
|
}
|