LEFT | RIGHT |
(no file at all) | |
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 ) | 10 ) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 _, err = c.WriteTo([]byte("Connection-less mode socket"), ra) | 80 _, err = c.WriteTo([]byte("Connection-less mode socket"), ra) |
81 if err != nil { | 81 if err != nil { |
82 t.Fatalf("WriteTo failed: %v", err) | 82 t.Fatalf("WriteTo failed: %v", err) |
83 } | 83 } |
84 | 84 |
85 _, err = c.(*UDPConn).Write([]byte("Connection-less mode socket")) | 85 _, err = c.(*UDPConn).Write([]byte("Connection-less mode socket")) |
86 if err == nil { | 86 if err == nil { |
87 t.Fatal("Write should fail") | 87 t.Fatal("Write should fail") |
88 } | 88 } |
89 } | 89 } |
| 90 |
| 91 var udpConnLocalNameTests = []struct { |
| 92 net string |
| 93 laddr *UDPAddr |
| 94 }{ |
| 95 {"udp4", &UDPAddr{IP: IPv4(127, 0, 0, 1)}}, |
| 96 {"udp4", &UDPAddr{}}, |
| 97 {"udp4", nil}, |
| 98 } |
| 99 |
| 100 func TestUDPConnLocalName(t *testing.T) { |
| 101 if testing.Short() || !*testExternal { |
| 102 t.Logf("skipping test to avoid external network") |
| 103 return |
| 104 } |
| 105 |
| 106 for _, tt := range udpConnLocalNameTests { |
| 107 c, err := ListenUDP(tt.net, tt.laddr) |
| 108 if err != nil { |
| 109 t.Errorf("ListenUDP failed: %v", err) |
| 110 return |
| 111 } |
| 112 defer c.Close() |
| 113 la := c.LocalAddr() |
| 114 if a, ok := la.(*UDPAddr); !ok || a.Port == 0 { |
| 115 t.Errorf("got %v; expected a proper address with non-zer
o port number", la) |
| 116 return |
| 117 } |
| 118 } |
| 119 } |
LEFT | RIGHT |