reader_test.go 671 B

12345678910111213141516171819202122232425262728
  1. package io_test
  2. import (
  3. "bytes"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/common/alloc"
  6. . "github.com/v2ray/v2ray-core/common/io"
  7. v2testing "github.com/v2ray/v2ray-core/testing"
  8. "github.com/v2ray/v2ray-core/testing/assert"
  9. )
  10. func TestAdaptiveReader(t *testing.T) {
  11. v2testing.Current(t)
  12. rawContent := make([]byte, 1024*1024)
  13. reader := NewAdaptiveReader(bytes.NewBuffer(rawContent))
  14. b1, err := reader.Read()
  15. assert.Error(err).IsNil()
  16. assert.Bool(b1.IsFull()).IsTrue()
  17. assert.Int(b1.Len()).Equals(alloc.BufferSize)
  18. b2, err := reader.Read()
  19. assert.Error(err).IsNil()
  20. assert.Bool(b2.IsFull()).IsTrue()
  21. assert.Int(b2.Len()).Equals(alloc.LargeBufferSize)
  22. }