LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 "bytes" | 8 "bytes" |
9 "reflect" | 9 "reflect" |
10 "testing" | 10 "testing" |
11 "os" | |
12 "runtime" | 11 "runtime" |
13 ) | 12 ) |
14 | 13 |
15 func isEqual(a, b []byte) bool { | 14 func isEqual(a, b []byte) bool { |
16 if a == nil && b == nil { | 15 if a == nil && b == nil { |
17 return true | 16 return true |
18 } | 17 } |
19 if a == nil || b == nil { | 18 if a == nil || b == nil { |
20 return false | 19 return false |
21 } | 20 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if out := tt.in.String(); out != tt.out { | 105 if out := tt.in.String(); out != tt.out { |
107 t.Errorf("IPMask.String(%v) = %q, want %q", tt.in, out,
tt.out) | 106 t.Errorf("IPMask.String(%v) = %q, want %q", tt.in, out,
tt.out) |
108 } | 107 } |
109 } | 108 } |
110 } | 109 } |
111 | 110 |
112 var parsecidrtests = []struct { | 111 var parsecidrtests = []struct { |
113 in string | 112 in string |
114 ip IP | 113 ip IP |
115 net *IPNet | 114 net *IPNet |
116 » err os.Error | 115 » err error |
117 }{ | 116 }{ |
118 {"135.104.0.0/32", IPv4(135, 104, 0, 0), &IPNet{IPv4(135, 104, 0, 0), IP
v4Mask(255, 255, 255, 255)}, nil}, | 117 {"135.104.0.0/32", IPv4(135, 104, 0, 0), &IPNet{IPv4(135, 104, 0, 0), IP
v4Mask(255, 255, 255, 255)}, nil}, |
119 {"0.0.0.0/24", IPv4(0, 0, 0, 0), &IPNet{IPv4(0, 0, 0, 0), IPv4Mask(255,
255, 255, 0)}, nil}, | 118 {"0.0.0.0/24", IPv4(0, 0, 0, 0), &IPNet{IPv4(0, 0, 0, 0), IPv4Mask(255,
255, 255, 0)}, nil}, |
120 {"135.104.0.0/24", IPv4(135, 104, 0, 0), &IPNet{IPv4(135, 104, 0, 0), IP
v4Mask(255, 255, 255, 0)}, nil}, | 119 {"135.104.0.0/24", IPv4(135, 104, 0, 0), &IPNet{IPv4(135, 104, 0, 0), IP
v4Mask(255, 255, 255, 0)}, nil}, |
121 {"135.104.0.1/32", IPv4(135, 104, 0, 1), &IPNet{IPv4(135, 104, 0, 1), IP
v4Mask(255, 255, 255, 255)}, nil}, | 120 {"135.104.0.1/32", IPv4(135, 104, 0, 1), &IPNet{IPv4(135, 104, 0, 1), IP
v4Mask(255, 255, 255, 255)}, nil}, |
122 {"135.104.0.1/24", IPv4(135, 104, 0, 1), &IPNet{IPv4(135, 104, 0, 0), IP
v4Mask(255, 255, 255, 0)}, nil}, | 121 {"135.104.0.1/24", IPv4(135, 104, 0, 1), &IPNet{IPv4(135, 104, 0, 0), IP
v4Mask(255, 255, 255, 0)}, nil}, |
123 {"::1/128", ParseIP("::1"), &IPNet{ParseIP("::1"), IPMask(ParseIP("ffff:
ffff:ffff:ffff:ffff:ffff:ffff:ffff"))}, nil}, | 122 {"::1/128", ParseIP("::1"), &IPNet{ParseIP("::1"), IPMask(ParseIP("ffff:
ffff:ffff:ffff:ffff:ffff:ffff:ffff"))}, nil}, |
124 {"abcd:2345::/127", ParseIP("abcd:2345::"), &IPNet{ParseIP("abcd:2345::"
), IPMask(ParseIP("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"))}, nil}, | 123 {"abcd:2345::/127", ParseIP("abcd:2345::"), &IPNet{ParseIP("abcd:2345::"
), IPMask(ParseIP("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"))}, nil}, |
125 {"abcd:2345::/65", ParseIP("abcd:2345::"), &IPNet{ParseIP("abcd:2345::")
, IPMask(ParseIP("ffff:ffff:ffff:ffff:8000::"))}, nil}, | 124 {"abcd:2345::/65", ParseIP("abcd:2345::"), &IPNet{ParseIP("abcd:2345::")
, IPMask(ParseIP("ffff:ffff:ffff:ffff:8000::"))}, nil}, |
126 {"abcd:2345::/64", ParseIP("abcd:2345::"), &IPNet{ParseIP("abcd:2345::")
, IPMask(ParseIP("ffff:ffff:ffff:ffff::"))}, nil}, | 125 {"abcd:2345::/64", ParseIP("abcd:2345::"), &IPNet{ParseIP("abcd:2345::")
, IPMask(ParseIP("ffff:ffff:ffff:ffff::"))}, nil}, |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() | 359 return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() |
361 } | 360 } |
362 | 361 |
363 func TestIPAddrScope(t *testing.T) { | 362 func TestIPAddrScope(t *testing.T) { |
364 for _, tt := range ipscopetests { | 363 for _, tt := range ipscopetests { |
365 if ok := tt.scope(tt.in); ok != tt.ok { | 364 if ok := tt.scope(tt.in); ok != tt.ok { |
366 t.Errorf("%s(%q) = %v, want %v", name(tt.scope), tt.in,
ok, tt.ok) | 365 t.Errorf("%s(%q) = %v, want %v", name(tt.scope), tt.in,
ok, tt.ok) |
367 } | 366 } |
368 } | 367 } |
369 } | 368 } |
LEFT | RIGHT |