OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package net | 5 package net |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | 8 "runtime" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if !sendMsg(c, buf[:]) || !recvMsg(c, buf[:]) { | 109 if !sendMsg(c, buf[:]) || !recvMsg(c, buf[:]) { |
110 break | 110 break |
111 } | 111 } |
112 } | 112 } |
113 }() | 113 }() |
114 } | 114 } |
115 for i := 0; i < cap(sem); i++ { | 115 for i := 0; i < cap(sem); i++ { |
116 sem <- true | 116 sem <- true |
117 } | 117 } |
118 } | 118 } |
| 119 |
| 120 var tcpListenerNameTests = []struct { |
| 121 net string |
| 122 laddr *TCPAddr |
| 123 }{ |
| 124 {"tcp4", &TCPAddr{IP: IPv4(127, 0, 0, 1)}}, |
| 125 {"tcp4", &TCPAddr{}}, |
| 126 {"tcp4", nil}, |
| 127 } |
| 128 |
| 129 func TestTCPListenerName(t *testing.T) { |
| 130 if testing.Short() || !*testExternal { |
| 131 t.Logf("skipping test to avoid external network") |
| 132 return |
| 133 } |
| 134 |
| 135 for _, tt := range tcpListenerNameTests { |
| 136 ln, err := ListenTCP(tt.net, tt.laddr) |
| 137 if err != nil { |
| 138 t.Errorf("ListenTCP failed: %v", err) |
| 139 return |
| 140 } |
| 141 defer ln.Close() |
| 142 la := ln.Addr() |
| 143 if a, ok := la.(*TCPAddr); !ok || a.Port == 0 { |
| 144 t.Errorf("got %v; expected a proper address with non-zer
o port number", la) |
| 145 return |
| 146 } |
| 147 } |
| 148 } |
OLD | NEW |