MCPcopy
hub / github.com/grpc/grpc-go / TestBuffer_NewBufferAndFree

Method TestBuffer_NewBufferAndFree

mem/buffers_test.go:44–64  ·  view source on GitHub ↗

Tests that a buffer created with NewBuffer, which when later freed, invokes the free function with the correct data.

(t *testing.T)

Source from the content-addressed store, hash-verified

42// Tests that a buffer created with NewBuffer, which when later freed, invokes
43// the free function with the correct data.
44func (s) TestBuffer_NewBufferAndFree(t *testing.T) {
45 data := "abcd"
46 freed := false
47 freeF := poolFunc(func(got *[]byte) {
48 if !bytes.Equal(*got, []byte(data)) {
49 t.Fatalf("Free function called with bytes %s, want %s", string(*got), data)
50 }
51 freed = true
52 })
53
54 buf := newBuffer([]byte(data), freeF)
55 if got := buf.ReadOnlyData(); !bytes.Equal(got, []byte(data)) {
56 t.Fatalf("Buffer contains data %s, want %s", string(got), string(data))
57 }
58
59 // Verify that the free function is invoked when all references are freed.
60 buf.Free()
61 if !freed {
62 t.Fatalf("Buffer not freed")
63 }
64}
65
66// Tests that a buffer created with NewBuffer, on which an additional reference
67// is acquired, which when later freed, invokes the free function with the

Callers

nothing calls this directly

Calls 6

poolFuncFuncType · 0.85
newBufferFunction · 0.70
EqualMethod · 0.65
FatalfMethod · 0.65
ReadOnlyDataMethod · 0.65
FreeMethod · 0.65

Tested by

no test coverage detected