Explorar el Código

test case for serial

Darien Raymond hace 8 años
padre
commit
ff83a9ca91
Se han modificado 2 ficheros con 29 adiciones y 0 borrados
  1. 9 0
      common/serial/bytes_test.go
  2. 20 0
      common/serial/string_test.go

+ 9 - 0
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)
+}

+ 20 - 0
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())
+}