protocol/rtp: wrote TestHasExt

Wrote test TestHasExt which checks the behaviour of hasExt for when it's call with an
RTP packet with an extension indicator and also for an RTP packet with no extension
indicator.
This commit is contained in:
Saxon 2019-04-05 15:46:05 +10:30
parent c2b67d7fb9
commit 3dc6d7733b
1 changed files with 27 additions and 0 deletions

View File

@ -55,3 +55,30 @@ func TestCsrcCount(t *testing.T) {
t.Errorf("unexpected csrc count for RTP packet. Got: %v\n Want: %v\n", 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")
}
}