1
# This file contains the test driver for the html widget. It defines
2
# a special version of the test procedure to use for testing the
6
# $Id: engine.tcl,v 1.2 2003/01/28 05:01:05 hkoba Exp $
8
# Make sure the html widget is loaded into
11
if {[info command html]==""} {
12
if {[catch {package require Tkhtml} error]} {
16
/usr/lib/libTkhtml*.so
17
/usr/local/lib/libTkhtml*.so
20
if {[set f [lindex [glob -nocomplain $f] end]] != ""} {
21
if {[catch {load $f Tkhtml}]==0} break
27
# Initialize variables
29
namespace eval tcltest {
40
# tag A symbolic tag for this test. Ex: html-1.0
42
# desc A human-readable description of what this test does.
44
# script Tcl code to implement the test
46
# result The expected result from this test. If the actual result
47
# is different the test fails.
49
proc ::tcltest::test {tag desc script result} {
50
::tcltest::change-desc $tag $desc
51
if {[info exists ::tcltest::idle]} {
52
catch {after cancel $::tcltest::idle}
53
catch {unset ::tcltest::idle}
55
set rc [catch {uplevel #0 $script} msg]
58
incr ::tcltest::passed
59
puts "---- Test $tag passed"
61
incr ::tcltest::failed
62
puts "**** Test $tag failed"
63
puts "Expected: [list $result]"
67
::tcltest::update-status
68
set ::tcltest::idle [after 100 ::tcltest::testing-complete]
71
# Create the test control window
73
proc ::tcltest::mainwin {} {
76
wm title $w {Html Widget Test Information}
77
wm iconname $w {Html-Test}
80
pack $f -side top -fill x
81
label $f.l -text {Status: }
82
label $f.v -textvariable ::tcltest::status
83
pack $f.l $f.v -side left
86
pack $f -side top -fill x
87
label $f.l -text {Current Test: }
88
label $f.v -textvariable ::tcltest::current
89
pack $f.l $f.v -side left
92
pack $f -side bottom -fill x
93
button $f.pause -text Pause -command ::tcltest::pause
94
button $f.pass -text {Pass} -command {::tcltest::set-result pass}
95
button $f.fail -text {Fail} -command {::tcltest::set-result fail}
96
button $f.exit -text Exit -command exit
97
pack $f.pause $f.pass $f.fail $f.exit -side right -pady 10 -expand 1
98
scrollbar $w.sb -orient vertical -command "$w.t yview"
99
pack $w.sb -side right -fill y
100
html $w.t -yscrollcommand "$w.sb set" -width 400 -height 150 \
101
-bd 2 -relief sunken -padx 5 -pady 5
102
pack $w.t -side right -fill both -expand 1
103
::tcltest::update-status
106
# Change the test description in the control window
108
proc ::tcltest::change-desc {tag desc} {
109
if {![winfo exists .testinfo]} ::tcltest::mainwin
111
.testinfo.t parse $desc\n
112
set ::tcltest::current $tag
115
# Update the status line
117
proc ::tcltest::update-status {} {
118
set v "$::tcltest::passed passed $::tcltest::failed failed "
119
append v "$::tcltest::total total"
120
set ::tcltest::status $v
123
# Wait for the user to press either the pass or failed buttons.
125
proc ::tcltest::user-result {} {
126
.testinfo.b.pass config -state normal
127
.testinfo.b.fail config -state normal
130
focus .testinfo.b.pass
131
set ::tcltest::result {}
132
vwait ::tcltest::result
133
.testinfo.b.pass config -state disabled
134
.testinfo.b.fail config -state disabled
135
return $::tcltest::result
138
# Called when the user presses either the failed or passed buttons.
140
proc ::tcltest::set-result v {
141
set ::tcltest::result $v
144
# Call this routine at the end of all tests
146
proc ::tcltest::testing-complete {} {
147
::tcltest::change-desc {} {Testing is now complete}
150
# Construct an HTML widget to use for testing.
152
proc tkhtml_test_widget {} {
154
if {[winfo exists $w]} {
158
wm title $w {TkHtml Test Widget}
159
wm iconname $w {TkHtml Test}
160
scrollbar $w.sb -orient vertical -command "$w.h yview"
161
pack $w.sb -side right -fill y
162
html $w.h -yscrollcommand "$w.sb set"
163
pack $w.h -side right -fill both -expand 1