av/codec/h264/h264dec/slice_test.go

126 lines
3.2 KiB
Go
Raw Normal View History

/*
DESCRIPTION
slice_test.go provides testing for parsing utilities found in slice.go.
AUTHORS
Saxon Nelson-Milton <saxon@ausocean.org>, The Australian Ocean Laboratory (AusOcean)
Shawn Smith <shawn@ausocean.org>, The Australian Ocean Laboratory (AusOcean)
*/
package h264dec
import (
"bytes"
"reflect"
"testing"
"bitbucket.org/ausocean/av/codec/h264/h264dec/bits"
)
var subWidthCTests = []struct {
in SPS
want int
}{
{SPS{}, 17},
{SPS{ChromaFormat: 0}, 17},
{SPS{ChromaFormat: 1}, 2},
{SPS{ChromaFormat: 2}, 2},
{SPS{ChromaFormat: 3}, 1},
{SPS{ChromaFormat: 3, UseSeparateColorPlane: true}, 17},
{SPS{ChromaFormat: 999}, 17},
}
// TestSubWidthC tests that the correct SubWidthC is returned given
// SPS inputs with various chroma formats.
func TestSubWidthC(t *testing.T) {
for _, tt := range subWidthCTests {
if got := SubWidthC(&tt.in); got != tt.want {
t.Errorf("SubWidthC(%#v) = %d, want %d", tt.in, got, tt.want)
}
}
}
var subHeightCTests = []struct {
in SPS
want int
}{
{SPS{}, 17},
{SPS{ChromaFormat: 0}, 17},
{SPS{ChromaFormat: 1}, 2},
{SPS{ChromaFormat: 2}, 1},
{SPS{ChromaFormat: 3}, 1},
{SPS{ChromaFormat: 3, UseSeparateColorPlane: true}, 17},
{SPS{ChromaFormat: 999}, 17},
}
// TestSubHeightC tests that the correct SubHeightC is returned given
// SPS inputs with various chroma formats.
func TestSubHeightC(t *testing.T) {
for _, tt := range subHeightCTests {
if got := SubHeightC(&tt.in); got != tt.want {
t.Errorf("SubHeight(%#v) = %d, want %d", tt.in, got, tt.want)
}
}
}
func TestNewRefPicListModification(t *testing.T) {
tests := []struct {
in string
s SliceHeader
p PPS
want RefPicListModification
}{
{
in: "1" + // u(1) ref_pic_list_modification_flag_l0=true
// First modification for list0
"1" + // ue(v) modification_of_pic_nums_idc[0][0] = 0
"010" + // ue(v) abs_diff_pic_num_minus1[0][0] = 1
// Second modification for list0
"010" + // ue(v) modification_of_pic_nums_idc[0][1] = 1
"011" + // ue(v) abs_diff_pic_num_minus1[0][1] = 2
// Third modification for list0
"011" + // ue(v) modification_of_pic_nums_idc[0][2] = 2
"010" + // ue(v) long_term_pic_num = 1
// Fourth modification does not exist
"00100" + // ue(v) modification_of_pic_nums_idc[0][3] = 3
// Padding bits
"00",
s: SliceHeader{
SliceType: 3,
},
p: PPS{
NumRefIdxL0DefaultActiveMinus1: 2,
},
want: RefPicListModification{
RefPicListModificationFlag: [2]bool{true, false},
ModificationOfPicNums: [2][]int{{0, 1, 2, 3}, {0, 0}},
AbsDiffPicNumMinus1: [2][]int{{1, 2, 0, 0}, {0, 0}},
LongTermPicNum: [2][]int{{0, 0, 1, 0}, {0, 0}},
},
},
}
for i, test := range tests {
inBytes, err := binToSlice(test.in)
if err != nil {
t.Fatalf("unexpected error %v for binToSlice in test %d", err, i)
}
got, err := NewRefPicListModification(bits.NewBitReader(bytes.NewReader(inBytes)), &test.p, &test.s)
if err != nil {
t.Fatalf("unexpected error %v for NewRefPicListModification in test %d", err, i)
}
if !reflect.DeepEqual(*got, test.want) {
t.Errorf("did not get expected result for test %d\nGot: %v\nWant: %v\n", i, got, test.want)
}
}
}