iogt.test
来自「tcl是工具命令语言」· TEST 代码 · 共 953 行 · 第 1/2 页
TEST
953 行
set fin [open $path(dummy) r] set fout [open $path(dummyout) r] set res [string equal [set in [read $fin]] [set out [read $fout]]] lappend res [string length $in] [string length $out] close $fin close $fout set res} {1 71 71}test iogt-2.1 {basic I/O, operation trail} {testchannel unixOnly} { set fin [open $path(dummy) r] set fout [open $path(dummyout) w] set ain [list] ; set aout [list] audit_ops ain -attach $fin audit_ops aout -attach $fout fconfigure $fin -buffersize 10 fconfigure $fout -buffersize 5 fcopy $fin $fout close $fin close $fout set res "[join $ain \n]\n--------\n[join $aout \n]"} {create/readquery/maxReadreadquery/maxReadreadquery/maxReadreadquery/maxReadreadquery/maxReadreadquery/maxReadreadquery/maxReadreadquery/maxReadreadquery/maxReadflush/readdelete/read--------create/writewritewritewritewritewritewritewritewriteflush/writedelete/write}test iogt-2.2 {basic I/O, data trail} {testchannel unixOnly} { set fin [open $path(dummy) r] set fout [open $path(dummyout) w] set ain [list] ; set aout [list] audit_flow ain -attach $fin audit_flow aout -attach $fout fconfigure $fin -buffersize 10 fconfigure $fout -buffersize 5 fcopy $fin $fout close $fin close $fout set res "[join $ain \n]\n--------\n[join $aout \n]"} {create/read {} *ignored*query/maxRead {} -1read abcdefghij abcdefghijquery/maxRead {} -1read klmnopqrst klmnopqrstquery/maxRead {} -1read uvwxyz0123 uvwxyz0123query/maxRead {} -1read 456789,./? 456789,./?query/maxRead {} -1read {><;'\|":[]} {><;'\|":[]}query/maxRead {} -1read {\}\{`~!@#$} {\}\{`~!@#$}query/maxRead {} -1read %^&*()_+-= %^&*()_+-=query/maxRead {} -1read {} {}query/maxRead {} -1flush/read {} {}delete/read {} *ignored*--------create/write {} *ignored*write abcdefghij abcdefghijwrite klmnopqrst klmnopqrstwrite uvwxyz0123 uvwxyz0123write 456789,./? 456789,./?write {><;'\|":[]} {><;'\|":[]}write {\}\{`~!@#$} {\}\{`~!@#$}write %^&*()_+-= %^&*()_+-=write {} {}flush/write {} {}delete/write {} *ignored*}test iogt-2.3 {basic I/O, mixed trail} {testchannel unixOnly} { set fin [open $path(dummy) r] set fout [open $path(dummyout) w] set trail [list] audit_flow trail -attach $fin audit_flow trail -attach $fout fconfigure $fin -buffersize 20 fconfigure $fout -buffersize 10 fcopy $fin $fout close $fin close $fout join $trail \n} {create/read {} *ignored*create/write {} *ignored*query/maxRead {} -1read abcdefghijklmnopqrst abcdefghijklmnopqrstwrite abcdefghij abcdefghijwrite klmnopqrst klmnopqrstquery/maxRead {} -1read uvwxyz0123456789,./? uvwxyz0123456789,./?write uvwxyz0123 uvwxyz0123write 456789,./? 456789,./?query/maxRead {} -1read {><;'\|":[]\}\{`~!@#$} {><;'\|":[]\}\{`~!@#$}write {><;'\|":[]} {><;'\|":[]}write {\}\{`~!@#$} {\}\{`~!@#$}query/maxRead {} -1read {%^&*()_+-=} {%^&*()_+-=}query/maxRead {} -1flush/read {} {}write %^&*()_+-= %^&*()_+-=write {} {}delete/read {} *ignored*flush/write {} {}delete/write {} *ignored*}test iogt-3.0 {Tcl_Channel valid after stack/unstack, fevent handling} \ {testchannel unknownFailure} { # This test to check the validity of aquired Tcl_Channel references is # not possible because even a backgrounded fcopy will immediately start # to copy data, without waiting for the event loop. This is done only in # case of an underflow on the read size!. So stacking transforms after the # fcopy will miss information, or are not used at all. # # I was able to circumvent this by using the echo.tcl server with a big # delay, causing the fcopy to underflow immediately. proc DoneCopy {n {err {}}} { variable copy ; set copy 1 } set fin [open $path(dummy) r] fevent 1000 500 {20 20 20 10 1 1} { close $fin set fout [open dummyout w] flush $sock ; # now, or fcopy will error us out # But the 1 second delay should be enough to # initialize everything else here. fcopy $sock $fout -command [namespace code DoneCopy] # transform after fcopy got its handles ! # They should be still valid for fcopy. set trail [list] audit_ops trail -attach $fout vwait [namespace which -variable copy] } [read $fin] ; # {} close $fout rename DoneCopy {} # Check result of copy. set fin [open $path(dummy) r] set fout [open $path(dummyout) r] set res [string equal [read $fin] [read $fout]] close $fin close $fout list $res $trail} {1 {create/write create/read write flush/write flush/read delete/write delete/read}}test iogt-4.0 {fileevent readable, after transform} {testchannel unknownFailure} { set fin [open $path(dummy) r] set data [read $fin] close $fin set trail [list] set got [list] proc Done {args} { variable stop set stop 1 } proc Get {sock} { variable trail variable got if {[eof $sock]} { Done lappend trail "xxxxxxxxxxxxx" close $sock return } lappend trail "vvvvvvvvvvvvv" lappend trail "\tgot: [lappend got "\[\[[read $sock]\]\]"]" lappend trail "=============" #puts stdout $__ ; flush stdout #read $sock } fevent 1000 500 {20 20 20 10 1} { audit_flow trail -attach $sock rblocks_t rbuf trail 23 -attach $sock fileevent $sock readable [list Get $sock] flush $sock ; # now, or fcopy will error us out # But the 1 second delay should be enough to # initialize everything else here. vwait [namespace which -variable stop] } $data rename Done {} rename Get {} join [list [join $got \n] ~~~~~~~~ [join $trail \n]] \n} {[[]][[abcdefghijklmnopqrstuvw]][[xyz0123456789,./?><;'\|]][[]][[]][[":[]\}\{`~!@#$%^&*()]][[]]~~~~~~~~create/write {} *ignored*create/read {} *ignored*rblock | create/write {} {} | {}rblock | create/read {} {} | {}vvvvvvvvvvvvvrblock | query/maxRead {} -1 | {}query/maxRead {} -1read abcdefghijklmnopqrstu abcdefghijklmnopqrstuquery/maxRead {} -1rblock | {read 23 21 :- 0} abcdefghijklmnopqrstu {} | abcdefghijklmnopqrsturblock | query/maxRead {} -1 | abcdefghijklmnopqrstuquery/maxRead {} -1 got: {[[]]}=============vvvvvvvvvvvvvrblock | query/maxRead {} -1 | abcdefghijklmnopqrstuquery/maxRead {} -1read vwxyz0123456789,./?>< vwxyz0123456789,./?><query/maxRead {} -1rblock | {read 23 42 :- 23} vwxyz0123456789,./?>< abcdefghijklmnopqrstuvw | xyz0123456789,./?><rblock | query/maxRead {} -1 | xyz0123456789,./?><query/maxRead {} -1 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]}=============vvvvvvvvvvvvvrblock | query/maxRead {} -1 | xyz0123456789,./?><query/maxRead {} -1read {;'\|":[]\}\{`~!@#$%^&} {;'\|":[]\}\{`~!@#$%^&}query/maxRead {} -1rblock | {read 23 40 :- 23} {;'\|":[]\}\{`~!@#$%^&} {xyz0123456789,./?><;'\|} | {":[]\}\{`~!@#$%^&}rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&}query/maxRead {} -1 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]}=============vvvvvvvvvvvvvrblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&}query/maxRead {} -1read *( *(query/maxRead {} -1rblock | {read 23 19 :- 0} *( {} | {":[]\}\{`~!@#$%^&*(}rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*(}query/maxRead {} -1 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]}=============vvvvvvvvvvvvvrblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*(}query/maxRead {} -1read ) )query/maxRead {} -1rblock | {read 23 20 :- 0} ) {} | {":[]\}\{`~!@#$%^&*()}rblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*()}query/maxRead {} -1 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]} {[[]]}=============vvvvvvvvvvvvvrblock | query/maxRead {} -1 | {":[]\}\{`~!@#$%^&*()}query/maxRead {} -1flush/read {} {}rblock | flush/read {} {":[]\}\{`~!@#$%^&*()} | {}rblock | query/maxRead {} -1 | {}query/maxRead {} -1 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]} {[[]]} {[[":[]\}\{`~!@#$%^&*()]]}=============vvvvvvvvvvvvvrblock | query/maxRead {} -1 | {}query/maxRead {} -1 got: {[[]]} {[[abcdefghijklmnopqrstuvw]]} {[[xyz0123456789,./?><;'\|]]} {[[]]} {[[]]} {[[":[]\}\{`~!@#$%^&*()]]} {[[]]}xxxxxxxxxxxxxrblock | flush/write {} {} | {}rblock | delete/write {} {} | {}rblock | delete/read {} {} | {}flush/write {} {}delete/write {} *ignored*delete/read {} *ignored*} ; # catch unescaped quote "test iogt-5.0 {EOF simulation} {testchannel unknownFailure} { set fin [open $path(dummy) r] set fout [open $path(dummyout) w] set trail [list] audit_flow trail -attach $fin stopafter_audit d trail 20 -attach $fin audit_flow trail -attach $fout fconfigure $fin -buffersize 20 fconfigure $fout -buffersize 10 fcopy $fin $fout testchannel unstack $fin # now copy the rest in the channel lappend trail {**after unstack**} fcopy $fin $fout close $fin close $fout join $trail \n} {create/read {} *ignored*counter:create/read {} {}create/write {} *ignored*counter:query/maxRead {} 20query/maxRead {} -1read {abcdefghijklmnopqrstuvwxyz0123456789,./?><;'\|":[]\}\{`~!@#$%^&*()_+-=} {abcdefghijklmnopqrstuvwxyz0123456789,./?><;'\|":[]\}\{`~!@#$%^&*()_+-=}query/maxRead {} -1flush/read {} {}counter:read abcdefghijklmnopqrst abcdefghijklmnopqrstwrite abcdefghij abcdefghijwrite klmnopqrst klmnopqrstcounter:query/maxRead {} 0counter:flush/read {} {}counter:delete/read {} {}**after unstack**query/maxRead {} -1write uvwxyz0123 uvwxyz0123write 456789,./? 456789,./?write {><;'\|":[]} {><;'\|":[]}write {\}\{`~!@#$} {\}\{`~!@#$}write %^&*()_+-= %^&*()_+-=write {} {}query/maxRead {} -1delete/read {} *ignored*flush/write {} {}delete/write {} *ignored*}proc constX {op data} { # replace anything coming in with a same-length string of x'es. switch -- $op { create/write - create/read - delete/write - delete/read - clear_read {;#ignore} flush/write - flush/read - write - read { return [string repeat x [string length $data]] } query/maxRead {return -1} }}proc constx {-attach channel} { testchannel transform $channel -command [namespace code constX]}test iogt-6.0 {Push back} testchannel { set f [open $path(dummy) r] # contents of dummy = "abcdefghi..." read $f 3 ; # skip behind "abc" constx -attach $f # expect to get "xxx" from the transform because # of unread "def" input to transform which returns "xxx". # # Actually the IO layer pre-read the whole file and will # read "def" directly from the buffer without bothering # to consult the newly stacked transformation. This is # wrong. set res [read $f 3] close $f set res} {xxx}test iogt-6.1 {Push back and up} {testchannel knownBug} { set f [open $path(dummy) r] # contents of dummy = "abcdefghi..." read $f 3 ; # skip behind "abc" constx -attach $f set res [read $f 3] testchannel unstack $f append res [read $f 3] close $f set res} {xxxghi}# cleanupforeach file [list dummy dummyout __echo_srv__.tcl] { removeFile $file}cleanupTests}namespace delete ::tcl::test::iogtreturn
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?