2016-12-09 05:35:27 -05:00
|
|
|
package buf_test
|
2015-10-10 16:15:10 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-12-09 05:35:27 -05:00
|
|
|
. "v2ray.com/core/common/buf"
|
2016-12-06 05:03:42 -05:00
|
|
|
"v2ray.com/core/common/serial"
|
2017-10-24 10:15:35 -04:00
|
|
|
. "v2ray.com/ext/assert"
|
2015-10-10 16:15:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBufferClear(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2015-10-10 16:15:10 -04:00
|
|
|
|
2016-12-09 06:08:25 -05:00
|
|
|
buffer := New()
|
2015-10-10 16:15:10 -04:00
|
|
|
defer buffer.Release()
|
|
|
|
|
|
|
|
payload := "Bytes"
|
2018-04-19 16:56:55 -04:00
|
|
|
buffer.Write([]byte(payload))
|
2018-04-02 14:00:50 -04:00
|
|
|
assert(buffer.Len(), Equals, int32(len(payload)))
|
2015-10-10 16:15:10 -04:00
|
|
|
|
|
|
|
buffer.Clear()
|
2018-04-02 14:00:50 -04:00
|
|
|
assert(buffer.Len(), Equals, int32(0))
|
2015-10-10 16:15:10 -04:00
|
|
|
}
|
|
|
|
|
2016-12-06 05:03:42 -05:00
|
|
|
func TestBufferIsEmpty(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2015-10-10 16:15:10 -04:00
|
|
|
|
2016-12-09 06:08:25 -05:00
|
|
|
buffer := New()
|
2015-10-10 16:15:10 -04:00
|
|
|
defer buffer.Release()
|
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(buffer.IsEmpty(), IsTrue)
|
2015-10-10 16:15:10 -04:00
|
|
|
}
|
2016-01-31 15:24:40 -05:00
|
|
|
|
2016-04-29 17:47:42 -04:00
|
|
|
func TestBufferString(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2016-04-29 17:47:42 -04:00
|
|
|
|
2016-12-09 06:08:25 -05:00
|
|
|
buffer := New()
|
2016-04-29 17:47:42 -04:00
|
|
|
defer buffer.Release()
|
|
|
|
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(buffer.AppendSupplier(serial.WriteString("Test String")), IsNil)
|
|
|
|
assert(buffer.String(), Equals, "Test String")
|
2016-04-29 17:47:42 -04:00
|
|
|
}
|
2016-11-21 16:08:34 -05:00
|
|
|
|
2017-04-21 08:32:29 -04:00
|
|
|
func BenchmarkNewBuffer(b *testing.B) {
|
2016-11-21 16:08:34 -05:00
|
|
|
for i := 0; i < b.N; i++ {
|
2016-12-09 06:08:25 -05:00
|
|
|
buffer := New()
|
2016-11-21 16:08:34 -05:00
|
|
|
buffer.Release()
|
|
|
|
}
|
|
|
|
}
|