-
Notifications
You must be signed in to change notification settings - Fork 1
/
v2_test.go
226 lines (189 loc) · 4.9 KB
/
v2_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package id3
import (
"bytes"
"fmt"
"testing"
"github.com/cloudcloud/go-id3/frames"
"github.com/stretchr/testify/assert"
)
func TestBaseV2(t *testing.T) {
b := &tfile{}
b.Write([]byte("Bob is "))
v := &V2{Debug: false}
err := v.Parse(b)
if err == nil {
t.Fatalf("Invalid Parse() success with V2")
}
}
func TestParseV2(t *testing.T) {
b := &tfile{}
b.Write([]byte("ID3\x03\x00\x40\x00\x00\x00\x2b" +
"\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00" +
"TPE1\x00\x00\x00\x0d\x00\x00\x00Cult of Luna" +
"FAIL\x00\x00\x00\x00\x00\x00"))
v := &V2{Debug: false}
err := v.Parse(b)
if err != nil {
t.Fatalf("Unable to Parse() with V2 (v2.3.0)")
}
found := v.GetArtist()
expected := "Cult of Luna"
if found != expected {
t.Fatalf("Found [%s], Expected [%s]", found, expected)
}
}
func TestParseV2Crc(t *testing.T) {
b := &tfile{}
b.Write([]byte("ID3\x03\x00\x40\x00\x00\x00\x2b" +
"\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00" +
"\x00\x02\x00\xaa" +
"TPE1\x00\x00\x00\x0d\x00\x00\x00Cult of Luna" +
"FAIL\x00\x00\x00\x00\x00\x00"))
v := &V2{Debug: false}
err := v.Parse(b)
if err != nil {
t.Fatalf("Unable to Parse() with V2 (v2.3.0)")
}
if !v.Crc {
t.Fatal("Expected CRC processing")
}
calculated := v.CrcContent
should := []byte("\x00\x02\x00\xaa")
if !bytes.Equal(should, calculated) {
t.Fatalf("Found %v, Expected %v", should, calculated)
}
}
func TestParseV2Debug(t *testing.T) {
b := &tfile{}
v := &V2{Debug: true}
b.Write([]byte("ID3\x04\x00\x00\x00\x00\x00\x35" +
"TEXT\x00\x00\x00\x0a\x00\x00\x00CerealBoy" +
"FAIL\x00\x00\x00\x00\x00\x00" +
"TPE2\x00\x00\x00\x0d\x00\x00\x00Cult of Luna"))
err := v.Parse(b)
if err != nil {
t.Fatalf("Unable to Parse() with V2 (v2.4.0)")
}
found := v.GetArtist()
expected := "Cult of Luna"
if found != expected {
t.Fatalf("Found [%s], Expected [%s]", found, expected)
}
}
func TestV2Pe3(t *testing.T) {
b := &tfile{}
v := &V2{Debug: true}
b.Write([]byte("ID3\x04\x00\x00\x00\x00\x00\x46" +
"TEXT\x00\x00\x00\x0a\x00\x00\x00CerealBoy" +
"TPE3\x00\x00\x00\x0d\x00\x00\x00Cult of Luna" +
"TALB\x00\x00\x00\x0b\x00\x00\x00The Beyond"))
v.Parse(b)
expected := "Cult of Luna"
found := v.GetArtist()
if expected != found {
t.Fatalf("Got [%s], expected [%s]", found, expected)
}
expected = "The Beyond"
found = v.GetAlbum()
if expected != found {
t.Fatalf("Got [%s], expected [%s]", found, expected)
}
}
func TestV2Pe4(t *testing.T) {
b := &tfile{}
v := &V2{Debug: true}
b.Write([]byte("ID3\x04\x00\x00\x00\x00\x00\x46" +
"TEXT\x00\x00\x00\x0a\x00\x00\x00CerealBoy" +
"TPE4\x00\x00\x00\x0d\x00\x00\x00Cult of Luna" +
"TOAL\x00\x00\x00\x0b\x00\x00\x00The Beyond"))
v.Parse(b)
expected := "Cult of Luna"
found := v.GetArtist()
if expected != found {
t.Fatalf("Got [%s], expected [%s]", found, expected)
}
expected = "The Beyond"
found = v.GetAlbum()
if expected != found {
t.Fatalf("Got [%s], expected [%s]", found, expected)
}
}
func TestPanicNextBytes(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatalf("Was expecting a panic() from zero length read")
}
}()
v := &V2{}
_ = v.nextBytes(0)
}
func TestParseV2Original(t *testing.T) {
b := &tfile{}
v := &V2{Debug: false}
b.Write([]byte("ID3\x02\x00\x00\x00\x00\x00\x14" +
"BUF\x00\x00\x08\x00\x00\x42\x00\x00\x00\x00\x05" +
"BUD\x00\x00\x00"))
err := v.Parse(b)
if err != nil {
t.Fatalf("Unexpected error: [%s]", err)
}
expected := 1
found := len(v.Frames)
if found != expected {
t.Fatalf("Got [%d], Expected [%d]", found, expected)
}
}
func TestParseInvalidVersion(t *testing.T) {
b := &tfile{}
v := &V2{}
b.Write([]byte("ID3\x00\x05\x00\x00\x00\x00\x10" +
"FAIL\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"))
v.Parse(b)
expected := 0
found := len(v.Frames)
if found != expected {
t.Fatalf("Got [%d], Expected [%d]", found, expected)
}
}
func TestSimpleCatcher(t *testing.T) {
v := &V2{}
b := &tfile{}
v.catcher(b)
found := b.buf.String()
expected := "<nil>"
if found != expected {
t.Errorf("Got [%s], Expected [%s]", found, expected)
}
}
func TestCatcherElegance(t *testing.T) {
v := &V2{}
b := &tfile{}
catchMe(v, b)
found := b.buf.String()
expected := "Stumbled upon a panic(), testing.\n"
if found != expected {
t.Errorf("Got [%s], Expected [%s]", found, expected)
}
}
func catchMe(v *V2, b *tfile) {
defer v.catcher(b)
panic("testing")
}
func TestGetTitle(t *testing.T) {
assert := assert.New(t)
x := []frames.IFrame{
frames.NewFrame("TIT2", "Track Title", 0),
frames.NewFrame("TIT3", "Track Title", 0),
frames.NewFrame("TIT1", "Track Title", 0),
frames.NewFrame("TT2", "Track Title", 0),
frames.NewFrame("TT3", "Track Title", 0),
frames.NewFrame("TT1", "Track Title", 0),
}
for _, i := range x {
expected := fmt.Sprintf("Hello! %s.", i.GetName())
i.(*frames.TEXT).Cleaned = expected
v := &V2{Frames: []frames.IFrame{i}}
actual := v.GetTitle()
assert.Equal(expected, actual, "")
}
}