(t *testing.T)
| 275 | } |
| 276 | |
| 277 | func TestWriteCompressed(t *testing.T) { |
| 278 | for _, random := range []bool{false, true} { |
| 279 | buf := new(bytes.Buffer) |
| 280 | c := &rawConnection{ |
| 281 | cr: &countingReader{Reader: buf}, |
| 282 | cw: &countingWriter{Writer: buf}, |
| 283 | compression: CompressionAlways, |
| 284 | } |
| 285 | |
| 286 | msg := (&Response{Data: make([]byte, 10240)}).toWire() |
| 287 | if random { |
| 288 | // This should make the message incompressible. |
| 289 | rand.Read(msg.Data) |
| 290 | } |
| 291 | |
| 292 | if err := c.writeMessage(msg); err != nil { |
| 293 | t.Fatal(err) |
| 294 | } |
| 295 | got, err := c.readMessage(make([]byte, 4)) |
| 296 | if err != nil { |
| 297 | t.Fatal(err) |
| 298 | } |
| 299 | if !bytes.Equal(got.(*bep.Response).Data, msg.Data) { |
| 300 | t.Error("received the wrong message") |
| 301 | } |
| 302 | |
| 303 | hdr := &bep.Header{Type: typeOf(msg)} |
| 304 | size := int64(2 + proto.Size(hdr) + 4 + proto.Size(msg)) |
| 305 | if c.cr.Tot() > size { |
| 306 | t.Errorf("compression enlarged message from %d to %d", |
| 307 | size, c.cr.Tot()) |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | func TestLZ4Compression(t *testing.T) { |
| 313 | for i := 0; i < 10; i++ { |
nothing calls this directly
no test coverage detected