| 364 | } |
| 365 | |
| 366 | func TestWriteBytes(t *testing.T) { |
| 367 | var buf bytes.Buffer |
| 368 | wr := NewWriter(&buf) |
| 369 | sizes := []int{0, 1, 225, int(tuint32)} |
| 370 | |
| 371 | for _, size := range sizes { |
| 372 | buf.Reset() |
| 373 | bts := RandBytes(size) |
| 374 | |
| 375 | err := wr.WriteBytes(bts) |
| 376 | if err != nil { |
| 377 | t.Fatal(err) |
| 378 | } |
| 379 | |
| 380 | err = wr.Flush() |
| 381 | if err != nil { |
| 382 | t.Fatal(err) |
| 383 | } |
| 384 | |
| 385 | if buf.Len() < len(bts) { |
| 386 | t.Errorf("somehow, %d bytes were encoded in %d bytes", len(bts), buf.Len()) |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | func benchwrBytes(size uint32, b *testing.B) { |
| 392 | bts := RandBytes(int(size)) |