-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbyte_test.go
More file actions
50 lines (46 loc) · 1.16 KB
/
cbyte_test.go
File metadata and controls
50 lines (46 loc) · 1.16 KB
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 cbyte
import (
"bytes"
"testing"
)
var t__ = []byte(`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur luctus sapien eu velit sodales laoreet. Vestibulum laoreet in ex vel faucibus. Praesent in nibh arcu. In justo velit, ultricies id consequat in, porta volutpat mauris. Maecenas porttitor, mi sed condimentum pretium, enim nisl scelerisque nibh, eget tincidunt orci risus nec velit.`)
func TestCbyte(t *testing.T) {
t.Run("init", func(t *testing.T) {
h := InitHeader(64, 64)
if h.Cap != 64 {
t.Fail()
}
ReleaseHeader(h)
})
t.Run("grow", func(t *testing.T) {
h := InitHeader(0, 64)
h.Cap = 2048
h.Data = uintptr(Grow(uint64(h.Data), 64, 2048))
if cap(Bytes(h)) != 2048 {
t.Fail()
}
ReleaseHeader(h)
})
t.Run("memcpy", func(t *testing.T) {
h := InitHeader(512, 512)
n := Memcpy(uint64(h.Data), 16, t__)
if n != len(t__) {
t.Fail()
}
b := Bytes(h)
if !bytes.Equal(t__, b[16:len(t__)+16]) {
t.Fail()
}
ReleaseHeader(h)
})
}
func BenchmarkCbyte(b *testing.B) {
b.Run("memcpy", func(b *testing.B) {
b.ReportAllocs()
h := Init(512)
for i := 0; i < b.N; i++ {
Memcpy(h, 0, t__)
}
Release(h)
})
}