Rebase.
[official-gcc.git] / libgo / go / net / fd_unix_test.go
blobfe8e8ff6a88683c0e8ada5417717d236c2e26ad5
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 // +build darwin dragonfly freebsd linux netbsd openbsd solaris
7 package net
9 import (
10 "io"
11 "syscall"
12 "testing"
15 var chkReadErrTests = []struct {
16 n int
17 err error
18 fd *netFD
19 expected error
22 {100, nil, &netFD{sotype: syscall.SOCK_STREAM}, nil},
23 {100, io.EOF, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF},
24 {100, errClosing, &netFD{sotype: syscall.SOCK_STREAM}, errClosing},
25 {0, nil, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF},
26 {0, io.EOF, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF},
27 {0, errClosing, &netFD{sotype: syscall.SOCK_STREAM}, errClosing},
29 {100, nil, &netFD{sotype: syscall.SOCK_DGRAM}, nil},
30 {100, io.EOF, &netFD{sotype: syscall.SOCK_DGRAM}, io.EOF},
31 {100, errClosing, &netFD{sotype: syscall.SOCK_DGRAM}, errClosing},
32 {0, nil, &netFD{sotype: syscall.SOCK_DGRAM}, nil},
33 {0, io.EOF, &netFD{sotype: syscall.SOCK_DGRAM}, io.EOF},
34 {0, errClosing, &netFD{sotype: syscall.SOCK_DGRAM}, errClosing},
36 {100, nil, &netFD{sotype: syscall.SOCK_SEQPACKET}, nil},
37 {100, io.EOF, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF},
38 {100, errClosing, &netFD{sotype: syscall.SOCK_SEQPACKET}, errClosing},
39 {0, nil, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF},
40 {0, io.EOF, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF},
41 {0, errClosing, &netFD{sotype: syscall.SOCK_SEQPACKET}, errClosing},
43 {100, nil, &netFD{sotype: syscall.SOCK_RAW}, nil},
44 {100, io.EOF, &netFD{sotype: syscall.SOCK_RAW}, io.EOF},
45 {100, errClosing, &netFD{sotype: syscall.SOCK_RAW}, errClosing},
46 {0, nil, &netFD{sotype: syscall.SOCK_RAW}, nil},
47 {0, io.EOF, &netFD{sotype: syscall.SOCK_RAW}, io.EOF},
48 {0, errClosing, &netFD{sotype: syscall.SOCK_RAW}, errClosing},
51 func TestChkReadErr(t *testing.T) {
52 for _, tt := range chkReadErrTests {
53 actual := chkReadErr(tt.n, tt.err, tt.fd)
54 if actual != tt.expected {
55 t.Errorf("chkReadError(%v, %v, %v): expected %v, actual %v", tt.n, tt.err, tt.fd.sotype, tt.expected, actual)