1
0
dwelling-radio/pkg/oggtag/oggtag_test.go

58 lines
1.0 KiB
Go

package oggtag
import (
"testing"
"time"
)
const sampleSong = "/mnt/data/appdata/radio/fallback.ogg"
const sampleArtist = "breskina"
const sampleTitle = "Песня про мечты"
func TestGetTag(t *testing.T) {
oggf, err := NewOggFile(sampleSong)
if err != nil {
t.Fatal(err)
}
tag := oggf.GetTag("artist")
if tag != sampleArtist {
t.Error(tag, "!=", sampleArtist)
}
tag = oggf.GetTag("title")
if tag != sampleTitle {
t.Error(tag, "!=", sampleTitle)
}
}
func BenchmarkGetTag(b *testing.B) {
oggf, err := NewOggFile(sampleSong)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
oggf.GetTag("artist")
}
}
func BenchmarkGetDuration(b *testing.B) {
oggf, err := NewOggFile(sampleSong)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
oggf.GetDuration()
}
}
func TestGetDuration(t *testing.T) {
oggf, err := NewOggFile(sampleSong)
if err != nil {
t.Fatal(err)
}
dur := oggf.GetDuration()
t.Log(dur, ((dur)/time.Second)*time.Second, dur.Milliseconds())
}