(t *testing.T)
| 310 | } |
| 311 | |
| 312 | func TestLZ4Compression(t *testing.T) { |
| 313 | for i := 0; i < 10; i++ { |
| 314 | dataLen := 150 + rand.Intn(150) |
| 315 | data := make([]byte, dataLen) |
| 316 | _, err := io.ReadFull(rand.Reader, data[100:]) |
| 317 | if err != nil { |
| 318 | t.Fatal(err) |
| 319 | } |
| 320 | |
| 321 | comp := make([]byte, lz4.CompressBlockBound(dataLen)) |
| 322 | compLen, err := lz4Compress(data, comp) |
| 323 | if err != nil { |
| 324 | t.Errorf("compressing %d bytes: %v", dataLen, err) |
| 325 | continue |
| 326 | } |
| 327 | |
| 328 | res, err := lz4Decompress(comp[:compLen]) |
| 329 | if err != nil { |
| 330 | t.Errorf("decompressing %d bytes to %d: %v", len(comp), dataLen, err) |
| 331 | continue |
| 332 | } |
| 333 | if len(res) != len(data) { |
| 334 | t.Errorf("Incorrect len %d != expected %d", len(res), len(data)) |
| 335 | } |
| 336 | if !bytes.Equal(data, res) { |
| 337 | t.Error("Incorrect decompressed data") |
| 338 | } |
| 339 | t.Logf("OK #%d, %d -> %d -> %d", i, dataLen, len(comp), dataLen) |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | func TestLZ4CompressionUpdate(t *testing.T) { |
| 344 | uncompressed := []byte("this is some arbitrary yet fairly compressible data") |
nothing calls this directly
no test coverage detected