av/pes/pes_test.go

86 lines
2.2 KiB
Go
Raw Normal View History

/*
NAME
MpegTs.go - provides a data structure intended to encapsulate the properties
of an MpegTs packet.
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon.milton@gmail.com>
LICENSE
MpegTs.go is Copyright (C) 2017 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
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
package pes
import (
"testing"
)
const (
dataLength = 3 // bytes
)
func TestPesToByteSlice(t *testing.T) {
pesPkt := PESPacket{
byte(0xE0), // StreamID
uint16(6), // Length
byte(0), // ScramblingControl
bool(true), // Priority
bool(false), // DAI
bool(false), // copyright
bool(true), // Original
byte(0), // PDI
bool(false), // Escr
bool(false), // ESRate
bool(false), // DSMTrickMode
bool(false), // ACI
bool(false), // CRC
bool(false), // Ext
byte(0), // header length
[]byte{},
[]byte{},
[]byte{ // data
0xEA,
0x4B,
0x12,
},
}
pesExpectedOutput := []byte{
0x00, // packet start code prefix byte 1
0x00, // packet start code prefix byte 2
0x01, // packet start code prefix byte 3
0xE0, // stream ID
0x00, // PES Packet length byte 1
0x06, // PES packet length byte 2
0x89, // Marker bits,ScramblingControl, Priority, DAI, Copyright, Original
0x00, // PDI, ESCR, ESRate, DSMTrickMode, ACI, CRC, Ext
0x00, // header length
0xEA, // data byte 1
0x4B, // data byte 2
0x12, // data byte 3
}
pesPktAsByteSlice := pesPkt.ToByteSlice()
for ii := range pesPktAsByteSlice {
if pesPktAsByteSlice[ii] != pesExpectedOutput[ii] {
t.Errorf("Conversion to byte slice bad! Byte: %v Wanted: %v Got: %v",
ii, pesExpectedOutput[ii], pesPktAsByteSlice[ii])
}
}
}