container/mts/mpegts_test.go: added some more interesting test cases for FindPSI

This commit is contained in:
Saxon 2019-08-05 14:11:28 +09:30
parent 4e43f0f444
commit 0cb9a50af8
1 changed files with 51 additions and 23 deletions

View File

@ -574,6 +574,32 @@ func TestFindPSI(t *testing.T) {
err: nil,
},
},
{
pkts: []int{media, pat, pmt, media, media},
meta: "1",
want: want{
idx: 188,
streamType: gotspsi.PmtStreamTypeMpeg4Video,
streamPID: 4,
meta: map[string]string{
"key": "1",
},
err: nil,
},
},
{
pkts: []int{pat, media, pmt, media, media},
meta: "1",
want: want{
idx: 0,
streamType: gotspsi.PmtStreamTypeMpeg4Video,
streamPID: 4,
meta: map[string]string{
"key": "1",
},
err: ErrNotConsecutive,
},
},
}
var clip bytes.Buffer
@ -693,35 +719,37 @@ func TestFindPSI(t *testing.T) {
t.Errorf("did not get expected error for test %d\nGot: %v\nWant: %v\n", i, gotErr, test.want.err)
}
// Check idx
if gotIdx != test.want.idx {
t.Errorf("did not get expected idx for test %d\nGot: %v\nWant: %v\n", i, gotIdx, test.want.idx)
}
if gotErr == nil {
// Check idx
if gotIdx != test.want.idx {
t.Errorf("did not get expected idx for test %d\nGot: %v\nWant: %v\n", i, gotIdx, test.want.idx)
}
// Check stream type and PID
if gotStreams == nil {
t.Fatalf("gotStreams should not be nil")
}
// Check stream type and PID
if gotStreams == nil {
t.Fatalf("gotStreams should not be nil")
}
if len(gotStreams) == 0 {
t.Fatalf("gotStreams should not be 0 length")
}
if len(gotStreams) == 0 {
t.Fatalf("gotStreams should not be 0 length")
}
s := gotStreams[0]
gotStreamType := s.StreamType()
gotStreamPID := s.ElementaryPid()
s := gotStreams[0]
gotStreamType := s.StreamType()
gotStreamPID := s.ElementaryPid()
if gotStreamType != test.want.streamType {
t.Errorf("did not get expected stream type for test %d\nGot: %v\nWant: %v\n", i, gotStreamType, test.want.streamType)
}
if gotStreamType != test.want.streamType {
t.Errorf("did not get expected stream type for test %d\nGot: %v\nWant: %v\n", i, gotStreamType, test.want.streamType)
}
if gotStreamPID != test.want.streamPID {
t.Errorf("did not get expected stream PID for test %d\nGot: %v\nWant: %v\n", i, gotStreamPID, test.want.streamPID)
}
if gotStreamPID != test.want.streamPID {
t.Errorf("did not get expected stream PID for test %d\nGot: %v\nWant: %v\n", i, gotStreamPID, test.want.streamPID)
}
// Check meta
if !reflect.DeepEqual(gotMeta, test.want.meta) {
t.Errorf("did not get expected meta for test %d\nGot: %v\nWant: %v\n", i, gotMeta, test.want.meta)
// Check meta
if !reflect.DeepEqual(gotMeta, test.want.meta) {
t.Errorf("did not get expected meta for test %d\nGot: %v\nWant: %v\n", i, gotMeta, test.want.meta)
}
}
}
}