home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / resource.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  6.7 KB  |  170 lines  |  [TEXT/ALFA]

  1. # Commands covered:  resource
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1996-1997 Sun Microsystems, Inc.
  8. #
  9. # See the file "license.terms" for information on usage and redistribution
  10. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. #
  12. # SCCS: @(#) resource.test 1.6 97/07/23 17:41:51
  13.  
  14. # Only run this test on Macintosh systems
  15. if {$tcl_platform(platform) != "macintosh"} {
  16.     return
  17. }
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test resource-1.1 {resource tests} {
  21.     list [catch {resource} msg] $msg
  22. } {1 {wrong # args: should be "resource option ?arg ...?"}}
  23. test resource-1.2 {resource tests} {
  24.     list [catch {resource _bad_} msg] $msg
  25. } {1 {bad option "_bad_": must be close, list, open, read, types, or write}}
  26.  
  27. # resource open & close tests
  28. test resource-2.1 {resource open & close tests} {
  29.     list [catch {resource open} msg] $msg
  30. } {1 {wrong # args: should be "resource open fileName ?permissions?"}}
  31. test resource-2.2 {resource open & close tests} {
  32.     list [catch {resource open resource.test r extraArg} msg] $msg
  33. } {1 {wrong # args: should be "resource open fileName ?permissions?"}}
  34. test resource-2.3 {resource open & close tests} {
  35.     list [catch {resource open resource.test bad_perms} msg] $msg
  36. } {1 {illegal access mode "bad_perms"}}
  37. test resource-2.4 {resource open & close tests} {
  38.     list [catch {resource open _bad_file_} msg] $msg
  39. } {1 {file does not exist}}
  40. test resource-2.5 {resource open & close tests} {
  41.     testWriteTextResource -rsrc fileRsrcName -file rsrc.file  {error "don't source me"}
  42.     set id [resource open rsrc.file]
  43.     resource close $id
  44. } {}
  45. test resource-2.6 {resource open & close tests} {
  46.     list [catch {resource close} msg] $msg
  47. } {1 {wrong # args: should be "resource close resourceRef"}}
  48. test resource-2.7 {resource open & close tests} {
  49.     list [catch {resource close foo bar} msg] $msg
  50. } {1 {wrong # args: should be "resource close resourceRef"}}
  51. test resource-2.8 {resource open & close tests} {
  52.     list [catch {resource close _bad_resource_} msg] $msg
  53. } {1 {invalid resource file reference "_bad_resource_"}}
  54.  
  55. # Tests for listing resources
  56. test resource-3.1 {resource list tests} {
  57.     list [catch {resource list} msg] $msg
  58. } {1 {wrong # args: should be "resource list resourceType ?resourceRef?"}}
  59. test resource-3.2 {resource list tests} {
  60.     list [catch {resource list _bad_type_} msg] $msg
  61. } {1 {expected Macintosh OS type but got "_bad_type_"}}
  62. test resource-3.3 {resource list tests} {
  63.     list [catch {resource list TEXT _bad_ref_} msg] $msg
  64. } {1 {invalid resource file reference "_bad_ref_"}}
  65. test resource-3.4 {resource list tests} {
  66.     list [catch {resource list TEXT _bad_ref_ extraArg} msg] $msg
  67. } {1 {wrong # args: should be "resource list resourceType ?resourceRef?"}}
  68. test resource-3.5 {resource list tests} {
  69.     catch {file delete rsrc.file}
  70.     testWriteTextResource -rsrc fileRsrcName -file rsrc.file  {error "don't source me"}
  71.     set id [resource open rsrc.file]
  72.     catch "resource list TEXT $id" result
  73.     resource close $id
  74.     set result
  75. } {fileRsrcName}
  76. test resource-3.6 {resource list tests} {
  77.     # There should be any resource of this type
  78.     resource list XXXX
  79. } {}
  80. test resource-3.7 {resource list tests} {
  81.     set resourceList [resource list STR#]
  82.     if {[lsearch $resourceList {Tcl Environment Variables}] == -1} {
  83.         set result {couldn't find resource that should exist}
  84.     } else {
  85.         set result ok
  86.     }
  87. } {ok}
  88.  
  89. # Tests for listing resources
  90. test resource-4.1 {resource read tests} {
  91.     list [catch {resource read} msg] $msg
  92. } {1 {wrong # args: should be "resource read resourceType resourceId ?resourceRef?"}}
  93. test resource-4.2 {resource read tests} {
  94.     list [catch {resource read TEXT} msg] $msg
  95. } {1 {wrong # args: should be "resource read resourceType resourceId ?resourceRef?"}}
  96. test resource-4.3 {resource read tests} {
  97.     list [catch {resource read STR# {_non_existant_resource_}} msg] $msg
  98. } {1 {could not load resource}}
  99. test resource-4.4 {resource read tests} {
  100.     # The following resource should exist and load OK without error
  101.     catch {resource read STR# {Tcl Environment Variables}}
  102. } {0}
  103.  
  104. # Tests for getting resource types
  105. test resource-5.1 {resource types tests} {
  106.     list [catch {resource types _bad_ref_} msg] $msg
  107. } {1 {invalid resource file reference "_bad_ref_"}}
  108. test resource-5.2 {resource types tests} {
  109.     list [catch {resource types _bad_ref_ extraArg} msg] $msg
  110. } {1 {wrong # args: should be "resource types ?resourceRef?"}}
  111. test resource-5.3 {resource types tests} {
  112.     # This should never cause an error
  113.     catch {resource types}
  114. } {0}
  115. test resource-5.4 {resource types tests} {
  116.     testWriteTextResource -rsrc fileRsrcName -file rsrc.file  {error "don't source me"}
  117.     set id [resource open rsrc.file]
  118.     set result [resource types $id]
  119.     resource close $id
  120.     set result
  121. } {TEXT}
  122.  
  123. # resource write tests
  124. test resource-6.1 {resource write tests} {
  125.     list [catch {resource write} msg] $msg
  126. } {1 {wrong # args: should be "resource write ?-id resourceId? ?-name resourceName? ?-file resourceRef? resourceType data"}}
  127. test resource-6.2 {resource write tests} {
  128.     list [catch {resource write _bad_type_ data} msg] $msg
  129. } {1 {expected Macintosh OS type but got "_bad_type_"}}
  130. test resource-6.3 {resource write tests} {
  131.     catch {file delete rsrc2.file}
  132.     set id [resource open rsrc2.file w]
  133.     resource write -file $id -name Hello TEXT {set x "our test data"}
  134.     source -rsrc Hello rsrc2.file
  135.     resource close $id
  136.     file delete rsrc2.file
  137.     set x
  138. } {our test data}
  139.  
  140. # Tests for the Mac version of the source command
  141. catch {file delete rsrc.file}
  142. testWriteTextResource -rsrc fileRsrcName -rsrcid 128 \
  143.     -file rsrc.file  {set rsrc_foo 1}
  144. test resource-7.1 {source command} {
  145.     catch {unset rsrc_foo}
  146.     source -rsrc fileRsrcName rsrc.file
  147.     list [catch {set rsrc_foo} msg] $msg
  148. } {0 1}
  149. test resource-7.2 {source command} {
  150.     catch {unset rsrc_foo}
  151.     list [catch {source -rsrc no_resource rsrc.file} msg] $msg
  152. } {1 {The resource "no_resource" could not be loaded from rsrc.file.}}
  153. test resource-7.3 {source command} {
  154.     catch {unset rsrc_foo}
  155.     source -rsrcid 128 rsrc.file
  156.     list [catch {set rsrc_foo} msg] $msg
  157. } {0 1}
  158. test resource-7.4 {source command} {
  159.     catch {unset rsrc_foo}
  160.     list [catch {source -rsrcid bad_int rsrc.file} msg] $msg
  161. } {1 {expected integer but got "bad_int"}}
  162. test resource-7.5 {source command} {
  163.     catch {unset rsrc_foo}
  164.     list [catch {source -rsrcid 100 rsrc.file} msg] $msg
  165. } {1 {The resource "ID=100" could not be loaded from rsrc.file.}}
  166.  
  167. # Clean up and return
  168. catch {file delete rsrc.file}
  169. return
  170.