diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-16 11:17:15 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-16 11:17:15 +0000 |
commit | c2e9c1da57c35f46052398ab31707ceb2dfc4e09 (patch) | |
tree | afd93279258b2ca1d846fdca1df67587efe6faad /libgo/go/net/interface_test.go | |
parent | 56664e5da23e1ca0072b690b206c297484897bd3 (diff) | |
download | gcc-c2e9c1da57c35f46052398ab31707ceb2dfc4e09.tar.gz |
2012-01-16 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 183204 using svnmerge
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@183208 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/net/interface_test.go')
-rw-r--r-- | libgo/go/net/interface_test.go | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/libgo/go/net/interface_test.go b/libgo/go/net/interface_test.go index cc614910fac..4ce01dc9061 100644 --- a/libgo/go/net/interface_test.go +++ b/libgo/go/net/interface_test.go @@ -24,7 +24,7 @@ func sameInterface(i, j *Interface) bool { func TestInterfaces(t *testing.T) { ift, err := Interfaces() if err != nil { - t.Fatalf("Interfaces() failed: %v", err) + t.Fatalf("Interfaces failed: %v", err) } t.Logf("table: len/cap = %v/%v\n", len(ift), cap(ift)) @@ -43,34 +43,57 @@ func TestInterfaces(t *testing.T) { if !sameInterface(ifxn, &ifi) { t.Fatalf("InterfaceByName(%#q) = %v, want %v", ifi.Name, *ifxn, ifi) } - ifat, err := ifi.Addrs() - if err != nil { - t.Fatalf("Interface.Addrs() failed: %v", err) - } - ifmat, err := ifi.MulticastAddrs() - if err != nil { - t.Fatalf("Interface.MulticastAddrs() failed: %v", err) - } t.Logf("%q: flags %q, ifindex %v, mtu %v\n", ifi.Name, ifi.Flags.String(), ifi.Index, ifi.MTU) - for _, ifa := range ifat { - t.Logf("\tinterface address %q\n", ifa.String()) - } - for _, ifma := range ifmat { - t.Logf("\tjoined group address %q\n", ifma.String()) - } t.Logf("\thardware address %q", ifi.HardwareAddr.String()) + testInterfaceAddrs(t, &ifi) + testInterfaceMulticastAddrs(t, &ifi) } } func TestInterfaceAddrs(t *testing.T) { ifat, err := InterfaceAddrs() if err != nil { - t.Fatalf("InterfaceAddrs() failed: %v", err) + t.Fatalf("InterfaceAddrs failed: %v", err) } t.Logf("table: len/cap = %v/%v\n", len(ifat), cap(ifat)) + testAddrs(t, ifat) +} + +func testInterfaceAddrs(t *testing.T, ifi *Interface) { + ifat, err := ifi.Addrs() + if err != nil { + t.Fatalf("Interface.Addrs failed: %v", err) + } + testAddrs(t, ifat) +} + +func testInterfaceMulticastAddrs(t *testing.T, ifi *Interface) { + ifmat, err := ifi.MulticastAddrs() + if err != nil { + t.Fatalf("Interface.MulticastAddrs failed: %v", err) + } + testMulticastAddrs(t, ifmat) +} +func testAddrs(t *testing.T, ifat []Addr) { for _, ifa := range ifat { - t.Logf("interface address %q\n", ifa.String()) + switch ifa.(type) { + case *IPAddr, *IPNet: + t.Logf("\tinterface address %q\n", ifa.String()) + default: + t.Errorf("\tunexpected type: %T", ifa) + } + } +} + +func testMulticastAddrs(t *testing.T, ifmat []Addr) { + for _, ifma := range ifmat { + switch ifma.(type) { + case *IPAddr: + t.Logf("\tjoined group address %q\n", ifma.String()) + default: + t.Errorf("\tunexpected type: %T", ifma) + } } } |