MCPcopy
hub / github.com/syncthing/syncthing / TestLZ4Compression

Function TestLZ4Compression

lib/protocol/protocol_test.go:312–341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310}
311
312func 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
343func TestLZ4CompressionUpdate(t *testing.T) {
344 uncompressed := []byte("this is some arbitrary yet fairly compressible data")

Callers

nothing calls this directly

Calls 6

IntnFunction · 0.92
lz4CompressFunction · 0.85
lz4DecompressFunction · 0.85
FatalMethod · 0.80
ErrorMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected