fd_unix_test.go 2.1 KB

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