| 37 | } |
| 38 | |
| 39 | func TestXerialReaderWriter(t *testing.T) { |
| 40 | rawData := new(bytes.Buffer) |
| 41 | rawData.Grow(1024 * 1024) |
| 42 | io.CopyN(rawData, rand.Reader, 1024*1024) |
| 43 | |
| 44 | framedData := new(bytes.Buffer) |
| 45 | framedData.Grow(rawData.Len() + 1024) |
| 46 | w := simpleWriter{&xerialWriter{writer: framedData}} |
| 47 | r := simpleReader{bytes.NewReader(rawData.Bytes())} |
| 48 | io.Copy(w, r) |
| 49 | w.Writer.(*xerialWriter).Flush() |
| 50 | |
| 51 | unframedData := new(bytes.Buffer) |
| 52 | unframedData.Grow(rawData.Len()) |
| 53 | io.Copy(unframedData, &xerialReader{reader: framedData}) |
| 54 | |
| 55 | b0 := rawData.Bytes() |
| 56 | b1 := unframedData.Bytes() |
| 57 | |
| 58 | if !bytes.Equal(b0, b1) { |
| 59 | t.Error("data mismatch") |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func TestXerialFramedCompression(t *testing.T) { |
| 64 | rawData := new(bytes.Buffer) |