MCPcopy
hub / github.com/coocood/freecache / TestRingBuf

Function TestRingBuf

ringbuf_test.go:7–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestRingBuf(t *testing.T) {
8 rb := NewRingBuf(16, 0)
9 for i := 0; i < 2; i++ {
10 rb.Write([]byte("fghibbbbccccddde"))
11 rb.Write([]byte("fghibbbbc"))
12 rb.Resize(16)
13 off := rb.Evacuate(9, 3)
14 t.Log(string(rb.Dump()))
15 if off != rb.End()-3 {
16 t.Log(string(rb.Dump()), rb.End())
17 t.Fatalf("off got %v", off)
18 }
19 off = rb.Evacuate(15, 5)
20 t.Log(string(rb.Dump()))
21 if off != rb.End()-5 {
22 t.Fatalf("off got %v", off)
23 }
24 rb.Resize(64)
25 rb.Resize(32)
26 data := make([]byte, 5)
27 rb.ReadAt(data, off)
28 if string(data) != "efghi" {
29 t.Fatalf("read at should be efghi, got %v", string(data))
30 }
31
32 off = rb.Evacuate(0, 10)
33 if off != -1 {
34 t.Fatal("evacutate out of range offset should return error")
35 }
36
37 /* -- After reset the buffer should behave exactly the same as a new one.
38 * Hence, run the test once more again with reset buffer. */
39 rb.Reset(0)
40 }
41}

Callers

nothing calls this directly

Calls 8

WriteMethod · 0.95
ResizeMethod · 0.95
EvacuateMethod · 0.95
DumpMethod · 0.95
EndMethod · 0.95
ReadAtMethod · 0.95
ResetMethod · 0.95
NewRingBufFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…