package h264dec import ( "bytes" "reflect" "testing" "bitbucket.org/ausocean/av/codec/h264/h264dec/bits" ) func TestNewMVCExtension(t *testing.T) { tests := []struct { in string want MVCExtension err error }{ { in: "0" + // u(1) non_idr_flag = false "00 0010" + // u(6) priority_id = 2 "00 0001 1000" + // u(10) view_id = 24 "100" + // u(3) temporal_id = 4 "1" + // u(1) anchor_pic_flag = true "0" + // u(1) inter_view_flag = false "1", // u(1) reserved_one_bit = 1 want: MVCExtension{ NonIdrFlag: false, PriorityID: 2, ViewID: 24, TemporalID: 4, AnchorPicFlag: true, InterViewFlag: false, ReservedOneBit: 1, }, }, } for i, test := range tests { inBytes, err := binToSlice(test.in) if err != nil { t.Fatalf("did not expect error %v from binToSlice for test %d", err, i) } got, err := NewMVCExtension(bits.NewBitReader(bytes.NewReader(inBytes))) if err != test.err { t.Errorf("did not get expected error for test %d\nGot: %v\nWant: %v\n", i, err, test.err) } 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) } } } func TestNewThreeDAVCExtension(t *testing.T) { tests := []struct { in string want ThreeDAVCExtension err error }{ { in: "0001 0000" + // u(8) view_idx = 16 "1" + // u(1) depth_flag = true "0" + // u(1) non_idr_flag = false "010" + // u(1) temporal_id = 2 "1" + // u(1) anchor_pic_flag = true "1", // u(1) inter_view_flag = true want: ThreeDAVCExtension{ ViewIdx: 16, DepthFlag: true, NonIdrFlag: false, TemporalID: 2, AnchorPicFlag: true, InterViewFlag: true, }, }, } for i, test := range tests { inBytes, err := binToSlice(test.in) if err != nil { t.Fatalf("did not expect error %v from binToSlice for test %d", err, i) } got, err := NewThreeDAVCExtension(bits.NewBitReader(bytes.NewReader(inBytes))) if err != test.err { t.Errorf("did not get expected error for test %d\nGot: %v\nWant: %v\n", i, err, test.err) } 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) } } }