-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathavs3_test.go
More file actions
153 lines (133 loc) · 4.59 KB
/
avs3_test.go
File metadata and controls
153 lines (133 loc) · 4.59 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package mp4_test
import (
"bytes"
"testing"
"github.com/Eyevinn/mp4ff/mp4"
)
func TestAvs3Configuration(t *testing.T) {
// Create a sample Av3cBox
avs3Config := &mp4.Av3cBox{
Avs3Config: mp4.Avs3DecoderConfigurationRecord{
ConfigurationVersion: 1,
SequenceHeaderLength: 4,
SequenceHeader: []byte{0x01, 0x02, 0x03, 0x04},
LibraryDependencyIDC: 2, // 2-bit value
},
}
boxDiffAfterEncodeAndDecode(t, avs3Config)
buf := bytes.Buffer{}
err := avs3Config.Encode(&buf)
if err != nil {
t.Error(err)
}
data := buf.Bytes()
// Check that there is an error if the LibraryDependencyIDC reserved bits are not set correctly
raw := make([]byte, len(data))
copy(raw, data)
// Set the last byte to have incorrect reserved bits (should be 0xFC | 0x02 = 0xFE)
raw[len(raw)-1] = 0x02 // Missing reserved bits
_, err = mp4.DecodeBox(0, bytes.NewBuffer(raw))
errMsg := "decode av3c pos 0: invalid LibraryDependencyIDC: reserved bits must be 111111"
if err == nil || err.Error() != errMsg {
t.Errorf("Expected error msg: %q, got: %v", errMsg, err)
}
// Check that there is an error if the SequenceHeaderLength doesn't match actual sequence header length
copy(raw, data)
// Change sequence header length to mismatch (at bytes 9-10, after 8-byte header and 1-byte version)
raw[10] = 10 // Change length from 4 to 10, but sequence header is still 4 bytes
_, err = mp4.DecodeBox(0, bytes.NewBuffer(raw))
if err == nil {
t.Error("Expected error for mismatched sequence header length")
}
// Check that there is an error if the box is too short
tooShortSize := uint32(11) // Less than 12 bytes
changeBoxSizeAndAssertError(t, data, 0, tooShortSize, "decode av3c pos 0: box too short < 12 bytes")
}
func TestAvs3ConfigurationWithEmptySequenceHeader(t *testing.T) {
// Test with empty sequence header
avs3Config := &mp4.Av3cBox{
Avs3Config: mp4.Avs3DecoderConfigurationRecord{
ConfigurationVersion: 1,
SequenceHeaderLength: 0,
SequenceHeader: nil,
LibraryDependencyIDC: 1,
},
}
boxDiffAfterEncodeAndDecode(t, avs3Config)
}
func TestAvs3ConfigurationReservedBitsValidation(t *testing.T) {
testCases := []struct {
name string
libDepValue uint8
shouldPass bool
}{
{"Valid LibraryDependencyIDC 0", 0xFC, true}, // 11111100 (reserved bits + 0)
{"Valid LibraryDependencyIDC 1", 0xFD, true}, // 11111101 (reserved bits + 1)
{"Valid LibraryDependencyIDC 2", 0xFE, true}, // 11111110 (reserved bits + 2)
{"Valid LibraryDependencyIDC 3", 0xFF, true}, // 11111111 (reserved bits + 3)
{"Invalid reserved bits", 0x02, false}, // 00000010 (wrong reserved bits)
{"Invalid reserved bits", 0x7E, false}, // 01111110 (wrong reserved bits)
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Create minimal valid box data
data := []byte{
// Box header (8 bytes)
0x00, 0x00, 0x00, 0x0C, // size = 12
'a', 'v', '3', 'c', // type
// Box payload (4 bytes)
0x01, // ConfigurationVersion
0x00, 0x00, // SequenceHeaderLength = 0
tc.libDepValue, // LibraryDependencyIDC with reserved bits
}
_, err := mp4.DecodeBox(0, bytes.NewBuffer(data))
if tc.shouldPass && err != nil {
t.Errorf("Expected no error for valid reserved bits, got: %v", err)
} else if !tc.shouldPass && err == nil {
t.Errorf("Expected error for invalid reserved bits")
}
})
}
}
func TestAvs3ConfigurationInfo(t *testing.T) {
// Create a sample Av3cBox with sequence header data
avs3Config := &mp4.Av3cBox{
Avs3Config: mp4.Avs3DecoderConfigurationRecord{
ConfigurationVersion: 1,
SequenceHeaderLength: 4,
SequenceHeader: []byte{0xAB, 0xCD, 0xEF, 0x12},
LibraryDependencyIDC: 2,
},
}
// Test basic info (level 0)
var buf bytes.Buffer
err := avs3Config.Info(&buf, "", "", " ")
if err != nil {
t.Error(err)
}
// Should contain basic information
expectedBasic := []string{
"configurationVersion: 1",
"sequenceHeaderLength: 4",
"libraryDependencyIDC: 2",
}
for _, expected := range expectedBasic {
if !bytes.Contains(buf.Bytes(), []byte(expected)) {
t.Errorf("Basic info missing expected string: %s", expected)
}
}
// Should NOT contain sequence header at level 0
if bytes.Contains(buf.Bytes(), []byte("sequenceHeader:")) {
t.Error("Basic info should not contain sequence header")
}
// Test detailed info (level 1)
buf.Reset()
err = avs3Config.Info(&buf, "av3c:1", "", " ")
if err != nil {
t.Error(err)
}
// Should contain sequence header in hex at level 1
if !bytes.Contains(buf.Bytes(), []byte("sequenceHeader: abcdef12")) {
t.Error("Detailed info should contain sequence header in hex format")
}
}