-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_test.go
160 lines (146 loc) · 3.97 KB
/
stream_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package doge
import (
"bytes"
"testing"
)
func TestStreamBytes(t *testing.T) {
stream := NewStream(hx2b("01020304"))
if !bytes.Equal(stream.Bytes(4), hx2b("01020304")) {
t.Errorf("Bytes: wrong value: %x", stream.Bytes(2))
}
if !stream.Complete() {
t.Errorf("Bytes: stream not complete")
}
}
func TestStreamUint16le(t *testing.T) {
stream := NewStream(hx2b("0102"))
if stream.Uint16le() != 0x0201 {
t.Errorf("Uint16le: wrong value: %x", stream.Uint16le())
}
if !stream.Complete() {
t.Errorf("Uint16le: stream not complete")
}
}
func TestStreamUint32le(t *testing.T) {
stream := NewStream(hx2b("01020304"))
if stream.Uint32le() != 0x04030201 {
t.Errorf("Uint32le: wrong value: %x", stream.Uint32le())
}
if !stream.Complete() {
t.Errorf("Uint32le: stream not complete")
}
}
func TestStreamUint64le(t *testing.T) {
stream := NewStream(hx2b("0102030405060708"))
if stream.Uint64le() != 0x0807060504030201 {
t.Errorf("Uint64le: wrong value: %x", stream.Uint64le())
}
if !stream.Complete() {
t.Errorf("Uint64le: stream not complete")
}
}
func TestStreamVarUint(t *testing.T) {
// Test VarUint with 1 byte
stream := NewStream(hx2b("01"))
if stream.VarUint() != 0x01 {
t.Errorf("VarUint: wrong value: %x", stream.VarUint())
}
if !stream.Complete() {
t.Errorf("VarUint: stream not complete")
}
}
func TestStreamVarUint2(t *testing.T) {
// Test VarUint with 2 bytes
stream := NewStream(hx2b("FD0102"))
if stream.VarUint() != 0x0201 {
t.Errorf("VarUint: wrong value: %x", stream.VarUint())
}
if !stream.Complete() {
t.Errorf("VarUint: stream not complete")
}
}
func TestStreamVarUint3(t *testing.T) {
// Test VarUint with 4 bytes
stream := NewStream(hx2b("FE01020304"))
if stream.VarUint() != 0x04030201 {
t.Errorf("VarUint: wrong value: %x", stream.VarUint())
}
if !stream.Complete() {
t.Errorf("VarUint: stream not complete")
}
}
func TestStreamVarUint4(t *testing.T) {
// Test VarUint with 8 bytes
stream := NewStream(hx2b("FF0102030405060708"))
if stream.VarUint() != 0x0807060504030201 {
t.Errorf("VarUint: wrong value: %x", stream.VarUint())
}
if !stream.Complete() {
t.Errorf("VarUint: stream not complete")
}
}
func TestOverrunBytes(t *testing.T) {
// Test overrun of bytes
stream := NewStream(hx2b("01020304"))
if stream.Bytes(5) != nil {
t.Errorf("Bytes: should return nil for overrun")
}
if stream.Valid() {
t.Errorf("Bytes: stream should not be valid for overrun")
}
if stream.Complete() {
t.Errorf("Bytes: stream should not be complete for overrun")
}
}
func TestOverrunUint16le(t *testing.T) {
// Test overrun of Uint16le
stream := NewStream(hx2b("01"))
if stream.Uint16le() != 0 {
t.Errorf("Uint16le: stream should return 0 for overrun")
}
if stream.Valid() {
t.Errorf("Uint16le: stream should not be valid for overrun")
}
if stream.Complete() {
t.Errorf("Uint16le: stream should not be complete for overrun")
}
}
func TestOverrunUint32le(t *testing.T) {
// Test overrun of Uint32le
stream := NewStream(hx2b("010203"))
if stream.Uint32le() != 0 {
t.Errorf("Uint32le: stream should return 0 for overrun")
}
if stream.Valid() {
t.Errorf("Uint32le: stream should not be valid for overrun")
}
if stream.Complete() {
t.Errorf("Uint32le: stream should not be complete for overrun")
}
}
func TestOverrunUint64le(t *testing.T) {
// Test overrun of Uint64le
stream := NewStream(hx2b("01020304050607"))
if stream.Uint64le() != 0 {
t.Errorf("Uint64le: stream should return 0 for overrun")
}
if stream.Valid() {
t.Errorf("Uint64le: stream should not be valid for overrun")
}
if stream.Complete() {
t.Errorf("Uint64le: stream should not be complete for overrun")
}
}
func TestOverrunVarUint(t *testing.T) {
// Test overrun of VarUint
stream := NewStream([]byte{})
if stream.VarUint() != 0 {
t.Errorf("VarUint: should return 0 for overrun")
}
if stream.Valid() {
t.Errorf("VarUint: stream should not be valid for overrun")
}
if stream.Complete() {
t.Errorf("VarUint: stream should not be complete for overrun")
}
}