Skip to content

Commit

Permalink
data_psi: add test for parsing multiple sections
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Apr 7, 2021
1 parent 9d2253c commit d0a1f65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions data_psi.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func parsePSIData(i *astikit.BytesIterator) (d *PSIData, err error) {
err = fmt.Errorf("astits: parsing PSI table failed: %w", err)
return
}
if stop {
break
}
d.Sections = append(d.Sections, s)
}
return
Expand Down Expand Up @@ -199,8 +202,7 @@ func parseCRC32(i *astikit.BytesIterator) (c uint32, err error) {

// shouldStopPSIParsing checks whether the PSI parsing should be stopped
func shouldStopPSIParsing(tableID PSITableID) bool {
return tableID == PSITableIDNull ||
tableID.isUnknown()
return tableID == PSITableIDNull
}

// parsePSISectionHeader parses a PSI section header
Expand Down Expand Up @@ -241,7 +243,7 @@ func parsePSISectionHeader(i *astikit.BytesIterator) (h *PSISectionHeader, offse
h.PrivateBit = bs[0]&0x40 > 0

// Section length
h.SectionLength = uint16(bs[0]&0xf)<<8 | uint16(bs[1])
h.SectionLength = uint16(bs[0]&3)<<8 | uint16(bs[1])

// Offsets
offsetSectionsStart = i.Offset()
Expand Down
21 changes: 21 additions & 0 deletions data_psi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,27 @@ var psiDataTestCases = []psiDataTestCase{
},
}

func TestParsePSIDataPMTMultipleSections(t *testing.T) {
pmt := hexToBytes(`00C0001500000100FF000000
000000010000000000038D646B02B07B
0001C90000EF9BF02109044749E10B05
04474139348713C1010100F30D01656E
670100000554562D504702EF9BF00E11
01FF1006C0BD62C0080006010281EF9C
F018050441432D33810A083805FF0F01
BF656E670A04656E670081EF9DF01805
0441432D33810A082885FF0001BF7370
610A0473706100082F08E3FFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFF`)
d, err := parsePSIData(astikit.NewBytesIterator(pmt))
assert.NoError(t, err)
assert.NotNil(t, d)
assert.Len(t, d.Sections, 2)
assert.Equal(t, PSITableID(0xc0), d.Sections[0].Header.TableID)
assert.Equal(t, PSITableID(0x02), d.Sections[1].Header.TableID)
}

func TestWritePSIData(t *testing.T) {
for _, tc := range psiDataTestCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit d0a1f65

Please sign in to comment.