av/protocol/rtp/parse_test.go

102 lines
2.6 KiB
Go

/*
NAME
parse_test.go
DESCRIPTION
parse_test.go provides testing for behaviour of functionality in parse.go.
AUTHOR
Saxon A. Nelson-Milton <saxon@ausocean.org>
LICENSE
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
This 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 [GNU licenses](http://www.gnu.org/licenses).
*/
package rtp
import (
"testing"
)
// TestVersion checks that we can correctly get the version from an RTP packet.
func TestVersion(t *testing.T) {
const expect = 1
pkt := (&Pkt{V: expect}).Bytes(nil)
got := version(pkt)
if got != expect {
t.Errorf("unexpected version for RTP packet. Got: %v\n Want: %v\n", got, expect)
}
}
// TestCsrcCount checks that we can correctly obtain the csrc count from an
// RTP packet.
func TestCsrcCount(t *testing.T) {
const ver, expect = 2, 2
pkt := (&Pkt{
V: ver,
CC: expect,
CSRC: make([][4]byte, expect),
}).Bytes(nil)
got := csrcCount(pkt)
if got != expect {
t.Errorf("unexpected csrc count for RTP packet. Got: %v\n Want: %v\n", got, expect)
}
}
// TestHasExt checks the behaviour of hasExt with an RTP packet that has the
// extension indicator true, and one with the extension indicator set to false.
func TestHasExt(t *testing.T) {
const ver = 2
// First check for when there is an extension field.
pkt := &Pkt{
V: ver,
X: true,
Extension: ExtensionHeader{
ID: 0,
Header: make([][4]byte, 0),
},
}
got := hasExt(pkt.Bytes(nil))
if !got {
t.Error("RTP packet did not have true extension indicator as expected")
}
// Now check when there is not an extension field.
pkt.X = false
got = hasExt(pkt.Bytes(nil))
if got {
t.Error("did not expect to have extension indicator as true")
}
}
// TestExtHeaderLen checks for a correct extension header len for an RTP packet.
func TestExtHeaderLen(t *testing.T) {
const ver, expect = 2, 3
pkt := (&Pkt{
V: ver,
X: true,
Extension: ExtensionHeader{
ID: 0,
Header: make([][4]byte, expect),
},
}).Bytes(nil)
got := extHeaderLen(pkt)
if got != expect {
t.Errorf("Unexpected extension header len. Got: %v\n Want: %v\n", got, expect)
}
}