-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbyte_reader_test.go
More file actions
50 lines (41 loc) · 938 Bytes
/
byte_reader_test.go
File metadata and controls
50 lines (41 loc) · 938 Bytes
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
package badio
import (
"testing"
)
func TestByteReader(t *testing.T) {
// test bytes reader
for i := 0; i < 0xFF; i++ {
b := make([]byte, 4096)
r := NewByteReader(byte(i))
n, err := r.Read(b)
if err != nil {
t.Fatalf("Error writing 0x%X: %v", i, err)
}
if n != len(b) {
t.Errorf("Expected to read %d bytes, got %d", len(b), n)
}
// validate each byte in the written buffer
for x := 0; x < len(b); x++ {
if b[x] != byte(i) {
t.Fatalf("Expected value at buffer offet %d to have value %d", x, i)
}
}
}
}
func TestNullReader(t *testing.T) {
b := make([]byte, 4096)
r := NewNullReader()
n, err := r.Read(b)
if err != nil {
t.Fatalf("%v", err)
}
if n != len(b) {
t.Errorf("Expected to read %d bytes, got %d", len(b), n)
}
// validate each byte in the written buffer
for x := 0; x < len(b); x++ {
if b[x] != 0 {
t.Fatalf("Expected value at buffer offet %d to be 0", x)
}
}
}