github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/src/net/fd_unix_test.go (about)

     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.
     4  
     5  // +build darwin dragonfly freebsd linux netbsd openbsd solaris
     6  
     7  package net
     8  
     9  import (
    10  	"io"
    11  	"syscall"
    12  	"testing"
    13  )
    14  
    15  var chkReadErrTests = []struct {
    16  	n        int
    17  	err      error
    18  	fd       *netFD
    19  	expected error
    20  }{
    21  
    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},
    28  
    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},
    35  
    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},
    42  
    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},
    49  }
    50  
    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)
    56  		}
    57  	}
    58  }