(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestExtensionRawStackBuffer(t *testing.T) { |
| 85 | var buf bytes.Buffer |
| 86 | en := NewWriter(&buf) |
| 87 | dc := NewReader(&buf) |
| 88 | |
| 89 | const bufSize = 128 |
| 90 | e := &RawExtension{Type: int8(rand.Int()), Data: RandBytes(bufSize)} |
| 91 | |
| 92 | allocs := testing.AllocsPerRun(100, func() { |
| 93 | buf.Reset() |
| 94 | |
| 95 | var staticBuf [bufSize]byte |
| 96 | slc := e.Data[:rand.Intn(bufSize)] |
| 97 | copy(staticBuf[:], slc) |
| 98 | |
| 99 | err := en.WriteExtensionRaw(e.Type, staticBuf[:len(slc)]) |
| 100 | if err != nil { |
| 101 | t.Errorf("error writing extension: %s", err) |
| 102 | } |
| 103 | en.Flush() |
| 104 | |
| 105 | typ, payload, err := dc.ReadExtensionRaw() |
| 106 | if err != nil { |
| 107 | t.Errorf("error reading extension: %s", err) |
| 108 | } |
| 109 | if typ != e.Type || !bytes.Equal(payload, slc) { |
| 110 | t.Errorf("extension mismatch: %d %x != %d %x", typ, payload, e.Type, slc) |
| 111 | } |
| 112 | }) |
| 113 | |
| 114 | if allocs != 0 { |
| 115 | t.Errorf("using stack allocated buffer with WriteExtensionRaw caused %f allocations", allocs) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | func TestReadWriteExtensionBytes(t *testing.T) { |
| 120 | var bts []byte |
nothing calls this directly
no test coverage detected
searching dependent graphs…