source: branches/blt4/tester/testview.tcl @ 2098

Last change on this file since 2098 was 2098, checked in by gah, 11 years ago
File size: 8.6 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: testview - display the results of a test
3#
4#  Entire right hand side of the regression tester.  Displays the
5#  golden test results, and compares them to the new results if the test
6#  has been ran.  The -test configuration option is used to provide a
7#  Test object to display.
8# ======================================================================
9#  AUTHOR:  Ben Rafferty, Purdue University
10#  Copyright (c) 2010  Purdue Research Foundation
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15package require Itk
16package require BLT
17
18namespace eval Rappture::Tester::TestView { #forward declaration }
19
20option add *TestView.font \
21    -*-helvetica-medium-r-normal-*-12-* widgetDefault
22option add *TestView.codeFont \
23    -*-courier-medium-r-normal-*-12-* widgetDefault
24option add *TestView.textFont \
25    -*-helvetica-medium-r-normal-*-12-* widgetDefault
26option add *TestView.boldTextFont \
27    -*-helvetica-bold-r-normal-*-12-* widgetDefault
28
29itcl::class Rappture::Tester::TestView {
30    inherit itk::Widget
31
32    itk_option define -test test Test ""
33
34    constructor {args} { #defined later }
35
36    protected method reset
37    protected method showDescription {text}
38    protected method showStatus {text}
39    protected method updateResults {args}
40    protected method updateInfo {args}
41    protected method updateInputs {args}
42    private variable _lastTest ""
43}
44
45# ----------------------------------------------------------------------
46# CONSTRUCTOR
47# ----------------------------------------------------------------------
48itcl::body Rappture::Tester::TestView::constructor {args} {
49
50    itk_component add status {
51        label $itk_interior.status
52    }
53    pack $itk_component(status) -expand no -fill none -side top -anchor w
54
55    itk_component add scroller {
56        Rappture::Scroller $itk_interior.scroller \
57            -xscrollmode auto -yscrollmode auto
58    }
59
60    itk_component add description {
61        text $itk_interior.scroller.description -height 0 -wrap word \
62            -relief flat
63    }
64    $itk_component(scroller) contents $itk_component(description)
65    pack $itk_component(scroller) -expand no -fill x -side top
66
67    itk_component add tabs {
68        blt::tabset $itk_interior.tabs -borderwidth 1  \
69                -outerborderwidth 1 \
70            -tearoff 0 -highlightthickness 0 \
71            -selectbackground #ffffcd
72    } {
73    }
74    $itk_component(tabs) insert end "Results" -fill both
75    $itk_component(tabs) insert end "Info" -fill both -state disabled
76    $itk_component(tabs) insert end "Inputs" -fill both \
77        -state disabled
78
79    itk_component add results {
80        Rappture::ResultsPage $itk_component(tabs).results
81    }
82    $itk_component(tabs) tab configure "Results" \
83        -window $itk_component(tabs).results
84
85    itk_component add info {
86        text $itk_component(tabs).info
87    }
88    $itk_component(tabs) tab configure "Info" -window $itk_component(info)
89    pack $itk_component(tabs) -expand yes -fill both -side top
90
91    itk_component add inputs {
92        blt::treeview $itk_component(tabs).inputs -separator . -autocreate true
93    } {
94        keep -foreground -font -cursor
95    }
96    $itk_component(tabs) tab configure "Inputs" -window $itk_component(inputs)
97
98    eval itk_initialize $args
99
100}
101
102# ----------------------------------------------------------------------
103# When the -test configuration option is modified, update the display
104# accordingly.  The data passed in should be a Test object, or the
105# empty string to clear the display.
106# ----------------------------------------------------------------------
107itcl::configbody Rappture::Tester::TestView::test {
108    set test $itk_option(-test)
109    if { $test == $_lastTest } {
110        return
111    }
112    # Data array is empty for branch nodes.
113    if {$test != ""} {
114        if {![$test isa Test]} {
115            error "-test option must be a Test object.  $test was given."
116        }
117        if {[$test hasRan]} {
118            switch [$test getResult] {
119                Pass {showStatus "Test passed."}
120                Fail {showStatus "Test failed."}
121                Error {showStatus "Error while running test."}
122            }
123        } else {
124            showStatus "Test has not yet ran."
125        }
126        updateResults
127        updateInfo
128        updateInputs
129        set descr [[$test getTestobj] get test.description]
130        if {$descr == ""} {
131            set descr "No description."
132        }
133        showDescription $descr
134        set _lastTest $test
135    } else {
136       # Clear everything if branch node selected
137        set _lastTest ""
138       reset
139    }
140}
141
142itk::usual TestView {
143    keep -background -foreground -font
144}
145
146# ----------------------------------------------------------------------
147# USAGE: reset
148#
149# Resets the entire TestView widget back to the default state.
150# ----------------------------------------------------------------------
151itcl::body Rappture::Tester::TestView::reset {} {
152    updateResults
153    updateInfo
154    updateInputs
155    showStatus ""
156    showDescription ""
157}
158
159# ----------------------------------------------------------------------
160# USAGE: showDescription <text>
161#
162# Displays a string in the description text space near the top of the
163# widget.  If given an empty string, disable the sunken relief effect
164# to partially hide the text box.
165# ----------------------------------------------------------------------
166itcl::body Rappture::Tester::TestView::showDescription {text} {
167    $itk_component(description) configure -state normal
168    $itk_component(description) delete 0.0 end
169    $itk_component(description) insert end "$text"
170    $itk_component(description) configure -state disabled
171    if {$text == ""} {
172        $itk_component(description) configure -relief flat
173    } else {
174        $itk_component(description) configure -relief sunken
175    }
176}
177
178# ----------------------------------------------------------------------
179# USAGE: showStatus <text>
180#
181# Displays a string in the status info space at the top of the widget.
182# ----------------------------------------------------------------------
183itcl::body Rappture::Tester::TestView::showStatus {text} {
184    $itk_component(status) configure -text "$text"
185}
186
187# ----------------------------------------------------------------------
188# USAGE: updateResults
189# ----------------------------------------------------------------------
190itcl::body Rappture::Tester::TestView::updateResults {} {
191    $itk_component(results) clear -nodelete
192    set test $itk_option(-test)
193    if {$test == ""} {
194        # Already cleared, do nothing.
195        # TODO: Eventually display some kinds of message here.
196    } else {
197        set test $itk_option(-test)
198        $itk_component(results) load [$test getTestobj]
199        if {[$test hasRan]} {
200            $itk_component(results) load [$test getRunobj]
201        }
202    }
203}
204
205# ----------------------------------------------------------------------
206# USAGE: updateInfo
207# ----------------------------------------------------------------------
208itcl::body Rappture::Tester::TestView::updateInfo {} {
209    set test $itk_option(-test)
210    if {$test == "" || ![$test hasRan]} {
211        $itk_component(info) delete 0.0 end
212        set index [$itk_component(tabs) index "Results"]
213        $itk_component(tabs) select $index
214        $itk_component(tabs) focus $index
215        $itk_component(tabs) tab configure "Info" -state disabled
216    } else {
217        set test $itk_option(-test)
218        set testxml [$test getTestxml]
219        set runfile [$test getRunfile]
220        $itk_component(tabs) tab configure "Info" -state normal
221        $itk_component(info) delete 0.0 end
222        $itk_component(info) insert end "Test xml: $testxml\n"
223        $itk_component(info) insert end "Runfile: $runfile\n"
224        if {[$test getResult] == "Fail"} {
225            set diffs [$test getDiffs]
226            set missing [$test getMissing]
227            set added [$test getAdded]
228            $itk_component(info) insert end "Diffs: $diffs\n"
229            $itk_component(info) insert end "Missing: $missing\n"
230            $itk_component(info) insert end "Added: $added\n"
231        }
232    }
233}
234
235itcl::body Rappture::Tester::TestView::updateInputs {} {
236    set test $itk_option(-test)
237    if {$test == ""} {
238        set index [$itk_component(tabs) index "Results"]
239        $itk_component(tabs) select $index
240        $itk_component(tabs) focus $index
241        $itk_component(tabs) tab configure "Inputs" -state disabled
242    } else {
243        set test $itk_option(-test)
244        $itk_component(tabs) tab configure "Inputs" -state normal
245    }
246}
247
Note: See TracBrowser for help on using the repository browser.