Debian Codegraph @

util_test.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcp
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestGetPadding(t *testing.T) {
13 assert := assert.New(t)
14 type testCase struct {
15 input int
16 result int
17 }
18
19 cases := []testCase{
20 {input: 0, result: 0},
21 {input: 1, result: 3},
22 {input: 2, result: 2},
23 {input: 3, result: 1},
24 {input: 4, result: 0},
25 {input: 100, result: 0},
26 {input: 500, result: 0},
27 }
28 for _, testCase := range cases {
29 assert.Equalf(
30 getPadding(testCase.input), testCase.result, "Test case returned wrong value for input %d", testCase.input,
31 )
32 }
33 }
34
35 func TestSetNBitsOfUint16(t *testing.T) {
36 for _, test := range []struct {
37 name string
38 source uint16
39 size uint16
40 index uint16
41 value uint16
42 result uint16
43 expectedErr error
44 }{
45 {
46 "setOneBit", 0, 1, 8, 1, 128, nil,
47 },
48 {
49 "setStatusVectorBit", 0, 1, 0, 1, 32768, nil,
50 },
51 {
52 "setStatusVectorSecondBit", 32768, 1, 1, 1, 49152, nil,
53 },
54 {
55 "setStatusVectorInnerBitsAndCutValue", 49152, 2, 6, 11111, 49920, nil,
56 },
57 {
58 "setRunLengthSecondTwoBit", 32768, 2, 1, 1, 40960, nil,
59 },
60 {
61 "setOneBitOutOfBounds", 32768, 2, 15, 1, 0, errInvalidSizeOrStartIndex,
62 },
63 } {
64 t.Run(test.name, func(t *testing.T) {
65 got, err := setNBitsOfUint16(test.source, test.size, test.index, test.value)
66 if test.expectedErr != nil {
67 assert.ErrorIs(t, err, test.expectedErr)
68 } else {
69 assert.NoError(t, err)
70 }
71
72 assert.Equalf(t, test.result, got, "setNBitsOfUint16 %q", test.name)
73 })
74 }
75 }