os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/iogt.test
First public contribution.
2 # Commands covered: transform, and stacking in general
4 # This file contains a collection of tests for Giot
6 # See the file "license.terms" for information on usage and redistribution
7 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9 # Copyright (c) 2000 Ajuba Solutions.
10 # Copyright (c) 2000 Andreas Kupries.
11 # All rights reserved.
13 # RCS: @(#) $Id: iogt.test,v 1.7.2.1 2005/04/14 07:10:57 davygrvy Exp $
15 if {[catch {package require tcltest 2.1}]} {
16 puts stderr "Skipping tests in [info script]. tcltest 2.1 required."
19 namespace eval ::tcl::test::iogt {
21 namespace import ::tcltest::cleanupTests
22 namespace import ::tcltest::makeFile
23 namespace import ::tcltest::removeFile
24 namespace import ::tcltest::test
25 namespace import ::tcltest::testConstraint
27 testConstraint testchannel [llength [info commands testchannel]]
29 set path(dummy) [makeFile {abcdefghijklmnopqrstuvwxyz0123456789,./?><;'\|":[]\}\{`~!@#$%^&*()_+-=
32 # " capture coloring of quotes
34 set path(dummyout) [makeFile {} dummyout]
36 set path(__echo_srv__.tcl) [makeFile {
37 #!/usr/local/bin/tclsh
41 # arguments, options: port to listen on for connections.
42 # delay till echo of first block
43 # delay between blocks
46 set port [lindex $argv 0]
47 set fdelay [lindex $argv 1]
48 set idelay [lindex $argv 2]
49 set bsizes [lrange $argv 3 end]
52 proc newconn {sock rhost rport} {
58 #puts stdout "C $sock $rhost $rport / $fdelay" ; flush stdout
65 set conn(delay) $fdelay
67 fileevent $sock readable [list echoGet $c $sock]
68 fconfigure $sock -translation binary -buffering none -blocking 0
71 proc echoGet {c sock} {
81 append conn(data) [read $sock]
83 #puts stdout "G $c $sock $conn(data) <<$conn(data)>>" ; flush stdout
85 if {$conn(after) == {}} {
86 set conn(after) [after $conn(delay) [list echoPut $c $sock]]
90 proc echoPut {c sock} {
97 if {[string length $conn(data)] == 0} {
98 #puts stdout "C $c $sock" ; flush stdout
102 #set conn(delay) $fdelay
107 set conn(delay) $idelay
109 set n [lindex $bsizes $conn(size)]
111 #puts stdout "P $c $sock $n >>" ; flush stdout
113 #puts __________________________________________
118 if {[string length $conn(data)] >= $n} {
119 puts -nonewline $sock [string range $conn(data) 0 $n]
120 set conn(data) [string range $conn(data) [incr n] end]
124 if {$conn(size) >= [llength $bsizes]} {
125 set conn(size) [expr {[llength $bsizes]-1}]
128 set conn(after) [after $conn(delay) [list echoPut $c $sock]]
131 #fileevent stdin readable {exit ;#cut}
134 socket -server newconn $port
139 ########################################################################
141 proc fevent {fdelay idelay blocks script data} {
142 # start and initialize an echo server, prepare data
143 # transmission, then hand over to the test script.
144 # this has to start real transmission via 'flush'.
145 # The server is stopped after completion of the test.
147 # fixed port, not so good. lets hope for the best, for now.
150 eval exec tclsh __echo_srv__.tcl \
151 $port $fdelay $idelay $blocks >@stdout &
155 #puts stdout "> $port" ; flush stdout
157 set sk [socket localhost $port]
161 -buffersize [expr {10+[llength $data]}]
163 puts -nonewline $sk $data
165 # The channel is prepared to go off.
167 #puts stdout ">>>>>" ; flush stdout
169 uplevel #0 set sock $sk
170 set res [uplevel #0 $script]
176 # --------------------------------------------------------------
177 # utility transformations ...
185 clear_read {;#ignore}
192 query/maxRead {return -1}
196 proc id_optrail {var op data} {
203 create/write - create/read -
204 delete/write - delete/read -
206 clear/read { #ignore }
216 lappend trail "error $op"
223 proc id_fulltrail {var op data} {
227 #puts stdout ">> $var $op $data" ; flush stdout
230 create/write - create/read -
231 delete/write - delete/read -
235 flush/write - flush/read -
245 #catch {puts stdout "\t>* $res" ; flush stdout}
246 #catch {puts stdout "x$res"} msg
248 lappend trail [list $op $data $res]
252 proc counter {var op data} {
257 create/write - create/read -
258 delete/write - delete/read -
259 clear_read {;#ignore}
260 flush/write - flush/read {return {}}
266 incr n -[string length $data]
280 proc counter_audit {var vtrail op data} {
283 upvar 0 $var n $vtrail trail
286 create/write - create/read -
287 delete/write - delete/read -
291 flush/write - flush/read {
299 incr n -[string length $data]
311 lappend trail [list counter:$op $data $res]
316 proc rblocks {var vtrail n op data} {
319 upvar 0 $var buf $vtrail trail
324 create/write - create/read -
325 delete/write - delete/read -
341 set b [expr {$n * ([string length $buf] / $n)}]
343 append op " $n [string length $buf] :- $b"
345 set res [string range $buf 0 [incr b -1]]
346 set buf [string range $buf [incr b] end]
354 lappend trail [list rblock | $op $data $res | $buf]
359 # --------------------------------------------------------------
360 # ... and convenience procedures to stack them
362 proc identity {-attach channel} {
363 testchannel transform $channel -command [namespace code id]
366 proc audit_ops {var -attach channel} {
367 testchannel transform $channel -command [namespace code [list id_optrail $var]]
370 proc audit_flow {var -attach channel} {
371 testchannel transform $channel -command [namespace code [list id_fulltrail $var]]
374 proc stopafter {var n -attach channel} {
378 testchannel transform $channel -command [namespace code [list counter $var]]
381 proc stopafter_audit {var trail n -attach channel} {
385 testchannel transform $channel -command [namespace code [list counter_audit $var $trail]]
388 proc rblocks_t {var trail n -attach channel} {
389 testchannel transform $channel -command [namespace code [list rblocks $var $trail $n]]
392 # --------------------------------------------------------------
393 # serialize an array, with keys in sorted order.
395 proc array_sget {v} {
399 foreach n [lsort [array names a]] {
400 lappend res $n $a($n)
406 # sort a list of key/value pairs by key, removes duplicates too.
412 ########################################################################
414 test iogt-1.1 {stack/unstack} testchannel {
415 set fh [open $path(dummy) r]
417 testchannel unstack $fh
421 test iogt-1.2 {stack/close} testchannel {
422 set fh [open $path(dummy) r]
427 test iogt-1.3 {stack/unstack, configuration, options} testchannel {
428 set fh [open $path(dummy) r]
429 set ca [asort [fconfigure $fh]]
431 set cb [asort [fconfigure $fh]]
432 testchannel unstack $fh
433 set cc [asort [fconfigure $fh]]
436 # With this system none of the buffering, translation and
437 # encoding option may change their values with channels
438 # stacked upon each other or not.
442 list [string equal $ca $cb] [string equal $cb $cc] [string equal $ca $cc]
445 test iogt-1.4 {stack/unstack, configuration} testchannel {
446 set fh [open $path(dummy) r]
447 set ca [asort [fconfigure $fh]]
453 testchannel unstack $fh
454 set cc [asort [fconfigure $fh]]
457 [string equal $ca $cc] \
458 [fconfigure $fh -buffering] \
459 [fconfigure $fh -translation] \
460 [fconfigure $fh -encoding] \
465 } {0 line cr shiftjis}
467 test iogt-2.0 {basic I/O going through transform} testchannel {
468 set fin [open $path(dummy) r]
469 set fout [open $path(dummyout) w]
471 identity -attach $fin
472 identity -attach $fout
479 set fin [open $path(dummy) r]
480 set fout [open $path(dummyout) r]
482 set res [string equal [set in [read $fin]] [set out [read $fout]]]
483 lappend res [string length $in] [string length $out]
492 test iogt-2.1 {basic I/O, operation trail} {testchannel unixOnly} {
493 set fin [open $path(dummy) r]
494 set fout [open $path(dummyout) w]
496 set ain [list] ; set aout [list]
497 audit_ops ain -attach $fin
498 audit_ops aout -attach $fout
500 fconfigure $fin -buffersize 10
501 fconfigure $fout -buffersize 10
508 set res "[join $ain \n]\n--------\n[join $aout \n]"
542 test iogt-2.2 {basic I/O, data trail} {testchannel unixOnly} {
543 set fin [open $path(dummy) r]
544 set fout [open $path(dummyout) w]
546 set ain [list] ; set aout [list]
547 audit_flow ain -attach $fin
548 audit_flow aout -attach $fout
550 fconfigure $fin -buffersize 10
551 fconfigure $fout -buffersize 10
558 set res "[join $ain \n]\n--------\n[join $aout \n]"
559 } {create/read {} *ignored*
561 read abcdefghij abcdefghij
563 read klmnopqrst klmnopqrst
565 read uvwxyz0123 uvwxyz0123
567 read 456789,./? 456789,./?
569 read {><;'\|":[]} {><;'\|":[]}
571 read {\}\{`~!@#$} {\}\{`~!@#$}
573 read %^&*()_+-= %^&*()_+-=
580 delete/read {} *ignored*
582 create/write {} *ignored*
583 write abcdefghij abcdefghij
584 write klmnopqrst klmnopqrst
585 write uvwxyz0123 uvwxyz0123
586 write 456789,./? 456789,./?
587 write {><;'\|":[]} {><;'\|":[]}
588 write {\}\{`~!@#$} {\}\{`~!@#$}
589 write %^&*()_+-= %^&*()_+-=
594 delete/write {} *ignored*}
597 test iogt-2.3 {basic I/O, mixed trail} {testchannel unixOnly} {
598 set fin [open $path(dummy) r]
599 set fout [open $path(dummyout) w]
602 audit_flow trail -attach $fin
603 audit_flow trail -attach $fout
605 fconfigure $fin -buffersize 20
606 fconfigure $fout -buffersize 10
614 } {create/read {} *ignored*
615 create/write {} *ignored*
617 read abcdefghijklmnopqrst abcdefghijklmnopqrst
618 write abcdefghij abcdefghij
619 write klmnopqrst klmnopqrst
621 read uvwxyz0123456789,./? uvwxyz0123456789,./?
622 write uvwxyz0123 uvwxyz0123
623 write 456789,./? 456789,./?
625 read {><;'\|":[]\}\{`~!@#$} {><;'\|":[]\}\{`~!@#$}
626 write {><;'\|":[]} {><;'\|":[]}
627 write {\}\{`~!@#$} {\}\{`~!@#$}
634 write %^&*()_+-= %^&*()_+-=
638 delete/read {} *ignored*
640 delete/write {} *ignored*}
643 test iogt-3.0 {Tcl_Channel valid after stack/unstack, fevent handling} \
644 {testchannel unknownFailure} {
645 # This test to check the validity of aquired Tcl_Channel references is
646 # not possible because even a backgrounded fcopy will immediately start
647 # to copy data, without waiting for the event loop. This is done only in
648 # case of an underflow on the read size!. So stacking transforms after the
649 # fcopy will miss information, or are not used at all.
651 # I was able to circumvent this by using the echo.tcl server with a big
652 # delay, causing the fcopy to underflow immediately.
654 proc DoneCopy {n {err {}}} {
655 variable copy ; set copy 1
658 set fin [open $path(dummy) r]
660 fevent 1000 500 {20 20 20 10 1 1} {
663 set fout [open dummyout w]
665 flush $sock ; # now, or fcopy will error us out
666 # But the 1 second delay should be enough to
667 # initialize everything else here.
669 fcopy $sock $fout -command [namespace code DoneCopy]
671 # transform after fcopy got its handles !
672 # They should be still valid for fcopy.
675 audit_ops trail -attach $fout
677 vwait [namespace which -variable copy]
684 # Check result of copy.
686 set fin [open $path(dummy) r]
687 set fout [open $path(dummyout) r]
689 set res [string equal [read $fin] [read $fout]]
695 } {1 {create/write create/read write flush/write flush/read delete/write delete/read}}
698 test iogt-4.0 {fileevent readable, after transform} {testchannel unknownFailure} {
699 set fin [open $path(dummy) r]
716 lappend trail "xxxxxxxxxxxxx"
720 lappend trail "vvvvvvvvvvvvv"
721 lappend trail "\tgot: [lappend got "\[\[[read $sock]\]\]"]"
722 lappend trail "============="
723 #puts stdout $__ ; flush stdout
727 fevent 1000 500 {20 20 20 10 1} {
728 audit_flow trail -attach $sock
729 rblocks_t rbuf trail 23 -attach $sock
731 fileevent $sock readable [list Get $sock]
733 flush $sock ; # now, or fcopy will error us out
734 # But the 1 second delay should be enough to
735 # initialize everything else here.
737 vwait [namespace which -variable stop]
744 join [list [join $got \n] ~~~~~~~~ [join $trail \n]] \n
746 [[abcdefghijklmnopqrstuvw]]
747 [[xyz0123456789,./?><;'\|]]
750 [[":[]\}\{`~!@#$%^&*()]]
753 create/write {} *ignored*
754 create/read {} *ignored*
755 rblock | create/write {} {} | {}
756 rblock | create/read {} {} | {}
758 rblock | query/maxRead {} -1 | {}
760 read abcdefghijklmnopqrstu abcdefghijklmnopqrstu
762 rblock | {read 23 21 :- 0} abcdefghijklmnopqrstu {} | abcdefghijklmnopqrstu
763 rblock | query/maxRead {} -1 | abcdefghijklmnopqrstu
768 rblock | query/maxRead {} -1 | abcdefghijklmnopqrstu
770 read vwxyz0123456789,./?>< vwxyz0123456789,./?><
772 rblock | {read 23 42 :- 23} vwxyz0123456789,./?>< abcdefghijklmnopqrstuvw | xyz0123456789,./?><
773 rblock | query/maxRead {} -1 | xyz0123456789,./?><
775 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]}
778 rblock | query/maxRead {} -1 | xyz0123456789,./?><
780 read {;'\|":[]\}\{`~!@#$%^&} {;'\|":[]\}\{`~!@#$%^&}
782 rblock | {read 23 40 :- 23} {;'\|":[]\}\{`~!@#$%^&} {xyz0123456789,./?><;'\|} | {":[]\}\{`~!@#$%^&}
783 rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&}
785 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]}
788 rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&}
792 rblock | {read 23 19 :- 0} *( {} | {":[]\}\{`~!@#$%^&*(}
793 rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*(}
795 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]}
798 rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*(}
802 rblock | {read 23 20 :- 0} ) {} | {":[]\}\{`~!@#$%^&*()}
803 rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*()}
805 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]} {[[]]}
808 rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*()}
811 rblock | flush/read {} {":[]\}\{`~!@#$%^&*()} | {}
812 rblock | query/maxRead {} -1 | {}
814 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]} {[[]]} {[[":[]\}\{`~!@#$%^&*()]]}
817 rblock | query/maxRead {} -1 | {}
819 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]} {[[]]} {[[":[]\}\{`~!@#$%^&*()]]} {[[]]}
821 rblock | flush/write {} {} | {}
822 rblock | delete/write {} {} | {}
823 rblock | delete/read {} {} | {}
825 delete/write {} *ignored*
826 delete/read {} *ignored*} ; # catch unescaped quote "
829 test iogt-5.0 {EOF simulation} {testchannel unknownFailure} {
830 set fin [open $path(dummy) r]
831 set fout [open $path(dummyout) w]
835 audit_flow trail -attach $fin
836 stopafter_audit d trail 20 -attach $fin
837 audit_flow trail -attach $fout
839 fconfigure $fin -buffersize 20
840 fconfigure $fout -buffersize 10
843 testchannel unstack $fin
845 # now copy the rest in the channel
846 lappend trail {**after unstack**}
854 } {create/read {} *ignored*
855 counter:create/read {} {}
856 create/write {} *ignored*
857 counter:query/maxRead {} 20
859 read {abcdefghijklmnopqrstuvwxyz0123456789,./?><;'\|":[]\}\{`~!@#$%^&*()_+-=
860 } {abcdefghijklmnopqrstuvwxyz0123456789,./?><;'\|":[]\}\{`~!@#$%^&*()_+-=
864 counter:read abcdefghijklmnopqrst abcdefghijklmnopqrst
865 write abcdefghij abcdefghij
866 write klmnopqrst klmnopqrst
867 counter:query/maxRead {} 0
868 counter:flush/read {} {}
869 counter:delete/read {} {}
872 write uvwxyz0123 uvwxyz0123
873 write 456789,./? 456789,./?
874 write {><;'\|":[]} {><;'\|":[]}
875 write {\}\{`~!@#$} {\}\{`~!@#$}
876 write %^&*()_+-= %^&*()_+-=
881 delete/read {} *ignored*
883 delete/write {} *ignored*}
889 proc constX {op data} {
890 # replace anything coming in with a same-length string of x'es.
892 create/write - create/read -
893 delete/write - delete/read -
894 clear_read {;#ignore}
895 flush/write - flush/read -
898 return [string repeat x [string length $data]]
900 query/maxRead {return -1}
904 proc constx {-attach channel} {
905 testchannel transform $channel -command [namespace code constX]
908 test iogt-6.0 {Push back} testchannel {
909 set f [open $path(dummy) r]
911 # contents of dummy = "abcdefghi..."
912 read $f 3 ; # skip behind "abc"
916 # expect to get "xxx" from the transform because
917 # of unread "def" input to transform which returns "xxx".
919 # Actually the IO layer pre-read the whole file and will
920 # read "def" directly from the buffer without bothering
921 # to consult the newly stacked transformation. This is
929 test iogt-6.1 {Push back and up} {testchannel knownBug} {
930 set f [open $path(dummy) r]
932 # contents of dummy = "abcdefghi..."
933 read $f 3 ; # skip behind "abc"
938 testchannel unstack $f
939 append res [read $f 3]
946 foreach file [list dummy dummyout __echo_srv__.tcl] {
951 namespace delete ::tcl::test::iogt