~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/net/fd_unix_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 freebsd linux netbsd openbsd
 
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
}