File: leb128_test.go

package info (click to toggle)
golang-github-pion-rtp 1.7.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 472 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package obu

import (
	"errors"
	"testing"
)

func TestLEB128(t *testing.T) {
	for _, test := range []struct {
		Value   uint
		Encoded uint
	}{
		{0, 0},
		{5, 5},
		{999999, 0xBF843D},
	} {
		test := test

		encoded := EncodeLEB128(test.Value)
		if encoded != test.Encoded {
			t.Fatalf("Actual(%d) did not equal expected(%d)", encoded, test.Encoded)
		}

		decoded := decodeLEB128(encoded)
		if decoded != test.Value {
			t.Fatalf("Actual(%d) did not equal expected(%d)", decoded, test.Value)
		}
	}
}

func TestReadLeb128(t *testing.T) {
	if _, _, err := ReadLeb128(nil); !errors.Is(err, ErrFailedToReadLEB128) {
		t.Fatal("ReadLeb128 on a nil buffer should return an error")
	}

	if _, _, err := ReadLeb128([]byte{0xFF}); !errors.Is(err, ErrFailedToReadLEB128) {
		t.Fatal("ReadLeb128 on a buffer with all MSB set should fail")
	}
}