-
Notifications
You must be signed in to change notification settings - Fork 84
/
hdlr_test.go
69 lines (64 loc) · 1.99 KB
/
hdlr_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
package mp4
import (
"bytes"
"encoding/hex"
"testing"
)
func TestHdlr(t *testing.T) {
cases := []struct {
mediaType string
handlerType string
handlerName string
expectedError string
}{
{"video", "vide", "mp4ff video handler", ""},
{"vide", "vide", "mp4ff video handler", ""},
{"audio", "soun", "mp4ff audio handler", ""},
{"soun", "soun", "mp4ff audio handler", ""},
{"subtitle", "subt", "mp4ff subtitle handler", ""},
{"text", "text", "mp4ff text handler", ""},
{"wvtt", "text", "mp4ff text handler", ""},
{"meta", "meta", "mp4ff timed metadata handler", ""},
{"clcp", "subt", "mp4ff closed captions handler", ""},
{"roses", "", "", "handler type is not four characters: roses"},
{"auxv", "auxv", "mp4ff auxv handler", ""},
}
for _, c := range cases {
t.Run(c.mediaType, func(t *testing.T) {
hdlr, err := CreateHdlr(c.mediaType)
if c.expectedError != "" {
if err == nil {
t.Errorf("Expected error %s, but got nil", c.expectedError)
} else if err.Error() != c.expectedError {
t.Errorf("Expected error %s, but got %s", c.expectedError, err.Error())
}
return
}
if hdlr.HandlerType != c.handlerType {
t.Errorf("Expected handler type %s, but got %s", c.handlerType, hdlr.HandlerType)
}
if hdlr.Name != c.handlerName {
t.Errorf("Expected handler name %s, but got %s", c.handlerName, hdlr.Name)
}
boxDiffAfterEncodeAndDecode(t, hdlr)
hdlr.LacksNullTermination = true
boxDiffAfterEncodeAndDecode(t, hdlr)
})
}
}
func TestHdlrDecodeMissingNullTermination(t *testing.T) {
hdlrExample := "0000002068646C72000000000000000049443332000000000000000000000000"
byteData, _ := hex.DecodeString(hdlrExample)
buf := bytes.NewBuffer(byteData)
box, err := DecodeBox(0, buf)
if err != nil {
t.Error(err)
}
hdlr := box.(*HdlrBox)
if hdlr.Size() != uint64(len(byteData)) {
t.Errorf("Got size %d instead of %d", hdlr.Size(), len(byteData))
}
if hdlr.Name != "" {
t.Errorf("Expected empty name, but got %s", hdlr.Name)
}
}