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
|
# -*- tcl -*-
# Commands covered: None, introductory text
#
# This file contains a collection of tests for one or more of the commands
# the piTcl extension. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 1998 Andreas Kupries (a.kupries@westend.com)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: memchan.test,v 1.8 2004/11/10 00:51:00 patthoyts Exp $
if {[string compare test [info procs test]] == 1} then {source defs}
test memchan-basics-1.0 {Create memory channels} {
set m [memchan]
close $m
regsub -all {[0-9]} $m {} m
set m
} {mem}
test memchan-basics-1.1 {Check tell on memory channels} {
set m [memchan]
set res [tell $m]
close $m
set res
} {0}
test memchan-basics-1.2 {Check seek on memory channels} {
set m [memchan]
set res [seek $m 0]
close $m
set res
} {}
test memchan-basics-1.3 {Check fconfigure/get on memory channels} {
set m [memchan]
set resf [fconfigure $m]
set res [list]
lappend res [lrange $resf [set x [lsearch -exact $resf -length]] [incr x]]
lappend res [lrange $resf [set x [lsearch -exact $resf -allocated]] [incr x]]
close $m
set res
} {{-length 0} {-allocated 0}}
test memchan-basics-1.4 {Check fconfigure/get -length} {
set m [memchan]
set res [fconfigure $m -length]
close $m
set res
} {0}
test memchan-basics-1.5 {check -initial-size} {
set m [memchan -init 1024]
set res [fconfigure $m -allocated]
close $m
set res
} {1024}
test memchan-readwrite-1.0 {Write, length and tell} {
set m [memchan]
puts -nonewline $m {hello world}
set res [list [fconfigure $m -length] [tell $m]]
close $m
set res
} {11 11}
test memchan-readwrite-1.1 {Write, seek and read} {
set m [memchan]
puts -nonewline $m {hello world!}
set res [list [fconfigure $m -length] [tell $m]]
seek $m 0
lappend res [read $m]
close $m
set res
} {12 12 {hello world!}}
proc Read {chan} {
if {[eof $chan]} {
fileevent $chan readable {}
lappend ::res eof
set ::wait 1
}
lappend ::res [read $chan 2]
}
test memchan-2.1 {check fileevent - memchan bug #1060620} {
set m [memchan]
set ::res {}
set ::wait 0
puts -nonewline $m data
seek $m 0
fileevent $m readable [list Read $m]
set id [after 400 {set ::wait 2}]
vwait ::wait
catch {after cancel $id}
close $m
list $::wait $res
} {1 {da ta {} eof {}}}
catch {rename Read {}}
catch {unset m}
catch {unset res}
|