# Commands covered: resource # # This file contains a collection of tests for one or more of the Tcl # built-in commands. Sourcing this file into Tcl runs the tests and # generates output for errors. No output means no errors were found. # # Copyright (c) 1996-1997 Sun Microsystems, Inc. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # SCCS: @(#) resource.test 1.6 97/07/23 17:41:51 # Only run this test on Macintosh systems if {$tcl_platform(platform) != "macintosh"} { return } if {[string compare test [info procs test]] == 1} then {source defs} test resource-1.1 {resource tests} { list [catch {resource} msg] $msg } {1 {wrong # args: should be "resource option ?arg ...?"}} test resource-1.2 {resource tests} { list [catch {resource _bad_} msg] $msg } {1 {bad option "_bad_": must be close, list, open, read, types, or write}} # resource open & close tests test resource-2.1 {resource open & close tests} { list [catch {resource open} msg] $msg } {1 {wrong # args: should be "resource open fileName ?permissions?"}} test resource-2.2 {resource open & close tests} { list [catch {resource open resource.test r extraArg} msg] $msg } {1 {wrong # args: should be "resource open fileName ?permissions?"}} test resource-2.3 {resource open & close tests} { list [catch {resource open resource.test bad_perms} msg] $msg } {1 {illegal access mode "bad_perms"}} test resource-2.4 {resource open & close tests} { list [catch {resource open _bad_file_} msg] $msg } {1 {file does not exist}} test resource-2.5 {resource open & close tests} { testWriteTextResource -rsrc fileRsrcName -file rsrc.file {error "don't source me"} set id [resource open rsrc.file] resource close $id } {} test resource-2.6 {resource open & close tests} { list [catch {resource close} msg] $msg } {1 {wrong # args: should be "resource close resourceRef"}} test resource-2.7 {resource open & close tests} { list [catch {resource close foo bar} msg] $msg } {1 {wrong # args: should be "resource close resourceRef"}} test resource-2.8 {resource open & close tests} { list [catch {resource close _bad_resource_} msg] $msg } {1 {invalid resource file reference "_bad_resource_"}} # Tests for listing resources test resource-3.1 {resource list tests} { list [catch {resource list} msg] $msg } {1 {wrong # args: should be "resource list resourceType ?resourceRef?"}} test resource-3.2 {resource list tests} { list [catch {resource list _bad_type_} msg] $msg } {1 {expected Macintosh OS type but got "_bad_type_"}} test resource-3.3 {resource list tests} { list [catch {resource list TEXT _bad_ref_} msg] $msg } {1 {invalid resource file reference "_bad_ref_"}} test resource-3.4 {resource list tests} { list [catch {resource list TEXT _bad_ref_ extraArg} msg] $msg } {1 {wrong # args: should be "resource list resourceType ?resourceRef?"}} test resource-3.5 {resource list tests} { catch {file delete rsrc.file} testWriteTextResource -rsrc fileRsrcName -file rsrc.file {error "don't source me"} set id [resource open rsrc.file] catch "resource list TEXT $id" result resource close $id set result } {fileRsrcName} test resource-3.6 {resource list tests} { # There should be any resource of this type resource list XXXX } {} test resource-3.7 {resource list tests} { set resourceList [resource list STR#] if {[lsearch $resourceList {Tcl Environment Variables}] == -1} { set result {couldn't find resource that should exist} } else { set result ok } } {ok} # Tests for listing resources test resource-4.1 {resource read tests} { list [catch {resource read} msg] $msg } {1 {wrong # args: should be "resource read resourceType resourceId ?resourceRef?"}} test resource-4.2 {resource read tests} { list [catch {resource read TEXT} msg] $msg } {1 {wrong # args: should be "resource read resourceType resourceId ?resourceRef?"}} test resource-4.3 {resource read tests} { list [catch {resource read STR# {_non_existant_resource_}} msg] $msg } {1 {could not load resource}} test resource-4.4 {resource read tests} { # The following resource should exist and load OK without error catch {resource read STR# {Tcl Environment Variables}} } {0} # Tests for getting resource types test resource-5.1 {resource types tests} { list [catch {resource types _bad_ref_} msg] $msg } {1 {invalid resource file reference "_bad_ref_"}} test resource-5.2 {resource types tests} { list [catch {resource types _bad_ref_ extraArg} msg] $msg } {1 {wrong # args: should be "resource types ?resourceRef?"}} test resource-5.3 {resource types tests} { # This should never cause an error catch {resource types} } {0} test resource-5.4 {resource types tests} { testWriteTextResource -rsrc fileRsrcName -file rsrc.file {error "don't source me"} set id [resource open rsrc.file] set result [resource types $id] resource close $id set result } {TEXT} # resource write tests test resource-6.1 {resource write tests} { list [catch {resource write} msg] $msg } {1 {wrong # args: should be "resource write ?-id resourceId? ?-name resourceName? ?-file resourceRef? resourceType data"}} test resource-6.2 {resource write tests} { list [catch {resource write _bad_type_ data} msg] $msg } {1 {expected Macintosh OS type but got "_bad_type_"}} test resource-6.3 {resource write tests} { catch {file delete rsrc2.file} set id [resource open rsrc2.file w] resource write -file $id -name Hello TEXT {set x "our test data"} source -rsrc Hello rsrc2.file resource close $id file delete rsrc2.file set x } {our test data} # Tests for the Mac version of the source command catch {file delete rsrc.file} testWriteTextResource -rsrc fileRsrcName -rsrcid 128 \ -file rsrc.file {set rsrc_foo 1} test resource-7.1 {source command} { catch {unset rsrc_foo} source -rsrc fileRsrcName rsrc.file list [catch {set rsrc_foo} msg] $msg } {0 1} test resource-7.2 {source command} { catch {unset rsrc_foo} list [catch {source -rsrc no_resource rsrc.file} msg] $msg } {1 {The resource "no_resource" could not be loaded from rsrc.file.}} test resource-7.3 {source command} { catch {unset rsrc_foo} source -rsrcid 128 rsrc.file list [catch {set rsrc_foo} msg] $msg } {0 1} test resource-7.4 {source command} { catch {unset rsrc_foo} list [catch {source -rsrcid bad_int rsrc.file} msg] $msg } {1 {expected integer but got "bad_int"}} test resource-7.5 {source command} { catch {unset rsrc_foo} list [catch {source -rsrcid 100 rsrc.file} msg] $msg } {1 {The resource "ID=100" could not be loaded from rsrc.file.}} # Clean up and return catch {file delete rsrc.file} return