| 92 | } |
| 93 | |
| 94 | func 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 | |
| 128 | func TestBufferState(t *testing.T) { |
| 129 | b, err := NewBuffer(32) |