archie/tcl-dp/tests/copy.test

115 lines
2.6 KiB
Plaintext
Raw Permalink Normal View History

2024-05-27 16:13:40 +02:00
# copy.test
#
# This file tests the dp_copy command.
#
if {[string compare test [info procs test]] == 1} then {source ../tests/defs}
set argsError {wrong # args: should be "dp_copy ?-size size? inChanId outChanId ?outChanId ...?"}
test copy-1.1 {dp_copy command} {
list [catch {dp_copy} msg] $msg
} [list 1 $argsError]
test copy-1.2 {dp_copy command} {
list [catch {dp_copy foo} msg] $msg
} [list 1 $argsError]
test copy-1.3 {dp_copy command} {
list [catch {dp_copy -size 1000 foo} msg] $msg
} [list 1 $argsError]
test copy-1.4 {dp_copy command} {
list [catch {dp_copy -size foo} msg] $msg
} {1 {expected integer but got "foo"}}
test copy-1.5 {dp_copy command} {
list [catch {dp_copy -size stdin} msg] $msg
} {1 {expected integer but got "stdin"}}
test copy-2.1 {create temp file for testing} {
set tmpfd [open testtmp.00 {CREAT TRUNC WRONLY}]
puts -nonewline $tmpfd "0123456789"
puts $tmpfd ".........."
puts $tmpfd "abcd..abcd"
close $tmpfd
set dp_copyTmpFileGood 1
} 1
catch {close $tmpfd}
if ![info exists dp_copyTmpFileGood] {
puts stderr "Cannot create temporary file. Some tests of dp_copy are "
puts stderr "skipped."
catch {
file delete testtmp.00
}
return
}
test copy-2.2 {dp_copy command} {
set ifd [open testtmp.00 {RDONLY}]
set ofd [open testtmp.01 {CREAT TRUNC WRONLY}]
dp_copy -size 10 $ifd $ofd
close $ifd
close $ofd
set ofd [open testtmp.01 {RDONLY}]
gets $ofd
} "0123456789"
catch {close $ifd}
catch {close $ofd}
test copy-2.3 {dp_copy command} {
set ifd [open testtmp.00 {RDONLY}]
set ofd [open testtmp.01 {CREAT TRUNC WRONLY}]
dp_copy -size 10 $ifd $ofd
dp_copy -size 15 $ifd $ofd
close $ifd
close $ofd
set ofd [open testtmp.01 {RDONLY}]
set stuff "[gets $ofd][gets $ofd]"
#
# N.B. The newline character is discarded by gets
#
} "0123456789..........abcd"
catch {close $ifd}
catch {close $ofd}
test copy-2.4 {dp_copy command} {
set ifd [open testtmp.00 {RDONLY}]
set ofd1 [open testtmp.01 {CREAT TRUNC WRONLY}]
set ofd2 [open testtmp.02 {CREAT TRUNC WRONLY}]
dp_copy -size 10 $ifd $ofd1 $ofd2
dp_copy -size 5 $ifd $ofd1 $ofd2
dp_copy -size 10 $ifd $ofd1
close $ifd
close $ofd1
close $ofd2
set ofd1 [open testtmp.01 {RDONLY}]
set ofd2 [open testtmp.02 {RDONLY}]
set stuff "[gets $ofd1][gets $ofd2][gets $ofd1][gets $ofd2]"
} "0123456789..........0123456789.....abcd"
catch {close $ifd}
catch {close $ofd1}
catch {close $ofd2}
catch {file delete testtmp.00}
catch {file delete testtmp.01}
catch {file delete testtmp.02}