Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / net / conn_test.go
blob6854898da2ab09534fa8ecc5176de17dc9314913
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file implements API tests across platforms and will never have a build
6 // tag.
8 // +build !js
10 package net
12 import (
13 "testing"
14 "time"
17 // someTimeout is used just to test that net.Conn implementations
18 // don't explode when their SetFooDeadline methods are called.
19 // It isn't actually used for testing timeouts.
20 const someTimeout = 10 * time.Second
22 func TestConnAndListener(t *testing.T) {
23 for i, network := range []string{"tcp", "unix", "unixpacket"} {
24 if !testableNetwork(network) {
25 t.Logf("skipping %s test", network)
26 continue
29 ls, err := newLocalServer(network)
30 if err != nil {
31 t.Fatal(err)
33 defer ls.teardown()
34 ch := make(chan error, 1)
35 handler := func(ls *localServer, ln Listener) { transponder(ln, ch) }
36 if err := ls.buildup(handler); err != nil {
37 t.Fatal(err)
39 if ls.Listener.Addr().Network() != network {
40 t.Fatalf("got %s; want %s", ls.Listener.Addr().Network(), network)
43 c, err := Dial(ls.Listener.Addr().Network(), ls.Listener.Addr().String())
44 if err != nil {
45 t.Fatal(err)
47 defer c.Close()
48 if c.LocalAddr().Network() != network || c.RemoteAddr().Network() != network {
49 t.Fatalf("got %s->%s; want %s->%s", c.LocalAddr().Network(), c.RemoteAddr().Network(), network, network)
51 c.SetDeadline(time.Now().Add(someTimeout))
52 c.SetReadDeadline(time.Now().Add(someTimeout))
53 c.SetWriteDeadline(time.Now().Add(someTimeout))
55 if _, err := c.Write([]byte("CONN AND LISTENER TEST")); err != nil {
56 t.Fatal(err)
58 rb := make([]byte, 128)
59 if _, err := c.Read(rb); err != nil {
60 t.Fatal(err)
63 for err := range ch {
64 t.Errorf("#%d: %v", i, err)