-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheader_test.go
63 lines (61 loc) · 5.9 KB
/
header_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
package audiotools
import "testing"
func TestHeaderFormat(t *testing.T) {
tests := []struct {
name string
header []byte
want Format
wantErr bool
}{
{name: "mp4",
header: []byte{0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x00, 0x69, 0x73, 0x6F, 0x6D, 0x6D, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x88, 0x66, 0x72, 0x65, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x6D, 0x64, 0x61, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0xB3, 0xBE, 0x65, 0x00, 0x00, 0x00, 0x0D, 0x67, 0x64, 0x00, 0x32, 0xAC, 0x1B, 0x1A, 0x32, 0x06, 0xE0, 0x73, 0x79, 0xD0, 0x00, 0x00, 0x00, 0x05, 0x68, 0xE8, 0xBC, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x74, 0x65, 0xB8, 0x00, 0x02, 0x00, 0x00, 0x44, 0xFF, 0xF2, 0x83, 0x60, 0xFC, 0x7F, 0xFC, 0x0F, 0x59, 0xAF, 0xFB, 0x88, 0x7D, 0xE0, 0xA0, 0x98, 0x9C, 0x5B, 0x47, 0x62, 0x96, 0xA8, 0xD2, 0x17, 0xB7, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x09, 0x57, 0xB9, 0xB8, 0x69, 0x5B, 0x1A, 0xB9, 0xA7, 0x34, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x01, 0x03, 0x00, 0x00, 0x03, 0x02, 0xEE, 0x00, 0x00, 0x0B, 0x10, 0x00, 0x00, 0x2F, 0xC0, 0x00, 0x01, 0x47, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x34, 0x80, 0x00, 0x01, 0xE2, 0x00, 0x00, 0x0E, 0x10, 0x00, 0x00, 0x88, 0x00, 0x00, 0x06, 0x88, 0x00, 0x00, 0x44, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x5B, 0xE0, 0x00, 0x00, 0x00, 0x76, 0x65, 0x00, 0x33, 0x9B, 0x80, 0x00, 0x20, 0x00, 0x04, 0x4F, 0xF2, 0x83, 0x60, 0xFC, 0x7F, 0xFC, 0x0F, 0x59, 0xAF, 0xFB, 0x88, 0x7D, 0xE0, 0xA0, 0x98, 0x9C, 0x5B, 0x47, 0x62, 0x96, 0xA8, 0xD2, 0x17, 0xB7, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x09, 0x57, 0xB9, 0xB8, 0x69, 0x5B, 0x1A, 0xB9, 0xA7, 0x34, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x01, 0x03, 0x00, 0x00, 0x03, 0x02, 0xEE, 0x00, 0x00, 0x0B, 0x10, 0x00, 0x00, 0x2F, 0xC0, 0x00, 0x01, 0x47, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x34, 0x80, 0x00, 0x01, 0xE2, 0x00, 0x00, 0x0E, 0x10, 0x00, 0x00, 0x88, 0x00, 0x00, 0x06, 0x88, 0x00, 0x00, 0x44, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x5B, 0xE0, 0x00, 0x00, 0x00, 0x77, 0x65, 0x00, 0x19, 0xCA, 0xE0, 0x00, 0x08, 0x00, 0x01, 0x13, 0xFF, 0xF2, 0x83, 0x60, 0xFC, 0x7F, 0xFC, 0x0F, 0x59, 0xAF, 0xFB, 0x88, 0x7D, 0xE0, 0xA0, 0x98, 0x9C, 0x5B, 0x47, 0x62, 0x96, 0xA8, 0xD2, 0x17, 0xB7, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x09, 0x57, 0xB9, 0xB8, 0x69, 0x5B, 0x1A, 0xB9, 0xA7, 0x34, 0x00, 0x00, 0x03, 0x00, 0x00},
want: VideoMP4,
},
{
name: "wav",
header: []byte{0x52, 0x49, 0x46, 0x46, 0xEC, 0xA8, 0x01, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xAC, 0x00, 0x00, 0x98, 0x09, 0x04, 0x00, 0x06, 0x00, 0x18, 0x00, 0x64, 0x61, 0x74, 0x61, 0xC8, 0xA8, 0x01, 0x00, 0xCC, 0xD9, 0xDC, 0xCC, 0xD9, 0xDC, 0xEF, 0x77},
want: Wav,
},
{
name: "aiff",
header: []byte{0x46, 0x4F, 0x52, 0x4D, 0x00, 0x05, 0x2B, 0x2E, 0x41, 0x49, 0x46, 0x46, 0x43, 0x4F, 0x4D, 0x4D, 0x00, 0x00, 0x00, 0x12, 0x00, 0x02, 0x00, 0x01, 0x4A, 0xC0, 0x00, 0x10, 0x40, 0x0E, 0xAC, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x53, 0x4E, 0x44, 0x00, 0x05},
want: Aiff,
},
{name: "mp3",
header: []byte{0x49, 0x44, 0x33, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x76, 0x54, 0x59, 0x45, 0x52, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x31, 0x39, 0x38, 0x30, 0x54, 0x45, 0x4E, 0x43, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x4C, 0x41, 0x4D, 0x45, 0x20, 0x69, 0x6E, 0x20, 0x46, 0x4C, 0x20, 0x53, 0x74, 0x75, 0x64, 0x69, 0x6F, 0x20, 0x37, 0x54, 0x42, 0x50, 0x4D, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x34, 0x30, 0x50, 0x52, 0x49, 0x56, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00},
want: Mp3,
},
{
name: "m4a",
header: []byte{0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41, 0x20, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x34, 0x41, 0x20, 0x6D, 0x70, 0x34, 0x32, 0x69, 0x73, 0x6F, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x97, 0x2B, 0x6D, 0x6F, 0x6F, 0x76, 0x00, 0x00, 0x00, 0x6C, 0x6D, 0x76, 0x68, 0x64, 0x00, 0x00, 0x00, 0x00, 0xD1, 0xB1, 0xAB, 0xCC, 0xCD, 0x84, 0x91, 0x5C},
want: VideoMP4,
},
{
name: "avi",
header: []byte{0x52, 0x49, 0x46, 0x46, 0x2c, 0x4f, 0x0a, 0x00, 0x41, 0x56, 0x49, 0x20},
want: VideoAvi,
},
{
name: "webm",
header: []byte{0x1a, 0x45, 0xdf, 0xa3, 0x42},
want: VideoWebm,
},
{
name: "unknown",
header: []byte{0x70, 0x61, 0x63, 0x6B, 0x61, 0x67, 0x65, 0x20, 0x61, 0x75, 0x64, 0x69, 0x6F, 0x74, 0x6F, 0x6F, 0x6C, 0x73, 0x0A, 0x0A, 0x69, 0x6D, 0x70, 0x6F, 0x72, 0x74, 0x20, 0x22, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6E, 0x67, 0x22, 0x0A, 0x0A, 0x66, 0x75, 0x6E, 0x63, 0x20, 0x54, 0x65, 0x73, 0x74, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x46, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x28, 0x74, 0x20, 0x2A, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6E, 0x67, 0x2E, 0x54, 0x29, 0x20, 0x00},
want: Unknown,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := HeaderFormat(tt.header)
if (err != nil) != tt.wantErr {
t.Errorf("HeaderFormat() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("HeaderFormat() = %v, want %v", got, tt.want)
}
})
}
}