forked from wtolson/go-taglib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtaglib_test.go
127 lines (96 loc) · 2.63 KB
/
taglib_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package taglib
import (
"testing"
"time"
)
func TestReadNothing(t *testing.T) {
file, err := Read("doesnotexist.mp3")
if file != nil {
t.Fatal("Returned non nil file struct.")
}
if err == nil {
t.Fatal("Returned nil err.")
}
if err != ErrInvalid {
t.Fatal("Didn't return ErrInvalid")
}
}
func TestReadDirectory(t *testing.T) {
file, err := Read("/")
if file != nil {
t.Fatal("Returned non nil file struct.")
}
if err == nil {
t.Fatal("Returned nil err.")
}
if err != ErrInvalid {
t.Fatal("Didn't return ErrInvalid")
}
}
func TestTagLib(t *testing.T) {
file, err := Read("test.mp3")
if err != nil {
panic(err)
t.Fatalf("Read returned error: %s", err)
}
defer file.Close()
// Test the Tags
if title := file.Title(); title != "The Title" {
t.Errorf("Got wrong title: %s", title)
}
if artist := file.Artist(); artist != "The Artist" {
t.Errorf("Got wrong artist: %s", artist)
}
if album := file.Album(); album != "The Album" {
t.Errorf("Got wrong album: %s", album)
}
if comment := file.Comment(); comment != "A Comment" {
t.Errorf("Got wrong comment: %s", comment)
}
if genre := file.Genre(); genre != "Booty Bass" {
t.Errorf("Got wrong genre: %s", genre)
}
if year := file.Year(); year != 1942 {
t.Errorf("Got wrong year: %d", year)
}
if track := file.Track(); track != 42 {
t.Errorf("Got wrong track: %d", track)
}
// Test the properties
if length := file.Length(); length != 42*time.Second {
t.Errorf("Got wrong length: %s", length)
}
if bitrate := file.Bitrate(); bitrate != 128 {
t.Errorf("Got wrong bitrate: %d", bitrate)
}
if samplerate := file.Samplerate(); samplerate != 44100 {
t.Errorf("Got wrong samplerate: %d", samplerate)
}
if channels := file.Channels(); channels != 2 {
t.Errorf("Got wrong channels: %d", channels)
}
// Test writing
file.SetTitle("TEST")
file.Save()
if title := file.Title(); title != "TEST" {
t.Errorf("Got the wrong title: %s (expecting %s)", title, "TEST")
}
// Test writing the title name back
file.SetTitle("The Title")
file.Save()
if title := file.Title(); title != "The Title" {
t.Errorf("Got the wrong title when reverting change: %s (expecting %s", title, "The Title")
}
// Test setting the artist
file.SetArtist("Test Artist")
file.Save()
if artist := file.Artist(); artist != "Test Artist" {
t.Errorf("Got the wrong artist: %s (expecting %s)", artist, "Test Artist")
}
// Test writing back the original artist name
file.SetArtist("The Artist")
file.Save()
if artist := file.Artist(); artist != "The Artist" {
t.Errorf("Got the wrong artist when reverting change: %s (expecting %s)", artist, "The Artist")
}
}