psi: wrote first tests, for simple pat and pmt tables. Pat writing seems to be working

This commit is contained in:
saxon 2018-12-11 14:52:18 +10:30
parent 43abed9522
commit a5fa6bed5f
2 changed files with 42 additions and 33 deletions

View File

@ -20,7 +20,7 @@ var (
// syntax section
0x00, 0x01, // table id extension
0xc1, // reserved bits:3|version:5|use now:1 1100 0001
0xc1, // reserved bits:2|version:5|use now:1 1100 0001
0x00, // section number
0x00, // last section number
// table data
@ -141,12 +141,7 @@ func ReadPSI(data []byte) *PSI {
pos := 0
psi.Pf = data[pos]
if psi.Pf != 0 {
psi.Pfb = make([]byte, 0, psi.Pf)
pos++
for i := 0; i < int(psi.Pf); i++ {
psi.Pfb = append(psi.Pfb, data[pos])
pos++
}
panic("No support for pointer filler bytes")
}
psi.Tid = data[pos]
pos++
@ -242,17 +237,16 @@ func readEssd(data []byte) *ESSD {
// Bytes outputs a byte slice representation of the PSI
func (p *PSI) Bytes() []byte {
l := 1 + len(p.Pfb)
out := make([]byte, l+PSIDefLen)
out := make([]byte, 4)
out[0] = p.Pf
for i, b := range p.Pfb {
out[1+i] = b
if p.Pf != 0 {
panic("No support for pointer filler bytes")
}
out[l] = p.Tid
out[l+1] = 0x80 | 0x40 | 0x30 | (0x03 & byte(p.Sl>>8))
out[l+2] = byte(p.Sl)
out[1] = p.Tid
out[2] = 0x80 | 0x30 | (0x03 & byte(p.Sl>>8))
out[3] = byte(p.Sl)
out = append(out, p.Tss.Bytes()...)
crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[l:])
crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[3:])
out = append(out, make([]byte, 0, 4)...)
out = append(out, byte(crc32>>24))
out = append(out, byte(crc32>>16))

View File

@ -1,6 +1,7 @@
package psi
import (
"bytes"
"testing"
)
@ -19,34 +20,48 @@ var (
Lsn: 0,
Sd: &PAT{
Pn: uint16(0x01),
Pmpid: 16,
Pmpid: uint16(0x1000),
},
},
}
pmtPsi = PSI{
Pf: 0x00,
Pf: 0x00,
Tid: 0x02,
Ssi: true,
Sl: uint16(0x12),
Tss: & TSS{
Sl: uint16(0x12),
Tss: &TSS{
Tide: uint16(0x01),
V:0,
Cni: true,
Sn: 0,
Lsn: 0,
V: 0,
Cni: true,
Sn: 0,
Lsn: 0,
Sd: &PMT{
Pcrpid: 16, // wrong
Pil: 0,
Pcrpid: 0x1100, // wrong
Pil: 0,
Essd: &ESSD{
St: 0x1b,
}
}
}
}
St: 0x1b,
Epid: 0x0100,
Esil: 0x00,
},
},
},
}
)
func TestReadPSI1(t *testing.T) {
func TestWritePAT1(t *testing.T) {
got := patPsi.Bytes()
// Remove crc32
got = got[:len(got)-4]
if !bytes.Equal(StdPat, got[:len(got)-4]) {
t.Errorf("Incorrect output, wanted: %v, got: %v", StdPat, got)
}
}
func TestWritePMT1(t *testing.T) {
got := pmtPsi.Bytes()
// Remove crc32
got = got[:len(got)-4]
if !bytes.Equal(StdPmt, got[:len(got)-4]) {
t.Errorf("Incorrect output, wanted: %v, got: %v", StdPmt, got)
}
}