mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
test cases for Equals()
This commit is contained in:
parent
d75eeed25d
commit
7f4ff04483
@ -74,3 +74,51 @@ func TestNetIPv4Address(t *testing.T) {
|
||||
v2netassert.Address(addr).IsIPv4()
|
||||
assert.String(addr).Equals("1.2.3.4")
|
||||
}
|
||||
|
||||
func TestIPv4AddressEquals(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
addr := v2net.IPAddress([]byte{1, 2, 3, 4})
|
||||
assert.Bool(addr.Equals(nil)).IsFalse()
|
||||
|
||||
addr2 := v2net.IPAddress([]byte{1, 2, 3, 4})
|
||||
assert.Bool(addr.Equals(addr2)).IsTrue()
|
||||
|
||||
addr3 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
|
||||
assert.Bool(addr.Equals(addr3)).IsFalse()
|
||||
|
||||
addr4 := v2net.IPAddress([]byte{1, 2, 3, 5})
|
||||
assert.Bool(addr.Equals(addr4)).IsFalse()
|
||||
}
|
||||
|
||||
func TestIPv6AddressEquals(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
addr := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
|
||||
assert.Bool(addr.Equals(nil)).IsFalse()
|
||||
|
||||
addr2 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
|
||||
assert.Bool(addr.Equals(addr2)).IsTrue()
|
||||
|
||||
addr3 := v2net.IPAddress([]byte{1, 2, 3, 4})
|
||||
assert.Bool(addr.Equals(addr3)).IsFalse()
|
||||
|
||||
addr4 := v2net.IPAddress([]byte{1, 3, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
|
||||
assert.Bool(addr.Equals(addr4)).IsFalse()
|
||||
}
|
||||
|
||||
func TestDomainAddressEquals(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
addr := v2net.DomainAddress("v2ray.com")
|
||||
assert.Bool(addr.Equals(nil)).IsFalse()
|
||||
|
||||
addr2 := v2net.DomainAddress("v2ray.com")
|
||||
assert.Bool(addr.Equals(addr2)).IsTrue()
|
||||
|
||||
addr3 := v2net.DomainAddress("www.v2ray.com")
|
||||
assert.Bool(addr.Equals(addr3)).IsFalse()
|
||||
|
||||
addr4 := v2net.IPAddress([]byte{1, 3, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
|
||||
assert.Bool(addr.Equals(addr4)).IsFalse()
|
||||
}
|
||||
|
@ -57,6 +57,12 @@ func (dest *tcpDestination) Port() Port {
|
||||
}
|
||||
|
||||
func (dest *tcpDestination) Equals(another Destination) bool {
|
||||
if dest == nil && another == nil {
|
||||
return true
|
||||
}
|
||||
if dest == nil || another == nil {
|
||||
return false
|
||||
}
|
||||
if !another.IsTCP() {
|
||||
return false
|
||||
}
|
||||
@ -97,6 +103,12 @@ func (dest *udpDestination) Port() Port {
|
||||
}
|
||||
|
||||
func (dest *udpDestination) Equals(another Destination) bool {
|
||||
if dest == nil && another == nil {
|
||||
return true
|
||||
}
|
||||
if dest == nil || another == nil {
|
||||
return false
|
||||
}
|
||||
if !another.IsUDP() {
|
||||
return false
|
||||
}
|
||||
|
@ -26,3 +26,35 @@ func TestUDPDestination(t *testing.T) {
|
||||
v2netassert.Destination(dest).IsUDP()
|
||||
assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53")
|
||||
}
|
||||
|
||||
func TestTCPDestinationEquals(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
|
||||
assert.Bool(dest.Equals(nil)).IsFalse()
|
||||
|
||||
dest2 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
|
||||
assert.Bool(dest.Equals(dest2)).IsTrue()
|
||||
|
||||
dest3 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
|
||||
assert.Bool(dest.Equals(dest3)).IsFalse()
|
||||
|
||||
dest4 := v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)
|
||||
assert.Bool(dest.Equals(dest4)).IsFalse()
|
||||
}
|
||||
|
||||
func TestUDPDestinationEquals(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
|
||||
assert.Bool(dest.Equals(nil)).IsFalse()
|
||||
|
||||
dest2 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
|
||||
assert.Bool(dest.Equals(dest2)).IsTrue()
|
||||
|
||||
dest3 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
|
||||
assert.Bool(dest.Equals(dest3)).IsFalse()
|
||||
|
||||
dest4 := v2net.UDPDestination(v2net.DomainAddress("v2ray.com"), 80)
|
||||
assert.Bool(dest.Equals(dest4)).IsFalse()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user