mirror of https://bitbucket.org/ausocean/av.git
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
|
/*
|
||
|
NAME
|
||
|
mpegts_test.go
|
||
|
|
||
|
DESCRIPTION
|
||
|
mpegts_test.go contains testing for functionality found in mpegts.go.
|
||
|
|
||
|
AUTHORS
|
||
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
||
|
|
||
|
LICENSE
|
||
|
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
||
|
|
||
|
It is free software: you can redistribute it and/or modify them
|
||
|
under the terms of the GNU General Public License as published by the
|
||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||
|
option) any later version.
|
||
|
|
||
|
It is distributed in the hope that it will be useful, but WITHOUT
|
||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
|
for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||
|
*/
|
||
|
|
||
|
package mts
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestBytes(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
packet Packet
|
||
|
payloadLen int
|
||
|
stuffingLen int
|
||
|
expectedHeader []byte
|
||
|
}{
|
||
|
{
|
||
|
packet: Packet{
|
||
|
PUSI: true,
|
||
|
PID: 1,
|
||
|
RAI: true,
|
||
|
CC: 4,
|
||
|
AFC: HasPayload | HasAdaptationField,
|
||
|
PCRF: true,
|
||
|
PCR: 1,
|
||
|
},
|
||
|
payloadLen: 120,
|
||
|
stuffingLen: 56,
|
||
|
expectedHeader: []byte{
|
||
|
0x47, // Sync byte.
|
||
|
0x40, // TEI=0, PUSI=1, TP=0, PID=00000.
|
||
|
0x01, // PID(Cont)=00000001.
|
||
|
0x34, // TSC=00, AFC=11(adaptation followed by payload), CC=0100(4).
|
||
|
0x3f, // AFL=.
|
||
|
0x50, // DI=0,RAI=1,ESPI=0,PCRF=1,OPCRF=0,SPF=0,TPDF=0, AFEF=0.
|
||
|
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, // PCR.
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for testNum, test := range tests {
|
||
|
// Construct payload.
|
||
|
const payloadChar = 0x11
|
||
|
payload := make([]byte, 0, test.payloadLen)
|
||
|
for i := 0; i < test.payloadLen; i++ {
|
||
|
payload = append(payload, payloadChar)
|
||
|
}
|
||
|
|
||
|
// Fill the packet payload.
|
||
|
test.packet.FillPayload(payload)
|
||
|
|
||
|
// Create packet data and copy in expected header.
|
||
|
expected := make([]byte, len(test.expectedHeader), PacketSize)
|
||
|
copy(expected, test.expectedHeader)
|
||
|
|
||
|
// Append stuffing.
|
||
|
const stuffingChar = 0xff
|
||
|
for i := 0; i < test.stuffingLen; i++ {
|
||
|
expected = append(expected, stuffingChar)
|
||
|
}
|
||
|
|
||
|
// Copy in payload.
|
||
|
expected = append(expected, payload...)
|
||
|
|
||
|
// Compare got with expected.
|
||
|
got := test.packet.Bytes(nil)
|
||
|
if !bytes.Equal(got, expected) {
|
||
|
t.Errorf("did not get expected result for test: %v.\n Got: %v\n Want: %v\n", testNum, got, expected)
|
||
|
}
|
||
|
}
|
||
|
}
|