github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/src/net/fd_posix_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 nacl netbsd openbsd solaris windows
     6  
     7  package net
     8  
     9  import (
    10  	"io"
    11  	"syscall"
    12  	"testing"
    13  )
    14  
    15  var eofErrorTests = []struct {
    16  	n        int
    17  	err      error
    18  	fd       *netFD
    19  	expected error
    20  }{
    21  	{100, nil, &netFD{sotype: syscall.SOCK_STREAM}, nil},
    22  	{100, io.EOF, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF},
    23  	{100, errClosing, &netFD{sotype: syscall.SOCK_STREAM}, errClosing},
    24  	{0, nil, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF},
    25  	{0, io.EOF, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF},
    26  	{0, errClosing, &netFD{sotype: syscall.SOCK_STREAM}, errClosing},
    27  
    28  	{100, nil, &netFD{sotype: syscall.SOCK_DGRAM}, nil},
    29  	{100, io.EOF, &netFD{sotype: syscall.SOCK_DGRAM}, io.EOF},
    30  	{100, errClosing, &netFD{sotype: syscall.SOCK_DGRAM}, errClosing},
    31  	{0, nil, &netFD{sotype: syscall.SOCK_DGRAM}, nil},
    32  	{0, io.EOF, &netFD{sotype: syscall.SOCK_DGRAM}, io.EOF},
    33  	{0, errClosing, &netFD{sotype: syscall.SOCK_DGRAM}, errClosing},
    34  
    35  	{100, nil, &netFD{sotype: syscall.SOCK_SEQPACKET}, nil},
    36  	{100, io.EOF, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF},
    37  	{100, errClosing, &netFD{sotype: syscall.SOCK_SEQPACKET}, errClosing},
    38  	{0, nil, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF},
    39  	{0, io.EOF, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF},
    40  	{0, errClosing, &netFD{sotype: syscall.SOCK_SEQPACKET}, errClosing},
    41  
    42  	{100, nil, &netFD{sotype: syscall.SOCK_RAW}, nil},
    43  	{100, io.EOF, &netFD{sotype: syscall.SOCK_RAW}, io.EOF},
    44  	{100, errClosing, &netFD{sotype: syscall.SOCK_RAW}, errClosing},
    45  	{0, nil, &netFD{sotype: syscall.SOCK_RAW}, nil},
    46  	{0, io.EOF, &netFD{sotype: syscall.SOCK_RAW}, io.EOF},
    47  	{0, errClosing, &netFD{sotype: syscall.SOCK_RAW}, errClosing},
    48  }
    49  
    50  func TestEOFError(t *testing.T) {
    51  	for _, tt := range eofErrorTests {
    52  		actual := tt.fd.eofError(tt.n, tt.err)
    53  		if actual != tt.expected {
    54  			t.Errorf("eofError(%v, %v, %v): expected %v, actual %v", tt.n, tt.err, tt.fd.sotype, tt.expected, actual)
    55  		}
    56  	}
    57  }