MCPcopy Index your code
hub / github.com/Monibuca/engine / TestBits

Function TestBits

util/bits/bits_test.go:8–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestBits(t *testing.T) {
9 rdata := []byte{0xf3, 0xb3, 0x45, 0x60}
10 rbuf := bytes.NewReader(rdata[:])
11 r := &Reader{R: rbuf}
12 var u32 uint
13 if u32, _ = r.ReadBits(4); u32 != 0xf {
14 t.FailNow()
15 }
16 if u32, _ = r.ReadBits(4); u32 != 0x3 {
17 t.FailNow()
18 }
19 if u32, _ = r.ReadBits(2); u32 != 0x2 {
20 t.FailNow()
21 }
22 if u32, _ = r.ReadBits(2); u32 != 0x3 {
23 t.FailNow()
24 }
25 b := make([]byte, 2)
26 if r.Read(b); b[0] != 0x34 || b[1] != 0x56 {
27 t.FailNow()
28 }
29
30 wbuf := &bytes.Buffer{}
31 w := &Writer{W: wbuf}
32 w.WriteBits(0xf, 4)
33 w.WriteBits(0x3, 4)
34 w.WriteBits(0x2, 2)
35 w.WriteBits(0x3, 2)
36 n, _ := w.Write([]byte{0x34, 0x56})
37 if n != 2 {
38 t.FailNow()
39 }
40 w.FlushBits()
41 wdata := wbuf.Bytes()
42 if wdata[0] != 0xf3 || wdata[1] != 0xb3 || wdata[2] != 0x45 || wdata[3] != 0x60 {
43 t.FailNow()
44 }
45
46 b = make([]byte, 8)
47 PutUInt64BE(b, 0x11223344)
48 if b[0] != 0x11 || b[1] != 0x22 || b[2] != 0x33 || b[3] != 0x44 {
49 t.FailNow()
50 }
51}
52func PutUInt64BE(b []byte, v uint64) {
53 b[0] = byte(v >> 56)
54 b[1] = byte(v >> 48)

Callers

nothing calls this directly

Calls 8

ReadBitsMethod · 0.95
ReadMethod · 0.95
WriteBitsMethod · 0.95
WriteMethod · 0.95
FlushBitsMethod · 0.95
BytesMethod · 0.95
PutUInt64BEFunction · 0.85
NewReaderMethod · 0.45

Tested by

no test coverage detected