1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
source [file dirname [info script]]/testing.tcl
needs constraint jim
testCmdConstraints socket
testConstraint posixaio [expr {$tcl_platform(platform) eq {unix} && !$tcl_platform(bootstrap)}]
# Create and open in binary mode for compatibility between Windows and Unix
set f [open testdata.in wb]
$f puts test-data
$f close
set f [open testdata.in rb]
defer {
$f close
file delete testdata.in
}
test aio-1.1 {seek usage} -body {
$f seek
} -returnCodes error -match glob -result {wrong # args: should be "* seek offset ?start|current|end"}
test aio-1.2 {seek start} -body {
$f seek 2
$f tell
} -result {2}
test aio-1.3 {seek start} -body {
$f seek 4 start
$f tell
} -result {4}
test aio-1.4 {read after seek} -body {
set c [$f read 1]
list $c [$f tell]
} -result {- 5}
test aio-1.5 {seek backwards} -body {
$f seek -2 current
set c [$f read 1]
list $c [$f tell]
} -result {t 4}
test aio-1.6 {seek from end} -body {
$f seek -2 end
set c [$f read 2]
list $c [$f tell]
} -result [list "a\n" 10]
test aio-1.7 {seek usage} -body {
$f seek 4 bad
} -returnCodes error -match glob -result {wrong # args: should be "* seek offset ?start|current|end"}
test aio-1.8 {seek usage} -body {
$f seek badint
} -returnCodes error -match glob -result {expected integer but got "badint"}
test aio-1.9 {seek bad pos} -body {
$f seek -20
} -returnCodes error -match glob -result {testdata.in: Invalid argument}
test aio-2.1 {read usage} -body {
$f read -nonoption
} -returnCodes error -result {bad option "-nonoption": must be -nonewline, or -pending}
test aio-2.2 {read usage} -body {
$f read badint
} -returnCodes error -result {expected integer but got "badint"}
test aio-2.3 {read -ve len} -body {
$f read " -20"
} -returnCodes error -result {invalid parameter: negative len}
test aio-2.4 {read too many args} -body {
$f read 20 extra
} -returnCodes error -match glob -result {wrong # args: should be "* read ?-nonewline|-pending|len?"}
test aio-2.5 {read -pending on non-ssl} -body {
$f read -pending
} -returnCodes error -result {-pending not supported on this connection type}
test aio-3.1 {copy to invalid fh} -body {
$f copy lambda
} -returnCodes error -result {Not a filehandle: "lambda"}
test aio-3.2 {copy bad length} -body {
$f copy stdout invalid
} -returnCodes error -result {expected integer but got "invalid"}
set badvar a
test aio-4.1 {gets invalid var} -body {
$f gets badvar(abc)
} -returnCodes error -result {can't set "badvar(abc)": variable isn't array}
test aio-5.1 {puts usage} -body {
stdout puts -badopt abc
} -returnCodes error -result {wrong # args: should be "stdout puts ?-nonewline? str"}
test aio-6.1 {eof} {
$f seek 0
$f eof
} {0}
test aio-6.2 {eof} {
# eof won't trigger until we try to read
$f seek 0 end
$f eof
} {0}
test aio-6.3 {eof} {
$f read 1
$f eof
} {1}
test aio-7.1 {close args} -constraints socket -body {
$f close badopt
} -returnCodes error -result {bad option "badopt": must be -nodelete, r, or w}
test aio-7.2 {close w on non-socket} -constraints socket -body {
$f close w
} -returnCodes error -match regexp -result {^(Socket operation on non-socket|Not a socket)$}
test aio-7.3 {close -nodelete on non-socket} -constraints socket -body {
$f close -nodelete
} -returnCodes error -result {not supported}
test aio-8.1 {filename} {
$f filename
} testdata.in
test aio-9.1 {open: posix modes} -constraints posixaio -body {
set in [open testdata.in RDONLY]
set buf [$in gets]
$in close
set buf
} -result {test-data}
test aio-9.2 {open: posix modes, bad modes} -constraints posixaio -body {
open testdata.in {CREAT TRUNC}
} -returnCodes error -result {testdata.in: Invalid argument}
test aio-9.3 {open: posix modes, bad modes} -constraints posixaio -body {
open testdata.in {WRONG TRUNC}
} -returnCodes error -result {bad access mode "WRONG": must be APPEND, BINARY, CREAT, EXCL, NOCTTY, RDONLY, RDWR, TRUNC, or WRONLY}
test aio-9.4 {open: posix modes} -constraints posixaio -cleanup {
file delete testdata.out
} -body {
set out [open testdata.out {WRONLY CREAT TRUNC}]
$out puts write-data
$out close
# Now open for readwrite without truncate
set io [open testdata.out {RDWR CREAT}]
set buf [$io gets]
$io close
set buf
} -result {write-data}
testreport
|