-
Notifications
You must be signed in to change notification settings - Fork 30
/
box_test.go
66 lines (55 loc) · 1.44 KB
/
box_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
package mp4
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type mockBox struct {
Type BoxType
DynSizeMap map[string]uint
DynLenMap map[string]uint
DynOptMap map[string]bool
IsPStringMap map[string]bool
}
func (m *mockBox) GetType() BoxType {
return m.Type
}
func (m *mockBox) GetFieldSize(n string, ctx Context) uint {
if s, ok := m.DynSizeMap[n]; !ok {
panic(fmt.Errorf("invalid name of dynamic-size field: %s", n))
} else {
return s
}
}
func (m *mockBox) GetFieldLength(n string, ctx Context) uint {
if l, ok := m.DynLenMap[n]; !ok {
panic(fmt.Errorf("invalid name of dynamic-length field: %s", n))
} else {
return l
}
}
func (m *mockBox) IsOptFieldEnabled(n string, ctx Context) bool {
if enabled, ok := m.DynOptMap[n]; !ok {
panic(fmt.Errorf("invalid name of dynamic-opt field: %s", n))
} else {
return enabled
}
}
func (m *mockBox) IsPString(name string, bytes []byte, remainingSize uint64, ctx Context) bool {
if b, ok := m.IsPStringMap[name]; ok {
return b
}
return true
}
func TestFullBoxFlags(t *testing.T) {
box := FullBox{}
box.SetFlags(0x35ac68)
assert.Equal(t, byte(0x35), box.Flags[0])
assert.Equal(t, byte(0xac), box.Flags[1])
assert.Equal(t, byte(0x68), box.Flags[2])
assert.Equal(t, uint32(0x35ac68), box.GetFlags())
box.AddFlag(0x030000)
assert.Equal(t, uint32(0x37ac68), box.GetFlags())
box.RemoveFlag(0x000900)
assert.Equal(t, uint32(0x37a468), box.GetFlags())
}