1
1
package hevc
2
2
3
3
import (
4
+ "strings"
4
5
"testing"
5
6
6
7
"github.com/go-test/deep"
7
8
)
8
9
9
10
func TestGetNaluTypes (t * testing.T ) {
10
11
testCases := []struct {
11
- name string
12
- input []byte
13
- wanted []NaluType
12
+ name string
13
+ input []byte
14
+ wanted []NaluType
15
+ nalusUpToFirstVideo []NaluType
16
+ containsVPS bool
17
+ isRapSample bool
18
+ isIDRSample bool
14
19
}{
15
20
{
16
21
"AUD" ,
17
22
[]byte {0 , 0 , 0 , 2 , 70 , 0 },
18
23
[]NaluType {NALU_AUD },
24
+ []NaluType {NALU_AUD },
25
+ false ,
26
+ false ,
27
+ false ,
19
28
},
20
29
{
21
30
"AUD, VPS, SPS, PPS, and IDR " ,
@@ -26,14 +35,45 @@ func TestGetNaluTypes(t *testing.T) {
26
35
0 , 0 , 0 , 3 , 68 , 3 , 3 ,
27
36
0 , 0 , 0 , 3 , 40 , 4 , 4 },
28
37
[]NaluType {NALU_AUD , NALU_VPS , NALU_SPS , NALU_PPS , NALU_IDR_N_LP },
38
+ []NaluType {NALU_AUD , NALU_VPS , NALU_SPS , NALU_PPS , NALU_IDR_N_LP },
39
+ true ,
40
+ true ,
41
+ true ,
42
+ },
43
+ {
44
+ "too short" ,
45
+ []byte {0 , 0 , 0 },
46
+ []NaluType {},
47
+ []NaluType {},
48
+ false ,
49
+ false ,
50
+ false ,
29
51
},
30
52
}
31
53
32
54
for _ , tc := range testCases {
33
- got := FindNaluTypes (tc .input )
34
- if diff := deep .Equal (got , tc .wanted ); diff != nil {
35
- t .Errorf ("%s: %v" , tc .name , diff )
36
- }
55
+ t .Run (tc .name , func (t * testing.T ) {
56
+ got := FindNaluTypes (tc .input )
57
+ if diff := deep .Equal (got , tc .wanted ); diff != nil {
58
+ t .Errorf ("nalulist diff: %v" , diff )
59
+ }
60
+ got = FindNaluTypesUpToFirstVideoNalu (tc .input )
61
+ if diff := deep .Equal (got , tc .nalusUpToFirstVideo ); diff != nil {
62
+ t .Errorf ("nalus before first video diff: %v" , diff )
63
+ }
64
+ hasVPS := ContainsNaluType (tc .input , NALU_VPS )
65
+ if hasVPS != tc .containsVPS {
66
+ t .Errorf ("got %t instead of %t" , hasVPS , tc .containsVPS )
67
+ }
68
+ isRAP := IsRAPSample (tc .input )
69
+ if isRAP != tc .isRapSample {
70
+ t .Errorf ("got %t instead of %t" , isRAP , tc .isRapSample )
71
+ }
72
+ isIDR := IsIDRSample (tc .input )
73
+ if isIDR != tc .isIDRSample {
74
+ t .Errorf ("got %t instead of %t" , isIDR , tc .isIDRSample )
75
+ }
76
+ })
37
77
}
38
78
}
39
79
@@ -61,10 +101,12 @@ func TestHasParameterSets(t *testing.T) {
61
101
}
62
102
63
103
for _ , tc := range testCases {
64
- got := HasParameterSets (tc .input )
65
- if got != tc .wanted {
66
- t .Errorf ("%s: got %t instead of %t" , tc .name , got , tc .wanted )
67
- }
104
+ t .Run (tc .name , func (t * testing.T ) {
105
+ got := HasParameterSets (tc .input )
106
+ if got != tc .wanted {
107
+ t .Errorf ("got %t instead of %t" , got , tc .wanted )
108
+ }
109
+ })
68
110
}
69
111
}
70
112
@@ -96,15 +138,30 @@ func TestGetParameterSets(t *testing.T) {
96
138
}
97
139
98
140
for _ , tc := range testCases {
99
- gotVPS , gotSPS , gotPPS := GetParameterSets (tc .input )
100
- if diff := deep .Equal (gotVPS , tc .wantedVPS ); diff != nil {
101
- t .Errorf ("%s VPS: %v" , tc .name , diff )
102
- }
103
- if diff := deep .Equal (gotSPS , tc .wantedSPS ); diff != nil {
104
- t .Errorf ("%s SPS: %v" , tc .name , diff )
105
- }
106
- if diff := deep .Equal (gotPPS , tc .wantedPPS ); diff != nil {
107
- t .Errorf ("%s PPS: %v" , tc .name , diff )
141
+ t .Run (tc .name , func (t * testing.T ) {
142
+ gotVPS , gotSPS , gotPPS := GetParameterSets (tc .input )
143
+ if diff := deep .Equal (gotVPS , tc .wantedVPS ); diff != nil {
144
+ t .Errorf ("VPS diff: %v" , diff )
145
+ }
146
+ if diff := deep .Equal (gotSPS , tc .wantedSPS ); diff != nil {
147
+ t .Errorf ("SPS diff: %v" , diff )
148
+ }
149
+ if diff := deep .Equal (gotPPS , tc .wantedPPS ); diff != nil {
150
+ t .Errorf ("PPS diff: %v" , diff )
151
+ }
152
+ })
153
+ }
154
+ }
155
+
156
+ func TestNaluTypeStrings (t * testing.T ) {
157
+ named := 0
158
+ for n := NaluType (0 ); n < NaluType (64 ); n ++ {
159
+ desc := n .String ()
160
+ if ! strings .HasPrefix (desc , "Other" ) {
161
+ named ++
108
162
}
109
163
}
164
+ if named != 22 {
165
+ t .Errorf ("got %d named instead of 22" , named )
166
+ }
110
167
}
0 commit comments