2019-01-14 03:02:49 +00:00
|
|
|
package streaming
|
|
|
|
|
2019-01-16 02:53:13 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
2019-01-14 03:02:49 +00:00
|
|
|
|
|
|
|
func TestBitReader(t *testing.T) {
|
2019-01-16 02:53:13 +00:00
|
|
|
data := []byte{
|
|
|
|
0x69, // 01101001
|
|
|
|
0x96, // 10010110
|
|
|
|
0xf0, // 11110000
|
|
|
|
0xaa, // 10101010
|
|
|
|
0x00, // 00000000
|
|
|
|
0xff, // 11111111
|
|
|
|
}
|
2019-01-14 03:02:49 +00:00
|
|
|
|
2019-01-23 02:49:23 +00:00
|
|
|
r := NewBitReader(bytes.NewReader(data))
|
2019-01-16 03:44:02 +00:00
|
|
|
|
|
|
|
readPass := func(c int, v uint64) {
|
2019-01-24 04:06:32 +00:00
|
|
|
if value, err := r.ReadUint64(c); value != v || err != nil {
|
2019-01-16 03:44:02 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readFail := func(c int) {
|
2019-01-24 04:06:32 +00:00
|
|
|
if value, err := r.ReadUint64(c); value != 0 || err == nil {
|
2019-01-16 03:44:02 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readPass(0, 0x00)
|
|
|
|
readPass(2, 0x01)
|
|
|
|
readPass(2, 0x02)
|
|
|
|
readPass(3, 0x04)
|
|
|
|
readPass(1, 0x01)
|
|
|
|
readPass(12, 0x096f)
|
|
|
|
readPass(8, 0x000a)
|
|
|
|
readPass(20, 0x0a00ff)
|
|
|
|
readFail(1)
|
2019-01-14 03:02:49 +00:00
|
|
|
}
|