From 015b1f7aa9f3c7fd0a7ceb365845f5b842c48235 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 5 Apr 2019 15:14:32 +1030 Subject: [PATCH] protocol/rtp: wrote TestVersion Wrote test that checks the version func will correctly get the version from an RTP packet. --- protocol/rtp/parse.go | 2 +- protocol/rtp/parse_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/protocol/rtp/parse.go b/protocol/rtp/parse.go index 22a663f8..63e5dc2d 100644 --- a/protocol/rtp/parse.go +++ b/protocol/rtp/parse.go @@ -84,5 +84,5 @@ func csrcCount(d []byte) int { // version returns the version of the RTP packet. func version(d []byte) int { - return int(d[0] & 0xb0 >> 4) + return int(d[0] & 0xc0 >> 6) } diff --git a/protocol/rtp/parse_test.go b/protocol/rtp/parse_test.go index 7c5a03e9..01de123d 100644 --- a/protocol/rtp/parse_test.go +++ b/protocol/rtp/parse_test.go @@ -26,3 +26,17 @@ LICENSE */ 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) + } +}