-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathboxsr_test.go
More file actions
90 lines (84 loc) · 2.24 KB
/
boxsr_test.go
File metadata and controls
90 lines (84 loc) · 2.24 KB
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
package mp4_test
import (
"bytes"
"os"
"testing"
"github.com/Eyevinn/mp4ff/bits"
"github.com/Eyevinn/mp4ff/mp4"
)
// TestDecodeHeaderSRI tests DecodeHeaderSR with sufficient and insufficient bytes
func TestDecodeHeaderSRInsufficientBytes(t *testing.T) {
tests := []struct {
name string
data []byte
wantErr bool
}{
{
name: "7 bytes (one less than boxHeaderSize)",
data: make([]byte, 7),
wantErr: true,
},
{
name: "8 bytes (exactly boxHeaderSize)",
data: []byte{0x00, 0x00, 0x00, 0x10, 't', 'e', 's', 't'}, // size=16, type="test"
wantErr: false,
},
{
name: "extended size with insufficient bytes",
data: []byte{0x00, 0x00, 0x00, 0x01, 't', 'e', 's', 't', 0x00, 0x00, 0x00},
wantErr: true,
},
{
name: "extended size with sufficient bytes for mdat",
data: []byte{0x00, 0x00, 0x00, 0x01, 'm', 'd', 'a', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20},
wantErr: false,
},
{
name: "extended size rejected for non-mdat",
data: []byte{0x00, 0x00, 0x00, 0x01, 't', 'e', 's', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20},
wantErr: true,
},
{
name: "zero size not supported",
data: []byte{0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't'},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sr := bits.NewFixedSliceReader(tt.data)
_, err := mp4.DecodeHeaderSR(sr)
if (err != nil) != tt.wantErr {
t.Errorf("DecodeHeaderSR() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
// Test decode + encode file with slice reader and writer
func TestDecodeEncodeSRW(t *testing.T) {
testFiles := []string{
"testdata/1.m4s",
"testdata/prog_8s_enc_dashinit.mp4",
"testdata/prog_8s.mp4",
}
for _, testFile := range testFiles {
inData, err := os.ReadFile(testFile)
if err != nil {
t.Error(err)
}
sr := bits.NewFixedSliceReader(inData)
decFile, err := mp4.DecodeFileSR(sr)
if err != nil {
t.Error(err)
}
decFile.FragEncMode = mp4.EncModeBoxTree
sw := bits.NewFixedSliceWriter(len(inData))
err = decFile.EncodeSW(sw)
if err != nil {
t.Error(err)
}
if !bytes.Equal(inData, sw.Bytes()) {
t.Errorf("mismatch for testfile %s. Generated bytes differ from input", testFile)
}
}
}