本文整理汇总了Golang中v2ray/com/core/testing/assert.Int函数的典型用法代码示例。如果您正苦于以下问题:Golang Int函数的具体用法?Golang Int怎么用?Golang Int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestACKSegment
func TestACKSegment(t *testing.T) {
assert := assert.On(t)
seg := &AckSegment{
Conv: 1,
ReceivingWindow: 2,
ReceivingNext: 3,
Timestamp: 10,
NumberList: []uint32{1, 3, 5, 7, 9},
}
nBytes := seg.ByteSize()
bytes := make([]byte, nBytes)
seg.Bytes()(bytes)
assert.Int(len(bytes)).Equals(nBytes)
iseg, _ := ReadSegment(bytes)
seg2 := iseg.(*AckSegment)
assert.Uint16(seg2.Conv).Equals(seg.Conv)
assert.Uint32(seg2.ReceivingWindow).Equals(seg.ReceivingWindow)
assert.Uint32(seg2.ReceivingNext).Equals(seg.ReceivingNext)
assert.Int(len(seg2.NumberList)).Equals(len(seg.NumberList))
assert.Uint32(seg2.Timestamp).Equals(seg.Timestamp)
for i, number := range seg2.NumberList {
assert.Uint32(number).Equals(seg.NumberList[i])
}
}
示例2: TestBufferedReader
func TestBufferedReader(t *testing.T) {
assert := assert.On(t)
content := buf.New()
content.AppendSupplier(buf.ReadFrom(rand.Reader))
len := content.Len()
reader := NewReader(content)
assert.Bool(reader.Cached()).IsTrue()
payload := make([]byte, 16)
nBytes, err := reader.Read(payload)
assert.Int(nBytes).Equals(16)
assert.Error(err).IsNil()
len2 := content.Len()
assert.Int(len - len2).GreaterThan(16)
nBytes, err = reader.Read(payload)
assert.Int(nBytes).Equals(16)
assert.Error(err).IsNil()
assert.Int(content.Len()).Equals(len2)
}
示例3: TestHubSocksOption
func TestHubSocksOption(t *testing.T) {
assert := assert.On(t)
if os.Geteuid() != 0 {
// This test case requires root permission.
return
}
hub, err := ListenUDP(v2net.LocalHostIP, v2net.Port(0), ListenOption{
Callback: func(*buf.Buffer, *proxy.SessionInfo) {},
ReceiveOriginalDest: true,
})
assert.Error(err).IsNil()
conn := hub.Connection()
fd, err := internal.GetSysFd(conn)
assert.Error(err).IsNil()
val, err := syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT)
assert.Error(err).IsNil()
assert.Int(val).Equals(1)
val, err = syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR)
assert.Error(err).IsNil()
assert.Int(val).Equals(1)
}
示例4: TestPassiveTCPConnection
func TestPassiveTCPConnection(t *testing.T) {
assert := assert.On(t)
tcpServer := &tcp.Server{
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
buffer = append(buffer, data...)
return buffer
},
SendFirst: []byte("Server sends first."),
}
_, err := tcpServer.Start()
assert.Error(err).IsNil()
defer tcpServer.Close()
assert.Error(InitializeServerSetOnce("test_1")).IsNil()
socksPort := v2net.Port(50002)
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(socksPort),
})
assert.Error(err).IsNil()
authRequest := socks5AuthMethodRequest(byte(0))
nBytes, err := conn.Write(authRequest)
assert.Int(nBytes).Equals(len(authRequest))
assert.Error(err).IsNil()
authResponse := make([]byte, 1024)
nBytes, err = conn.Read(authResponse)
assert.Error(err).IsNil()
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
connectRequest := socks5Request(byte(1), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), tcpServer.Port))
nBytes, err = conn.Write(connectRequest)
assert.Int(nBytes).Equals(len(connectRequest))
assert.Error(err).IsNil()
connectResponse := make([]byte, 1024)
nBytes, err = conn.Read(connectResponse)
assert.Error(err).IsNil()
assert.Bytes(connectResponse[:nBytes]).Equals([]byte{socks5Version, 0, 0, 1, 0, 0, 0, 0, 6, 181})
actualResponse := make([]byte, 1024)
nResponse, err := conn.Read(actualResponse)
assert.Error(err).IsNil()
assert.String(string(actualResponse[:nResponse])).Equals(string(tcpServer.SendFirst))
conn.Close()
CloseAllServers()
}
示例5: TestTimeOutSettings
func TestTimeOutSettings(t *testing.T) {
assert := assert.On(t)
reader := NewTimeOutReader(8, nil)
assert.Int(reader.GetTimeOut()).Equals(8)
reader.SetTimeOut(8) // no op
assert.Int(reader.GetTimeOut()).Equals(8)
reader.SetTimeOut(9)
assert.Int(reader.GetTimeOut()).Equals(9)
}
示例6: TestAuthenticationReaderWriterPartial
func TestAuthenticationReaderWriterPartial(t *testing.T) {
assert := assert.On(t)
key := make([]byte, 16)
rand.Read(key)
block, err := aes.NewCipher(key)
assert.Error(err).IsNil()
aead, err := cipher.NewGCM(block)
assert.Error(err).IsNil()
payload := make([]byte, 8*1024)
rand.Read(payload)
cache := buf.NewLocal(16 * 1024)
iv := make([]byte, 12)
rand.Read(iv)
writer := NewAuthenticationWriter(&AEADAuthenticator{
AEAD: aead,
NonceGenerator: &StaticBytesGenerator{
Content: iv,
},
AdditionalDataGenerator: &NoOpBytesGenerator{},
}, cache)
nBytes, err := writer.Write(payload)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload))
assert.Int(cache.Len()).GreaterThan(0)
_, err = writer.Write([]byte{})
assert.Error(err).IsNil()
reader := NewAuthenticationReader(&AEADAuthenticator{
AEAD: aead,
NonceGenerator: &StaticBytesGenerator{
Content: iv,
},
AdditionalDataGenerator: &NoOpBytesGenerator{},
}, cache, false)
actualPayload := make([]byte, 7*1024)
nBytes, err = reader.Read(actualPayload)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(actualPayload))
assert.Bytes(actualPayload[:nBytes]).Equals(payload[:nBytes])
nBytes, err = reader.Read(actualPayload)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload) - len(actualPayload))
assert.Bytes(actualPayload[:nBytes]).Equals(payload[7*1024:])
_, err = reader.Read(actualPayload)
assert.Error(err).Equals(io.EOF)
}
示例7: TestBufferWrite
func TestBufferWrite(t *testing.T) {
assert := assert.On(t)
buffer := NewLocal(8)
nBytes, err := buffer.Write([]byte("abcd"))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(4)
nBytes, err = buffer.Write([]byte("abcde"))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(4)
assert.String(buffer.String()).Equals("abcdabcd")
}
示例8: TestBufferClear
func TestBufferClear(t *testing.T) {
assert := assert.On(t)
buffer := NewBuffer().Clear()
defer buffer.Release()
payload := "Bytes"
buffer.Append([]byte(payload))
assert.Int(buffer.Len()).Equals(len(payload))
buffer.Clear()
assert.Int(buffer.Len()).Equals(0)
}
示例9: TestSendingWindow
func TestSendingWindow(t *testing.T) {
assert := assert.On(t)
window := NewSendingWindow(5, nil, nil)
window.Push(0, []byte{})
window.Push(1, []byte{})
window.Push(2, []byte{})
assert.Int(window.Len()).Equals(3)
window.Remove(1)
assert.Int(window.Len()).Equals(3)
assert.Uint32(window.FirstNumber()).Equals(0)
window.Remove(0)
assert.Int(window.Len()).Equals(1)
assert.Uint32(window.FirstNumber()).Equals(2)
window.Remove(0)
assert.Int(window.Len()).Equals(0)
window.Push(4, []byte{})
assert.Int(window.Len()).Equals(1)
assert.Uint32(window.FirstNumber()).Equals(4)
window.Push(5, []byte{})
assert.Int(window.Len()).Equals(2)
window.Remove(1)
assert.Int(window.Len()).Equals(2)
window.Remove(0)
assert.Int(window.Len()).Equals(0)
}
示例10: TestAllHeadersLoadable
func TestAllHeadersLoadable(t *testing.T) {
assert := assert.On(t)
noopAuth, err := CreatePacketHeader((*noop.Config)(nil))
assert.Error(err).IsNil()
assert.Int(noopAuth.Size()).Equals(0)
srtp, err := CreatePacketHeader((*srtp.Config)(nil))
assert.Error(err).IsNil()
assert.Int(srtp.Size()).Equals(4)
utp, err := CreatePacketHeader((*utp.Config)(nil))
assert.Error(err).IsNil()
assert.Int(utp.Size()).Equals(4)
}
示例11: TestAllAuthenticatorLoadable
func TestAllAuthenticatorLoadable(t *testing.T) {
assert := assert.On(t)
noopAuth, err := CreateAuthenticator("none", nil)
assert.Error(err).IsNil()
assert.Int(noopAuth.Overhead()).Equals(0)
srtp, err := CreateAuthenticator("srtp", nil)
assert.Error(err).IsNil()
assert.Int(srtp.Overhead()).Equals(4)
utp, err := CreateAuthenticator("utp", nil)
assert.Error(err).IsNil()
assert.Int(utp.Overhead()).Equals(4)
}
示例12: TestAllAuthenticatorLoadable
func TestAllAuthenticatorLoadable(t *testing.T) {
assert := assert.On(t)
noopAuth, err := CreateAuthenticator(loader.GetType(new(noop.Config)), nil)
assert.Error(err).IsNil()
assert.Int(noopAuth.Overhead()).Equals(0)
srtp, err := CreateAuthenticator(loader.GetType(new(srtp.Config)), nil)
assert.Error(err).IsNil()
assert.Int(srtp.Overhead()).Equals(4)
utp, err := CreateAuthenticator(loader.GetType(new(utp.Config)), nil)
assert.Error(err).IsNil()
assert.Int(utp.Overhead()).Equals(4)
}
示例13: TestAllHeadersLoadable
func TestAllHeadersLoadable(t *testing.T) {
assert := assert.On(t)
noopAuth, err := CreatePacketHeader(serial.GetMessageType(new(noop.Config)), nil)
assert.Error(err).IsNil()
assert.Int(noopAuth.Size()).Equals(0)
srtp, err := CreatePacketHeader(serial.GetMessageType(new(srtp.Config)), nil)
assert.Error(err).IsNil()
assert.Int(srtp.Size()).Equals(4)
utp, err := CreatePacketHeader(serial.GetMessageType(new(utp.Config)), nil)
assert.Error(err).IsNil()
assert.Int(utp.Size()).Equals(4)
}
示例14: TestACKSegment
func TestACKSegment(t *testing.T) {
assert := assert.On(t)
seg := &AckSegment{
Conv: 1,
ReceivingWindow: 2,
ReceivingNext: 3,
Timestamp: 10,
Count: 5,
NumberList: []uint32{1, 3, 5, 7, 9},
}
nBytes := seg.ByteSize()
bytes := seg.Bytes(nil)
assert.Int(len(bytes)).Equals(nBytes)
iseg, _ := ReadSegment(bytes)
seg2 := iseg.(*AckSegment)
assert.Uint16(seg2.Conv).Equals(seg.Conv)
assert.Uint32(seg2.ReceivingWindow).Equals(seg.ReceivingWindow)
assert.Uint32(seg2.ReceivingNext).Equals(seg.ReceivingNext)
assert.Byte(seg2.Count).Equals(seg.Count)
assert.Uint32(seg2.Timestamp).Equals(seg.Timestamp)
for i := byte(0); i < seg2.Count; i++ {
assert.Uint32(seg2.NumberList[i]).Equals(seg.NumberList[i])
}
}
示例15: TestShadowsocksServerConfigParsing
func TestShadowsocksServerConfigParsing(t *testing.T) {
assert := assert.On(t)
rawJson := `{
"method": "aes-128-cfb",
"password": "v2ray-password"
}`
rawConfig := new(ShadowsocksServerConfig)
err := json.Unmarshal([]byte(rawJson), rawConfig)
assert.Error(err).IsNil()
ts, err := rawConfig.Build()
assert.Error(err).IsNil()
iConfig, err := ts.GetInstance()
assert.Error(err).IsNil()
config := iConfig.(*shadowsocks.ServerConfig)
rawAccount, err := config.User.GetTypedAccount()
assert.Error(err).IsNil()
account, ok := rawAccount.(*shadowsocks.ShadowsocksAccount)
assert.Bool(ok).IsTrue()
assert.Int(account.Cipher.KeySize()).Equals(16)
assert.Bytes(account.Key).Equals([]byte{160, 224, 26, 2, 22, 110, 9, 80, 65, 52, 80, 20, 38, 243, 224, 241})
}