MCPcopy
hub / github.com/awnumar/memguard / TestData

Function TestData

core/buffer_test.go:94–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestData(t *testing.T) {
95 b, err := NewBuffer(32)
96 if err != nil {
97 t.Error(err)
98 }
99 datasegm := b.data
100 datameth := b.Data()
101
102 // Check for naive equality.
103 if !bytes.Equal(datasegm, datameth) {
104 t.Error("naive equality check failed")
105 }
106
107 // Modify and check if the change was reflected in both.
108 datameth[0] = 1
109 datameth[31] = 1
110 if !bytes.Equal(datasegm, datameth) {
111 t.Error("modified equality check failed")
112 }
113
114 // Do a deep comparison.
115 if uintptr(unsafe.Pointer(&datameth[0])) != uintptr(unsafe.Pointer(&datasegm[0])) {
116 t.Error("pointer values differ")
117 }
118 if len(datameth) != len(datasegm) || cap(datameth) != cap(datasegm) {
119 t.Error("length or capacity values differ")
120 }
121
122 b.Destroy()
123 if b.Data() != nil {
124 t.Error("expected nil data slice for destroyed buffer")
125 }
126}
127
128func TestBufferState(t *testing.T) {
129 b, err := NewBuffer(32)

Callers

nothing calls this directly

Calls 3

DataMethod · 0.95
DestroyMethod · 0.95
NewBufferFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…