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 | # ====================================================================== |
---|
15 | package require Itk |
---|
16 | package require BLT |
---|
17 | |
---|
18 | namespace eval Rappture::Tester::TestView { #forward declaration } |
---|
19 | |
---|
20 | option add *TestView.font \ |
---|
21 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
22 | option add *TestView.codeFont \ |
---|
23 | -*-courier-medium-r-normal-*-12-* widgetDefault |
---|
24 | option add *TestView.textFont \ |
---|
25 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
26 | option add *TestView.boldTextFont \ |
---|
27 | -*-helvetica-bold-r-normal-*-12-* widgetDefault |
---|
28 | |
---|
29 | itcl::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 {} |
---|
40 | protected method updateInputs {} |
---|
41 | protected method updateOutputs {} |
---|
42 | |
---|
43 | } |
---|
44 | |
---|
45 | # ---------------------------------------------------------------------- |
---|
46 | # CONSTRUCTOR |
---|
47 | # ---------------------------------------------------------------------- |
---|
48 | itcl::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 descScroller { |
---|
56 | Rappture::Scroller $itk_interior.descScroller \ |
---|
57 | -xscrollmode auto -yscrollmode auto |
---|
58 | } |
---|
59 | |
---|
60 | itk_component add description { |
---|
61 | text $itk_interior.descScroller.description -height 0 -wrap word \ |
---|
62 | -relief flat |
---|
63 | } |
---|
64 | $itk_component(descScroller) contents $itk_component(description) |
---|
65 | pack $itk_component(descScroller) -expand no -fill x -side top |
---|
66 | |
---|
67 | itk_component add tabs { |
---|
68 | blt::tabset $itk_interior.tabs -borderwidth 0 -relief flat \ |
---|
69 | -side left -tearoff 0 -highlightthickness 0 \ |
---|
70 | -selectbackground $itk_option(-background) |
---|
71 | } { |
---|
72 | } |
---|
73 | $itk_component(tabs) insert end "Results" -ipady 25 -fill both |
---|
74 | $itk_component(tabs) insert end "Inputs" -ipady 25 -fill both \ |
---|
75 | -state disabled |
---|
76 | $itk_component(tabs) insert end "Outputs" -ipady 25 -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 inputScroller { |
---|
86 | Rappture::Scroller $itk_component(tabs).inputScroller \ |
---|
87 | -xscrollmode auto -yscrollmode auto |
---|
88 | } |
---|
89 | |
---|
90 | itk_component add inputs { |
---|
91 | blt::treeview $itk_component(inputScroller).inputs -separator . \ |
---|
92 | -autocreate true |
---|
93 | } { |
---|
94 | keep -foreground -font -cursor |
---|
95 | } |
---|
96 | $itk_component(inputs) column insert end "Value" |
---|
97 | $itk_component(inputScroller) contents $itk_component(inputs) |
---|
98 | $itk_component(tabs) tab configure "Inputs" \ |
---|
99 | -window $itk_component(inputScroller) |
---|
100 | |
---|
101 | itk_component add outputScroller { |
---|
102 | Rappture::Scroller $itk_component(tabs).outputScroller \ |
---|
103 | -xscrollmode auto -yscrollmode auto |
---|
104 | } |
---|
105 | |
---|
106 | itk_component add outputs { |
---|
107 | blt::treeview $itk_component(outputScroller).outputs -separator . \ |
---|
108 | -autocreate true |
---|
109 | } { |
---|
110 | keep -foreground -font -cursor |
---|
111 | } |
---|
112 | $itk_component(outputs) column insert end "Status" |
---|
113 | $itk_component(outputScroller) contents $itk_component(outputs) |
---|
114 | $itk_component(tabs) tab configure "Outputs" \ |
---|
115 | -window $itk_component(outputScroller) |
---|
116 | |
---|
117 | pack $itk_component(tabs) -expand yes -fill both -side top |
---|
118 | |
---|
119 | eval itk_initialize $args |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | # ---------------------------------------------------------------------- |
---|
124 | # When the -test configuration option is modified, update the display |
---|
125 | # accordingly. The data passed in should be a Test object, or an empty |
---|
126 | # string to clear the display. |
---|
127 | # ---------------------------------------------------------------------- |
---|
128 | itcl::configbody Rappture::Tester::TestView::test { |
---|
129 | set test $itk_option(-test) |
---|
130 | # If an empty string is passed in then clear everything |
---|
131 | if {$test == ""} { |
---|
132 | reset |
---|
133 | } else { |
---|
134 | if {![$test isa Test]} { |
---|
135 | error "-test option must be a Test object. $test was given." |
---|
136 | } |
---|
137 | if {[$test hasRan]} { |
---|
138 | switch [$test getResult] { |
---|
139 | Pass {showStatus "Test passed."} |
---|
140 | Fail {showStatus "Test failed."} |
---|
141 | Error {showStatus "Error while running test."} |
---|
142 | } |
---|
143 | } else { |
---|
144 | showStatus "Test has not yet ran." |
---|
145 | } |
---|
146 | updateResults |
---|
147 | updateInputs |
---|
148 | updateOutputs |
---|
149 | set descr [[$test getTestobj] get test.description] |
---|
150 | if {$descr == ""} { |
---|
151 | set descr "No description." |
---|
152 | } |
---|
153 | showDescription $descr |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | itk::usual TestView { |
---|
158 | keep -background -foreground -font |
---|
159 | } |
---|
160 | |
---|
161 | # ---------------------------------------------------------------------- |
---|
162 | # USAGE: reset |
---|
163 | # |
---|
164 | # Resets the entire TestView widget back to the default state. |
---|
165 | # ---------------------------------------------------------------------- |
---|
166 | itcl::body Rappture::Tester::TestView::reset {} { |
---|
167 | updateResults |
---|
168 | updateInputs |
---|
169 | updateOutputs |
---|
170 | showStatus "" |
---|
171 | showDescription "" |
---|
172 | } |
---|
173 | |
---|
174 | # ---------------------------------------------------------------------- |
---|
175 | # USAGE: showDescription <text> |
---|
176 | # |
---|
177 | # Displays a string in the description text space near the top of the |
---|
178 | # widget. If given an empty string, disable the sunken relief effect |
---|
179 | # to partially hide the text box. |
---|
180 | # ---------------------------------------------------------------------- |
---|
181 | itcl::body Rappture::Tester::TestView::showDescription {text} { |
---|
182 | $itk_component(description) configure -state normal |
---|
183 | $itk_component(description) delete 0.0 end |
---|
184 | $itk_component(description) insert end "$text" |
---|
185 | $itk_component(description) configure -state disabled |
---|
186 | if {$text == ""} { |
---|
187 | $itk_component(description) configure -relief flat |
---|
188 | } else { |
---|
189 | $itk_component(description) configure -relief sunken |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | # ---------------------------------------------------------------------- |
---|
194 | # USAGE: showStatus <text> |
---|
195 | # |
---|
196 | # Displays a string in the status info space at the top of the widget. |
---|
197 | # ---------------------------------------------------------------------- |
---|
198 | itcl::body Rappture::Tester::TestView::showStatus {text} { |
---|
199 | $itk_component(status) configure -text "$text" |
---|
200 | } |
---|
201 | |
---|
202 | # ---------------------------------------------------------------------- |
---|
203 | # USAGE: updateResults |
---|
204 | # ---------------------------------------------------------------------- |
---|
205 | itcl::body Rappture::Tester::TestView::updateResults {} { |
---|
206 | $itk_component(results) clear -nodelete |
---|
207 | set test $itk_option(-test) |
---|
208 | if {$test == ""} { |
---|
209 | # Already cleared, do nothing. |
---|
210 | # TODO: Eventually display some kinds of message here. |
---|
211 | } else { |
---|
212 | set test $itk_option(-test) |
---|
213 | $itk_component(results) load [$test getTestobj] |
---|
214 | if {[$test hasRan] && [Rappture::library isvalid [$test getRunobj]]} { |
---|
215 | $itk_component(results) load [$test getRunobj] |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | itcl::body Rappture::Tester::TestView::updateInputs {} { |
---|
221 | $itk_component(inputs) delete 0 |
---|
222 | set test $itk_option(-test) |
---|
223 | if {$test != ""} { |
---|
224 | $itk_component(tabs) tab configure "Inputs" -state normal |
---|
225 | foreach {path val} [$test getInputs] { |
---|
226 | $itk_component(inputs) insert end $path -data [list Value $val] |
---|
227 | } |
---|
228 | $itk_component(inputs) open -recurse root |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | itcl::body Rappture::Tester::TestView::updateOutputs {} { |
---|
233 | $itk_component(outputs) delete 0 |
---|
234 | set test $itk_option(-test) |
---|
235 | if {$test != "" && [$test hasRan] && [$test getResult] != "Error"} { |
---|
236 | $itk_component(tabs) tab configure "Outputs" -state normal |
---|
237 | foreach {path status} [$test getOutputs] { |
---|
238 | $itk_component(outputs) insert end $path -data [list Status $status] |
---|
239 | } |
---|
240 | $itk_component(outputs) open -recurse root |
---|
241 | } else { |
---|
242 | $itk_component(tabs) tab configure "Outputs" -state disabled |
---|
243 | # Switch back to results tab if the outputs tab is open and the |
---|
244 | # selected test has not been ran. |
---|
245 | if {[$itk_component(tabs) index select] == \ |
---|
246 | [$itk_component(tabs) index -name "Outputs"]} { |
---|
247 | set index [$itk_component(tabs) index -name "Results"] |
---|
248 | $itk_component(tabs) select $index |
---|
249 | $itk_component(tabs) focus $index |
---|
250 | } |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | |
---|