1#
2# Tests for "toaster" example
3# ----------------------------------------------------------------------
4#   AUTHOR:  Michael J. McLennan
5#            Bell Labs Innovations for Lucent Technologies
6#            mmclennan@lucent.com
7#            http://www.tcltk.com/itcl
8#
9#      RCS:  $Id: toaster.test,v 1.1 1998/07/27 18:41:26 stanton Exp $
10# ----------------------------------------------------------------------
11#            Copyright (c) 1993-1998  Lucent Technologies, Inc.
12# ======================================================================
13# See the file "license.terms" for information on usage and
14# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
16# ----------------------------------------------------------------------
17#  Get toaster classes from "demos" directory.
18# ----------------------------------------------------------------------
19lappend auto_path toasters
20
21# ----------------------------------------------------------------------
22#  Outlets send bills to an e-mail address.  Determine this address.
23# ----------------------------------------------------------------------
24if {[info exists env(USER)]} {
25	set Owner $env(USER)
26} elseif {[info exists env(LOGNAME)]} {
27	set Owner $env(LOGNAME)
28} else {
29	set Owner [exec logname]
30}
31
32# ----------------------------------------------------------------------
33#  TOASTERS
34# ----------------------------------------------------------------------
35test {Create a toaster and plug it in} {
36	global Owner
37	Toaster original -heat 1 -outlet [Outlet #auto -owner $Owner]
38} {
39	$result == "original"
40}
41
42test {Turn up the heat setting on the toaster} {
43	original config -heat 5
44} {
45	$result == ""
46}
47
48test {Toast a few slices of bread} {
49	original toast 2
50} {
51	$result == "crumb tray: 25% full"
52}
53
54test {Clean the toaster} {
55	original clean
56} {
57	$result == "crumb tray: 0% full"
58}
59
60test {Toast a few slices of bread a few different times} {
61	original clean
62	original toast 2
63	original toast 1
64} {
65	$result == "crumb tray: 38% full"
66}
67
68test {Toast too many slices of bread and cause a fire} {
69	puts stdout ">>> should say \"== FIRE! FIRE! ==\""
70	original clean
71	original toast 2
72	original toast 2
73	original toast 2
74	original toast 2
75} {
76	$result == "crumb tray: 100% full"
77}
78
79test {Destroy the toaster} {
80	original clean
81	original toast 2
82	original toast 1
83	puts stdout ">>> should say \"15 crumbs ... what a mess!\""
84	original delete
85} {
86	$result == ""
87}
88
89# ----------------------------------------------------------------------
90#  SMART TOASTERS
91# ----------------------------------------------------------------------
92test {Create a toaster and plug it in} {
93	global Owner
94	SmartToaster deluxe -heat 4 -outlet [Outlet #auto -owner $Owner]
95} {
96	$result == "deluxe"
97}
98
99test {Toast a few slices of bread} {
100	deluxe toast 2
101} {
102	$result == "crumb tray: 20% full"
103}
104
105test {Toast a few slices of bread and look for auto-clean} {
106	deluxe clean
107	deluxe toast 2
108	deluxe toast 2
109	deluxe toast 2
110	deluxe toast 2
111	deluxe toast 2
112} {
113	$result == "crumb tray: 20% full"
114}
115
116# ----------------------------------------------------------------------
117#  PRODUCT STATISTICS
118# ----------------------------------------------------------------------
119test {Check statistics gathered by Hazard base class} {
120	set tmp [Toaster #auto]
121	set stats [Hazard :: report ::Toaster]
122	$tmp delete
123	set stats
124} {
125	$result == "::Toaster: 2 produced, 1 active, 1 accidents"
126}
127
128test {Check statistics gathered by Hazard base class} {
129	Hazard :: report ::SmartToaster
130} {
131	$result == "::SmartToaster: 1 produced, 1 active, 0 accidents"
132}
133
134test {Destroy all Toasters} {
135	foreach toaster [itcl_info objects -isa Toaster] {
136		$toaster clean
137		$toaster delete
138	}
139} {
140	$result == ""
141}
142
143test {SmartToasters should have been destroyed along with Toasters} {
144	itcl_info objects -class SmartToaster
145} {
146	$result == ""
147}
148
149# ----------------------------------------------------------------------
150#  OUTLETS
151# ----------------------------------------------------------------------
152test {Bill all customers for outlet charges} {
153	Outlet :: bill
154	puts stdout ">>> should send two bills for outlets via e-mail"
155} {
156	$result == ""
157}
158
159test {Destroy all outlets} {
160	foreach outlet [itcl_info objects -class Outlet] {
161		$outlet delete
162	}
163} {
164	$result == ""
165}
166