home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / TCL / ITCL / _ITCL.TAR / usr / lib / itcl / tests / toaster.test < prev    next >
Encoding:
Text File  |  1994-03-21  |  5.0 KB  |  179 lines

  1. #
  2. # Tests for "toaster" example
  3. # ----------------------------------------------------------------------
  4. #   AUTHOR:  Michael J. McLennan       Phone: (610)712-2842
  5. #            AT&T Bell Laboratories   E-mail: michael.mclennan@att.com
  6. #
  7. #      RCS:  toaster.test,v 1.1.1.1 1994/03/21 22:09:50 mmc Exp
  8. # ----------------------------------------------------------------------
  9. #               Copyright (c) 1993  AT&T Bell Laboratories
  10. # ======================================================================
  11. # Permission to use, copy, modify, and distribute this software and its
  12. # documentation for any purpose and without fee is hereby granted,
  13. # provided that the above copyright notice appear in all copies and that
  14. # both that the copyright notice and warranty disclaimer appear in
  15. # supporting documentation, and that the names of AT&T Bell Laboratories
  16. # any of their entities not be used in advertising or publicity
  17. # pertaining to distribution of the software without specific, written
  18. # prior permission.
  19. #
  20. # AT&T disclaims all warranties with regard to this software, including
  21. # all implied warranties of merchantability and fitness.  In no event
  22. # shall AT&T be liable for any special, indirect or consequential
  23. # damages or any damages whatsoever resulting from loss of use, data or
  24. # profits, whether in an action of contract, negligence or other
  25. # tortuous action, arising out of or in connection with the use or
  26. # performance of this software.
  27. # ======================================================================
  28.  
  29. # ----------------------------------------------------------------------
  30. #  Get toaster classes from "demos" directory.
  31. # ----------------------------------------------------------------------
  32. lappend auto_path ../demos/toasters
  33.  
  34. # ----------------------------------------------------------------------
  35. #  Outlets send bills to an e-mail address.  Determine this address.
  36. # ----------------------------------------------------------------------
  37. if {[info exists env(USER)]} {
  38.     set Owner $env(USER)
  39. } elseif {[info exists env(LOGNAME)]} {
  40.     set Owner $env(LOGNAME)
  41. } else {
  42.     set Owner [exec logname]
  43. }
  44.  
  45. # ----------------------------------------------------------------------
  46. #  TOASTERS
  47. # ----------------------------------------------------------------------
  48. test {Create a toaster and plug it in} {
  49.     global Owner
  50.     Toaster original -heat 1 -outlet [Outlet #auto -owner $Owner]
  51. } {
  52.     $result == "original"
  53. }
  54.  
  55. test {Turn up the heat setting on the toaster} {
  56.     original config -heat 5
  57. } {
  58.     $result == ""
  59. }
  60.  
  61. test {Toast a few slices of bread} {
  62.     original toast 2
  63. } {
  64.     $result == "crumb tray: 25% full"
  65. }
  66.  
  67. test {Clean the toaster} {
  68.     original clean
  69. } {
  70.     $result == "crumb tray: 0% full"
  71. }
  72.  
  73. test {Toast a few slices of bread a few different times} {
  74.     original clean
  75.     original toast 2
  76.     original toast 1
  77. } {
  78.     $result == "crumb tray: 38% full"
  79. }
  80.  
  81. test {Toast too many slices of bread and cause a fire} {
  82.     puts stdout ">>> should say \"== FIRE! FIRE! ==\""
  83.     original clean
  84.     original toast 2
  85.     original toast 2
  86.     original toast 2
  87.     original toast 2
  88. } {
  89.     $result == "crumb tray: 100% full"
  90. }
  91.  
  92. test {Destroy the toaster} {
  93.     original clean
  94.     original toast 2
  95.     original toast 1
  96.     puts stdout ">>> should say \"15 crumbs ... what a mess!\""
  97.     original delete
  98. } {
  99.     $result == ""
  100. }
  101.  
  102. # ----------------------------------------------------------------------
  103. #  SMART TOASTERS
  104. # ----------------------------------------------------------------------
  105. test {Create a toaster and plug it in} {
  106.     global Owner
  107.     SmartToaster deluxe -heat 4 -outlet [Outlet #auto -owner $Owner]
  108. } {
  109.     $result == "deluxe"
  110. }
  111.  
  112. test {Toast a few slices of bread} {
  113.     deluxe toast 2
  114. } {
  115.     $result == "crumb tray: 20% full"
  116. }
  117.  
  118. test {Toast a few slices of bread and look for auto-clean} {
  119.     deluxe clean
  120.     deluxe toast 2
  121.     deluxe toast 2
  122.     deluxe toast 2
  123.     deluxe toast 2
  124.     deluxe toast 2
  125. } {
  126.     $result == "crumb tray: 20% full"
  127. }
  128.  
  129. # ----------------------------------------------------------------------
  130. #  PRODUCT STATISTICS
  131. # ----------------------------------------------------------------------
  132. test {Check statistics gathered by Hazard base class} {
  133.     set tmp [Toaster #auto]
  134.     set stats [Hazard :: report Toaster]
  135.     $tmp delete
  136.     set stats
  137. } {
  138.     $result == "Toaster: 2 produced, 1 active, 1 accidents"
  139. }
  140.  
  141. test {Check statistics gathered by Hazard base class} {
  142.     Hazard :: report SmartToaster
  143. } {
  144.     $result == "SmartToaster: 1 produced, 1 active, 0 accidents"
  145. }
  146.  
  147. test {Destroy all Toasters} {
  148.     foreach toaster [itcl_info objects -isa Toaster] {
  149.         $toaster clean
  150.         $toaster delete
  151.     }
  152. } {
  153.     $result == ""
  154. }
  155.  
  156. test {SmartToasters should have been destroyed along with Toasters} {
  157.     itcl_info objects -class SmartToaster
  158. } {
  159.     $result == ""
  160. }
  161.  
  162. # ----------------------------------------------------------------------
  163. #  OUTLETS
  164. # ----------------------------------------------------------------------
  165. test {Bill all customers for outlet charges} {
  166.     Outlet :: bill
  167.     puts stdout ">>> should send two bills for outlets via e-mail"
  168. } {
  169.     $result == ""
  170. }
  171.  
  172. test {Destroy all outlets} {
  173.     foreach outlet [itcl_info objects -class Outlet] {
  174.         $outlet delete
  175.     }
  176. } {
  177.     $result == ""
  178. }
  179.