2015-12-02 11:18:12 -05:00
|
|
|
package net_test
|
2015-09-16 16:19:42 -04:00
|
|
|
|
|
|
|
import (
|
2015-10-14 02:43:04 -04:00
|
|
|
"net"
|
2015-09-16 16:19:42 -04:00
|
|
|
"testing"
|
|
|
|
|
2015-12-02 10:19:39 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-09-16 16:19:42 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIPv4Address(t *testing.T) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-09-16 16:19:42 -04:00
|
|
|
|
|
|
|
ip := []byte{byte(1), byte(2), byte(3), byte(4)}
|
2015-12-16 17:53:38 -05:00
|
|
|
addr := v2net.IPAddress(ip)
|
2015-09-16 16:19:42 -04:00
|
|
|
|
2015-12-02 10:19:39 -05:00
|
|
|
v2netassert.Address(addr).IsIPv4()
|
|
|
|
v2netassert.Address(addr).IsNotIPv6()
|
|
|
|
v2netassert.Address(addr).IsNotDomain()
|
2015-09-20 10:55:45 -04:00
|
|
|
assert.Bytes(addr.IP()).Equals(ip)
|
2015-12-16 17:53:38 -05:00
|
|
|
assert.String(addr).Equals("1.2.3.4")
|
2015-09-16 16:19:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIPv6Address(t *testing.T) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-09-16 16:19:42 -04:00
|
|
|
|
|
|
|
ip := []byte{
|
|
|
|
byte(1), byte(2), byte(3), byte(4),
|
|
|
|
byte(1), byte(2), byte(3), byte(4),
|
|
|
|
byte(1), byte(2), byte(3), byte(4),
|
|
|
|
byte(1), byte(2), byte(3), byte(4),
|
|
|
|
}
|
2015-12-16 17:53:38 -05:00
|
|
|
addr := v2net.IPAddress(ip)
|
2015-09-16 16:19:42 -04:00
|
|
|
|
2015-12-02 10:19:39 -05:00
|
|
|
v2netassert.Address(addr).IsIPv6()
|
|
|
|
v2netassert.Address(addr).IsNotIPv4()
|
|
|
|
v2netassert.Address(addr).IsNotDomain()
|
2015-09-20 10:55:45 -04:00
|
|
|
assert.Bytes(addr.IP()).Equals(ip)
|
2015-12-16 17:53:38 -05:00
|
|
|
assert.String(addr).Equals("[102:304:102:304:102:304:102:304]")
|
2015-09-16 16:19:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDomainAddress(t *testing.T) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-09-16 16:19:42 -04:00
|
|
|
|
|
|
|
domain := "v2ray.com"
|
2015-12-16 17:53:38 -05:00
|
|
|
addr := v2net.DomainAddress(domain)
|
2015-09-16 16:19:42 -04:00
|
|
|
|
2015-12-02 10:19:39 -05:00
|
|
|
v2netassert.Address(addr).IsDomain()
|
|
|
|
v2netassert.Address(addr).IsNotIPv6()
|
|
|
|
v2netassert.Address(addr).IsNotIPv4()
|
2015-12-02 10:41:19 -05:00
|
|
|
assert.StringLiteral(addr.Domain()).Equals(domain)
|
2015-12-16 17:53:38 -05:00
|
|
|
assert.String(addr).Equals("v2ray.com")
|
2015-09-16 16:19:42 -04:00
|
|
|
}
|
2015-10-14 02:43:04 -04:00
|
|
|
|
|
|
|
func TestNetIPv4Address(t *testing.T) {
|
2015-12-02 09:27:18 -05:00
|
|
|
v2testing.Current(t)
|
2015-10-14 02:43:04 -04:00
|
|
|
|
|
|
|
ip := net.IPv4(1, 2, 3, 4)
|
2015-12-16 17:53:38 -05:00
|
|
|
addr := v2net.IPAddress(ip)
|
2015-12-02 10:19:39 -05:00
|
|
|
v2netassert.Address(addr).IsIPv4()
|
2015-12-16 17:53:38 -05:00
|
|
|
assert.String(addr).Equals("1.2.3.4")
|
2015-10-14 02:43:04 -04:00
|
|
|
}
|