-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathbox_test.go
63 lines (59 loc) · 1.56 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
package mp4
import (
"bytes"
"encoding/hex"
"testing"
"github.com/Eyevinn/mp4ff/bits"
)
// TestBadBoxAndRemoveBoxDecoder checks that we can avoid decoder error by removing a BoxDecode.
//
// The box is then interpreted as an UnknownBox and its data is not further processed with decoded.
func TestBadBoxAndRemoveBoxDecoder(t *testing.T) {
badMetaBox := (`000000416d6574610000002168646c7300000000000000006d64746100000000` +
`000000000000000000000000106b657973000000000000000000000008696c7374`)
data, err := hex.DecodeString(badMetaBox)
if err != nil {
t.Error(err)
}
sr := bits.NewFixedSliceReader(data)
_, err = DecodeBoxSR(0, sr)
if err == nil {
t.Errorf("reading bad meta box should have failed")
}
sr = bits.NewFixedSliceReader(data)
RemoveBoxDecoder("meta")
defer SetBoxDecoder("meta", DecodeMeta, DecodeMetaSR)
box, err := DecodeBoxSR(0, sr)
if err != nil {
t.Error(err)
}
_, ok := box.(*MetaBox)
if ok {
t.Errorf("box should not be MetaBox")
}
unknown, ok := box.(*UnknownBox)
if !ok {
t.Errorf("box should be unknown")
}
if unknown.Type() != "meta" {
t.Errorf("unknown type %q instead of meta", unknown.Type())
}
b := bytes.Buffer{}
err = unknown.Encode(&b)
if err != nil {
t.Error(err)
}
if !bytes.Equal(data, b.Bytes()) {
t.Errorf("written unknown differs")
}
}
func TestFixed16and32(t *testing.T) {
f16 := Fixed16(256)
if f16.String() != "1.0" {
t.Errorf("Fixed16(256) should be 1.0, not %s", f16.String())
}
f32 := Fixed32(65536)
if f16.String() != "1.0" {
t.Errorf("Fixed32(65536) should be 1.0, not %s", f32.String())
}
}