1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-27 12:35:21 -05:00

remove common/net unit test back.

This commit is contained in:
Darien Raymond
2015-12-02 16:18:12 +00:00
parent ab875000e0
commit ec31c1fa7f
4 changed files with 3 additions and 6 deletions

View File

@@ -1,71 +0,0 @@
package unit
import (
"net"
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestIPv4Address(t *testing.T) {
v2testing.Current(t)
ip := []byte{byte(1), byte(2), byte(3), byte(4)}
port := v2net.NewPort(80)
addr := v2net.IPAddress(ip, port.Value())
v2netassert.Address(addr).IsIPv4()
v2netassert.Address(addr).IsNotIPv6()
v2netassert.Address(addr).IsNotDomain()
assert.Bytes(addr.IP()).Equals(ip)
v2netassert.Port(addr.Port()).Equals(port)
assert.String(addr).Equals("1.2.3.4:80")
}
func TestIPv6Address(t *testing.T) {
v2testing.Current(t)
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),
}
port := v2net.NewPort(443)
addr := v2net.IPAddress(ip, port.Value())
v2netassert.Address(addr).IsIPv6()
v2netassert.Address(addr).IsNotIPv4()
v2netassert.Address(addr).IsNotDomain()
assert.Bytes(addr.IP()).Equals(ip)
assert.Uint16(addr.Port().Value()).Equals(port.Value())
assert.String(addr).Equals("[102:304:102:304:102:304:102:304]:443")
}
func TestDomainAddress(t *testing.T) {
v2testing.Current(t)
domain := "v2ray.com"
port := v2net.NewPort(443)
addr := v2net.DomainAddress(domain, port.Value())
v2netassert.Address(addr).IsDomain()
v2netassert.Address(addr).IsNotIPv6()
v2netassert.Address(addr).IsNotIPv4()
assert.StringLiteral(addr.Domain()).Equals(domain)
assert.Uint16(addr.Port().Value()).Equals(port.Value())
assert.String(addr).Equals("v2ray.com:443")
}
func TestNetIPv4Address(t *testing.T) {
v2testing.Current(t)
ip := net.IPv4(1, 2, 3, 4)
port := v2net.NewPort(80)
addr := v2net.IPAddress(ip, port.Value())
v2netassert.Address(addr).IsIPv4()
assert.String(addr).Equals("1.2.3.4:80")
}

View File

@@ -1,27 +0,0 @@
package unit
import (
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestTCPDestination(t *testing.T) {
v2testing.Current(t)
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}, 80))
assert.Bool(dest.IsTCP()).IsTrue()
assert.Bool(dest.IsUDP()).IsFalse()
assert.String(dest).Equals("tcp:1.2.3.4:80")
}
func TestUDPDestination(t *testing.T) {
v2testing.Current(t)
dest := v2net.NewUDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}, 53))
assert.Bool(dest.IsTCP()).IsFalse()
assert.Bool(dest.IsUDP()).IsTrue()
assert.String(dest).Equals("udp:[2001:4860:4860::8888]:53")
}

View File

@@ -1,153 +0,0 @@
package unit
import (
"bytes"
"crypto/rand"
"io"
"io/ioutil"
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestReaderAndWrite(t *testing.T) {
v2testing.Current(t)
size := 1024 * 1024
buffer := make([]byte, size)
nBytes, err := rand.Read(buffer)
assert.Int(nBytes).Equals(len(buffer))
assert.Error(err).IsNil()
readerBuffer := bytes.NewReader(buffer)
writerBuffer := bytes.NewBuffer(make([]byte, 0, size))
transportChan := make(chan *alloc.Buffer, 1024)
err = v2net.ReaderToChan(transportChan, readerBuffer)
assert.Error(err).Equals(io.EOF)
close(transportChan)
err = v2net.ChanToWriter(writerBuffer, transportChan)
assert.Error(err).IsNil()
assert.Bytes(buffer).Equals(writerBuffer.Bytes())
}
type StaticReader struct {
total int
current int
}
func (reader *StaticReader) Read(b []byte) (size int, err error) {
size = len(b)
if size > reader.total-reader.current {
size = reader.total - reader.current
}
for i := 0; i < size; i++ {
b[i] = byte(i)
}
//rand.Read(b[:size])
reader.current += size
if reader.current == reader.total {
err = io.EOF
}
return
}
func BenchmarkTransport1K(b *testing.B) {
size := 1 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func BenchmarkTransport2K(b *testing.B) {
size := 2 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func BenchmarkTransport4K(b *testing.B) {
size := 4 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func BenchmarkTransport10K(b *testing.B) {
size := 10 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func BenchmarkTransport100K(b *testing.B) {
size := 100 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func BenchmarkTransport1M(b *testing.B) {
size := 1024 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func BenchmarkTransport10M(b *testing.B) {
size := 10 * 1024 * 1024
for i := 0; i < b.N; i++ {
runBenchmarkTransport(size)
}
}
func runBenchmarkTransport(size int) {
transportChanA := make(chan *alloc.Buffer, 16)
transportChanB := make(chan *alloc.Buffer, 16)
readerA := &StaticReader{size, 0}
readerB := &StaticReader{size, 0}
writerA := ioutil.Discard
writerB := ioutil.Discard
finishA := make(chan bool)
finishB := make(chan bool)
go func() {
v2net.ChanToWriter(writerA, transportChanA)
close(finishA)
}()
go func() {
v2net.ReaderToChan(transportChanA, readerA)
close(transportChanA)
}()
go func() {
v2net.ChanToWriter(writerB, transportChanB)
close(finishB)
}()
go func() {
v2net.ReaderToChan(transportChanB, readerB)
close(transportChanB)
}()
<-transportChanA
<-transportChanB
}

View File

@@ -1,3 +0,0 @@
package unit
// Placeholder. Golang doesn't like folders full of test files.