forked from TyphoonMC/TyphoonCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer_test.go
64 lines (51 loc) · 1.15 KB
/
buffer_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
package typhoon
import (
"bytes"
"testing"
)
func TestVarBufferAllocation(t *testing.T) {
size := 20
buff := newVarBuffer(size)
if len(buff.buffer) != size {
t.Log("VarBuffer (size =", size, ") created with size", len(buff.buffer))
t.Fail()
}
if buff.used != 0 {
t.Log("VarBuffer started with used bytes")
t.Fail()
}
}
func TestVarBufferWriteWithoutResize(t *testing.T) {
size := 20
buff := newVarBuffer(size)
dataSize := 10
data := make([]byte, dataSize)
buff.Write(data)
if len(buff.buffer) != size {
t.Log("VarBuffer (size =", size, ") write with size", len(buff.buffer))
t.Fail()
}
if buff.used != dataSize {
t.Log("VarBuffer used bytes =", buff.used, " instead of", data)
t.Fail()
}
if !bytes.Equal(data, buff.Bytes()) {
t.Log("VarBuffer corrupted data")
t.Fail()
}
}
func TestVarBufferWriteWithResize(t *testing.T) {
size := 20
buff := newVarBuffer(size)
dataSize := 40
data := make([]byte, dataSize)
buff.Write(data)
if buff.used != dataSize {
t.Log("VarBuffer used bytes =", buff.used, " instead of", data)
t.Fail()
}
if !bytes.Equal(data, buff.Bytes()) {
t.Log("VarBuffer corrupted data")
t.Fail()
}
}