#
|
#
|
# Tests for "toaster" example
|
# Tests for "toaster" example
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# AUTHOR: Michael J. McLennan
|
# AUTHOR: Michael J. McLennan
|
# Bell Labs Innovations for Lucent Technologies
|
# Bell Labs Innovations for Lucent Technologies
|
# mmclennan@lucent.com
|
# mmclennan@lucent.com
|
# http://www.tcltk.com/itcl
|
# http://www.tcltk.com/itcl
|
#
|
#
|
# RCS: $Id: toaster.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
# RCS: $Id: toaster.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
# Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
# ======================================================================
|
# ======================================================================
|
# See the file "license.terms" for information on usage and
|
# See the file "license.terms" for information on usage and
|
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# Get toaster classes from "demos" directory.
|
# Get toaster classes from "demos" directory.
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
lappend auto_path toasters
|
lappend auto_path toasters
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# Outlets send bills to an e-mail address. Determine this address.
|
# Outlets send bills to an e-mail address. Determine this address.
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
if {[info exists env(USER)]} {
|
if {[info exists env(USER)]} {
|
set Owner $env(USER)
|
set Owner $env(USER)
|
} elseif {[info exists env(LOGNAME)]} {
|
} elseif {[info exists env(LOGNAME)]} {
|
set Owner $env(LOGNAME)
|
set Owner $env(LOGNAME)
|
} else {
|
} else {
|
set Owner [exec logname]
|
set Owner [exec logname]
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# TOASTERS
|
# TOASTERS
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
test {Create a toaster and plug it in} {
|
test {Create a toaster and plug it in} {
|
global Owner
|
global Owner
|
Toaster original -heat 1 -outlet [Outlet #auto -owner $Owner]
|
Toaster original -heat 1 -outlet [Outlet #auto -owner $Owner]
|
} {
|
} {
|
$result == "original"
|
$result == "original"
|
}
|
}
|
|
|
test {Turn up the heat setting on the toaster} {
|
test {Turn up the heat setting on the toaster} {
|
original config -heat 5
|
original config -heat 5
|
} {
|
} {
|
$result == ""
|
$result == ""
|
}
|
}
|
|
|
test {Toast a few slices of bread} {
|
test {Toast a few slices of bread} {
|
original toast 2
|
original toast 2
|
} {
|
} {
|
$result == "crumb tray: 25% full"
|
$result == "crumb tray: 25% full"
|
}
|
}
|
|
|
test {Clean the toaster} {
|
test {Clean the toaster} {
|
original clean
|
original clean
|
} {
|
} {
|
$result == "crumb tray: 0% full"
|
$result == "crumb tray: 0% full"
|
}
|
}
|
|
|
test {Toast a few slices of bread a few different times} {
|
test {Toast a few slices of bread a few different times} {
|
original clean
|
original clean
|
original toast 2
|
original toast 2
|
original toast 1
|
original toast 1
|
} {
|
} {
|
$result == "crumb tray: 38% full"
|
$result == "crumb tray: 38% full"
|
}
|
}
|
|
|
test {Toast too many slices of bread and cause a fire} {
|
test {Toast too many slices of bread and cause a fire} {
|
puts stdout ">>> should say \"== FIRE! FIRE! ==\""
|
puts stdout ">>> should say \"== FIRE! FIRE! ==\""
|
original clean
|
original clean
|
original toast 2
|
original toast 2
|
original toast 2
|
original toast 2
|
original toast 2
|
original toast 2
|
original toast 2
|
original toast 2
|
} {
|
} {
|
$result == "crumb tray: 100% full"
|
$result == "crumb tray: 100% full"
|
}
|
}
|
|
|
test {Destroy the toaster} {
|
test {Destroy the toaster} {
|
original clean
|
original clean
|
original toast 2
|
original toast 2
|
original toast 1
|
original toast 1
|
puts stdout ">>> should say \"15 crumbs ... what a mess!\""
|
puts stdout ">>> should say \"15 crumbs ... what a mess!\""
|
original delete
|
original delete
|
} {
|
} {
|
$result == ""
|
$result == ""
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# SMART TOASTERS
|
# SMART TOASTERS
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
test {Create a toaster and plug it in} {
|
test {Create a toaster and plug it in} {
|
global Owner
|
global Owner
|
SmartToaster deluxe -heat 4 -outlet [Outlet #auto -owner $Owner]
|
SmartToaster deluxe -heat 4 -outlet [Outlet #auto -owner $Owner]
|
} {
|
} {
|
$result == "deluxe"
|
$result == "deluxe"
|
}
|
}
|
|
|
test {Toast a few slices of bread} {
|
test {Toast a few slices of bread} {
|
deluxe toast 2
|
deluxe toast 2
|
} {
|
} {
|
$result == "crumb tray: 20% full"
|
$result == "crumb tray: 20% full"
|
}
|
}
|
|
|
test {Toast a few slices of bread and look for auto-clean} {
|
test {Toast a few slices of bread and look for auto-clean} {
|
deluxe clean
|
deluxe clean
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
deluxe toast 2
|
} {
|
} {
|
$result == "crumb tray: 20% full"
|
$result == "crumb tray: 20% full"
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# PRODUCT STATISTICS
|
# PRODUCT STATISTICS
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
test {Check statistics gathered by Hazard base class} {
|
test {Check statistics gathered by Hazard base class} {
|
set tmp [Toaster #auto]
|
set tmp [Toaster #auto]
|
set stats [Hazard :: report ::Toaster]
|
set stats [Hazard :: report ::Toaster]
|
$tmp delete
|
$tmp delete
|
set stats
|
set stats
|
} {
|
} {
|
$result == "::Toaster: 2 produced, 1 active, 1 accidents"
|
$result == "::Toaster: 2 produced, 1 active, 1 accidents"
|
}
|
}
|
|
|
test {Check statistics gathered by Hazard base class} {
|
test {Check statistics gathered by Hazard base class} {
|
Hazard :: report ::SmartToaster
|
Hazard :: report ::SmartToaster
|
} {
|
} {
|
$result == "::SmartToaster: 1 produced, 1 active, 0 accidents"
|
$result == "::SmartToaster: 1 produced, 1 active, 0 accidents"
|
}
|
}
|
|
|
test {Destroy all Toasters} {
|
test {Destroy all Toasters} {
|
foreach toaster [itcl_info objects -isa Toaster] {
|
foreach toaster [itcl_info objects -isa Toaster] {
|
$toaster clean
|
$toaster clean
|
$toaster delete
|
$toaster delete
|
}
|
}
|
} {
|
} {
|
$result == ""
|
$result == ""
|
}
|
}
|
|
|
test {SmartToasters should have been destroyed along with Toasters} {
|
test {SmartToasters should have been destroyed along with Toasters} {
|
itcl_info objects -class SmartToaster
|
itcl_info objects -class SmartToaster
|
} {
|
} {
|
$result == ""
|
$result == ""
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# OUTLETS
|
# OUTLETS
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
test {Bill all customers for outlet charges} {
|
test {Bill all customers for outlet charges} {
|
Outlet :: bill
|
Outlet :: bill
|
puts stdout ">>> should send two bills for outlets via e-mail"
|
puts stdout ">>> should send two bills for outlets via e-mail"
|
} {
|
} {
|
$result == ""
|
$result == ""
|
}
|
}
|
|
|
test {Destroy all outlets} {
|
test {Destroy all outlets} {
|
foreach outlet [itcl_info objects -class Outlet] {
|
foreach outlet [itcl_info objects -class Outlet] {
|
$outlet delete
|
$outlet delete
|
}
|
}
|
} {
|
} {
|
$result == ""
|
$result == ""
|
}
|
}
|
|
|