[Tclresource-commits] Extras/Tests WriteCmd.test,1.1,1.2
Status: Beta
Brought to you by:
bdesgraupes
From: Bernard D. <bde...@us...> - 2004-09-06 16:56:47
|
Update of /cvsroot/tclresource/Extras/Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4330 Modified Files: WriteCmd.test Log Message: 9 tests Index: WriteCmd.test =================================================================== RCS file: /cvsroot/tclresource/Extras/Tests/WriteCmd.test,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- WriteCmd.test 6 Sep 2004 07:04:26 -0000 1.1 +++ WriteCmd.test 6 Sep 2004 16:56:37 -0000 1.2 @@ -1,7 +1,7 @@ # ------------------------------------------------------- # File: "WriteCmd.test" # Created: 2004-09-05 20:16:33 -# Last modification: 2004-09-05 10:49:55 +# Last modification: 2004-09-06 18:52:16 # Author: Bernard Desgraupes # e-mail: <bde...@ea...> # www: <http://webperso.easyconnect.fr/bdesgraupes/> @@ -18,27 +18,85 @@ # ------------------------------------------------------- source [file join [file dir [info script]] common.tcl] +# set fname /Volumes/hd3/Tcl/Tcl_Sources/Extensions/Tclresource/Tclresource/Extras/Tests/Forks/TempFork.rsrc namespace eval ::resource::test { namespace import ::tcltest::* - test ResourceWrite-1-1 {} -setup { - } -body { - } -cleanup { - } -result "" + # Common code for setup + variable SETUP { + set fname [file join [file dir [info script]] Forks TempFork.rsrc] + set rid [resource open $fname w+] + } + + # Common code for cleanup + variable CLEANUP { + resource close $rid + if {[file exists $fname]} { + file delete $fname + } + } + + test ResourceWrite-1-1 {Specify -id, -name and -file} -setup $SETUP -body { + set res [catch {resource write -id 128 -name "Hello" -file $rid TEXT "Hello Tclresource!"}] + } -cleanup $CLEANUP -result 0 - test ResourceWrite-1-2 {} -setup { + test ResourceWrite-1-2 {Omit the -id option} -setup $SETUP -body { + set res [catch {resource write -name "Hello" -file $rid TEXT "Hello Tclresource!"}] + } -cleanup $CLEANUP -result 0 + + test ResourceWrite-1-3 {Omit the -name option} -setup $SETUP -body { + set res [catch {resource write -file $rid TEXT "Hello Tclresource!"}] + } -cleanup $CLEANUP -result 0 + + test ResourceWrite-1-4 {Omit the -file option, no fork opened} -setup { } -body { + # Since no resource fork has been opened, this will generate an error + resource write TEXT "Hello Tclresource!" } -cleanup { - } -result "" + } -returnCodes error \ + -result "error adding resource to resource map error releasing resource" - test ResourceWrite-1-3 {} -setup { + test ResourceWrite-1-5 {Omit the -file option, fork opened} -setup $SETUP -body { + # If a resource fork is open, this will write therein + set res [catch {resource write TEXT "Hello Tclresource!"}] + } -cleanup $CLEANUP -result 0 + + test ResourceWrite-1-6 {A resource with same ID exists, no -force} -setup $SETUP -body { + resource write -id 1000 -file $rid TEXT "Hello Tclresource!" + resource write -id 1000 -file $rid TEXT "Hello Tclresource!" + } -cleanup $CLEANUP -returnCodes error -match glob \ + -result "the resource * already exists, use the \"-force\" option to overwrite it." + + test ResourceWrite-1-7 {A resource with same ID exists, use -force} -setup $SETUP -body { + resource write -id 1000 -file $rid TEXT "Hello Tclresource!" + catch {resource write -id 1000 -file $rid -force TEXT "Hello Tclresource!"} res + set res + } -cleanup $CLEANUP -result "" + + test ResourceWrite-1-8 {Write to fork opened read-only} -setup { + set fname [file join [file dir [info script]] Forks TempFork.rsrc] + # This creates the resource file + set rid [resource open $fname w+] + resource close $rid + # Now reopen it read-only + set rid [resource open $fname r] } -body { - } -cleanup { - } -result "" + resource write -id 1000 -file $rid TEXT "Hello Tclresource!" + } -cleanup $CLEANUP -returnCodes error -match glob \ + -result "cannot write to resource file *, it was opened read only" -# Cleanup -::tcltest::cleanupTests + test ResourceWrite-1-9 {Write binary data} -setup $SETUP -body { + resource write -id 1000 -file $rid ALRT "\x00\x28\x00\x28\x00\x87\x01\x7c\x00\x80\x55\x55\x30\x0a" + } -cleanup $CLEANUP -result "" + +# test ResourceWrite-1-10 {} -setup { +# } -body { +# } -cleanup { +# } -result "" + + # Cleanup + ::tcltest::cleanupTests } namespace delete ::resource::test |