-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebml_test.go
69 lines (67 loc) · 1.45 KB
/
ebml_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ebml
import (
"bytes"
"github.com/coding-socks/ebml/schema"
"io"
"testing"
)
func TestReadElementID(t *testing.T) {
type args struct {
r io.Reader
maxIDLength uint
}
tests := []struct {
name string
args args
want schema.ElementID
wantErr bool
}{
{
name: "1 byte",
args: args{r: bytes.NewReader([]byte{0x81}), maxIDLength: 8},
want: 0x81,
},
{
name: "2 byte",
args: args{r: bytes.NewReader([]byte{0x41, 0x11}), maxIDLength: 8},
want: 0x4111,
},
{
name: "early EOF",
args: args{r: bytes.NewReader([]byte{}), maxIDLength: 8},
wantErr: true,
},
{
name: "early EOF",
args: args{r: bytes.NewReader([]byte{0x41}), maxIDLength: 8},
wantErr: true,
},
{
name: "invalid length",
args: args{r: bytes.NewReader([]byte{0x41, 0x11}), maxIDLength: 1},
wantErr: true,
},
{
name: "all one",
args: args{r: bytes.NewReader([]byte{0xff}), maxIDLength: 8},
wantErr: true,
},
{
name: "all one",
args: args{r: bytes.NewReader([]byte{0x7f, 0xff}), maxIDLength: 8},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _, err := ReadElementID(tt.args.r, tt.args.maxIDLength)
if (err != nil) != tt.wantErr {
t.Errorf("ReadElementID() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("ReadElementID() got = %v, want %v", got, tt.want)
}
})
}
}