From cd9ef96648b372ac90517a4d62c4f19f976f2dbe Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 5 Apr 2019 15:46:05 +1030 Subject: [PATCH] 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. --- protocol/rtp/parse_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/protocol/rtp/parse_test.go b/protocol/rtp/parse_test.go index be521a3b..64be4ece 100644 --- a/protocol/rtp/parse_test.go +++ b/protocol/rtp/parse_test.go @@ -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) } } + +// 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") + } +}