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.
86 lines
1.9 KiB
86 lines
1.9 KiB
3 years ago
|
package v1
|
||
3 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
3 years ago
|
"path/filepath"
|
||
3 years ago
|
"testing"
|
||
|
)
|
||
|
|
||
3 years ago
|
var TESTV11TAGS = &ID3v11Tags{
|
||
|
SongName: "testsong",
|
||
|
Artist: "testartist",
|
||
|
Album: "testalbum",
|
||
|
Year: 727,
|
||
|
Comment: "testcomment",
|
||
|
Track: 5,
|
||
|
Genre: "Blues",
|
||
|
}
|
||
|
|
||
3 years ago
|
func TestGetID3v11Tags(t *testing.T) {
|
||
3 years ago
|
testfile, err := os.Open(filepath.Join(TESTDATAPATH, "testreadv1.mp3"))
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("could not open file for testing: %s", err)
|
||
|
}
|
||
|
mp3tags, err := GetID3v11Tags(testfile)
|
||
|
if err != nil {
|
||
3 years ago
|
t.Errorf("GetID3v11Tags failed: %s", err)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
if mp3tags.Artist != "Artist" {
|
||
3 years ago
|
fmt.Printf("%v", mp3tags.Artist)
|
||
3 years ago
|
t.Errorf("GetID3v11Tags failed: expected %s; got %s", "Artist", mp3tags.Artist)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
if mp3tags.Track != 4 {
|
||
|
t.Errorf("GetID3v11Tags failed: expected %d; got %d", 4, mp3tags.Track)
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
// WILL ADD NEW "TAG" WITHOUT REMOVING THE OLD ONE !!!
|
||
3 years ago
|
func TestWriteID3v11Tags(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
|
tags := TESTV11TAGS
|
||
3 years ago
|
|
||
3 years ago
|
err = tags.Write(f)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("WriteID3v1Tags failed: %s", err)
|
||
|
}
|
||
|
|
||
|
readTags, err := GetID3v11Tags(f)
|
||
|
if err != nil {
|
||
|
t.Errorf("%s", err)
|
||
|
}
|
||
|
|
||
|
if readTags.Album != "testalbum" {
|
||
|
t.Errorf("WriteID3v11Tags failed: expected %s; got %s", "testalbum", readTags.Album)
|
||
|
}
|
||
|
|
||
|
if readTags.Year != 727 {
|
||
|
t.Errorf("WriteID3v11Tags failed: expected %d; got %d", 727, readTags.Year)
|
||
|
}
|
||
|
|
||
|
if readTags.Track != 5 {
|
||
|
t.Errorf("WriteID3v11Tags failed: expected %d; got %d", 5, readTags.Track)
|
||
3 years ago
|
}
|
||
|
}
|
||
3 years ago
|
|
||
|
func TestWriteID3v11ToFile(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)
|
||
|
}
|
||
|
|
||
|
tags := TESTV11TAGS
|
||
|
|
||
3 years ago
|
err = tags.WriteToFile(f)
|
||
3 years ago
|
if err != nil {
|
||
|
t.Errorf("WriteID3v1ToFile failed: %s", err)
|
||
|
}
|
||
|
}
|