From ff83a9ca91f47c462bf68e6d5e50c56384fafda1 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 28 Apr 2017 20:44:28 +0200 Subject: [PATCH] test case for serial --- common/serial/bytes_test.go | 9 +++++++++ common/serial/string_test.go | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 common/serial/string_test.go diff --git a/common/serial/bytes_test.go b/common/serial/bytes_test.go index 4b37a42e..a873395c 100644 --- a/common/serial/bytes_test.go +++ b/common/serial/bytes_test.go @@ -24,3 +24,12 @@ func TestBytesToHex(t *testing.T) { assert.String(test.output).Equals(BytesToHexString(test.input)) } } + +func TestInt64(t *testing.T) { + assert := assert.On(t) + + x := int64(375134875348) + b := Int64ToBytes(x, []byte{}) + v := BytesToInt64(b) + assert.Int64(x).Equals(v) +} diff --git a/common/serial/string_test.go b/common/serial/string_test.go new file mode 100644 index 00000000..9464df5b --- /dev/null +++ b/common/serial/string_test.go @@ -0,0 +1,20 @@ +package serial_test + +import ( + "testing" + + "v2ray.com/core/common" + "v2ray.com/core/common/buf" + . "v2ray.com/core/common/serial" + "v2ray.com/core/testing/assert" +) + +func TestUint32(t *testing.T) { + assert := assert.On(t) + + x := uint32(458634234) + s1 := Uint32ToBytes(x, []byte{}) + s2 := buf.New() + common.Must(s2.AppendSupplier(WriteUint32(x))) + assert.Bytes(s1).Equals(s2.Bytes()) +}