From 0cb9a50af81700b86ea977f514111e4a28924302 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 5 Aug 2019 14:11:28 +0930 Subject: [PATCH] container/mts/mpegts_test.go: added some more interesting test cases for FindPSI --- container/mts/mpegts_test.go | 74 +++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/container/mts/mpegts_test.go b/container/mts/mpegts_test.go index e801d6f1..791d9de5 100644 --- a/container/mts/mpegts_test.go +++ b/container/mts/mpegts_test.go @@ -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) + } } } }