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 | public variable 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 | |
---|
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 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 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 "Info" -ipady 25 -fill both -state disabled |
---|
75 | $itk_component(tabs) insert end "Inputs" -ipady 25 -fill both \ |
---|
76 | -state disabled |
---|
77 | |
---|
78 | itk_component add results { |
---|
79 | Rappture::ResultsPage $itk_component(tabs).results |
---|
80 | } |
---|
81 | $itk_component(tabs) tab configure "Results" \ |
---|
82 | -window $itk_component(tabs).results |
---|
83 | |
---|
84 | itk_component add info { |
---|
85 | text $itk_component(tabs).info |
---|
86 | } |
---|
87 | $itk_component(tabs) tab configure "Info" -window $itk_component(info) |
---|
88 | pack $itk_component(tabs) -expand yes -fill both -side top |
---|
89 | |
---|
90 | itk_component add inputs { |
---|
91 | blt::treeview $itk_component(tabs).inputs -separator . -autocreate true |
---|
92 | } { |
---|
93 | keep -foreground -font -cursor |
---|
94 | } |
---|
95 | $itk_component(tabs) tab configure "Inputs" -window $itk_component(inputs) |
---|
96 | |
---|
97 | eval itk_initialize $args |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | # ---------------------------------------------------------------------- |
---|
102 | # When the -test configuration option is modified, update the display |
---|
103 | # accordingly. The data passed in should be a Test object, or the |
---|
104 | # empty string to clear the display. |
---|
105 | # ---------------------------------------------------------------------- |
---|
106 | itcl::configbody Rappture::Tester::TestView::test { |
---|
107 | # Data array is empty for branch nodes. |
---|
108 | if {$test != ""} { |
---|
109 | if {![$test isa Test]} { |
---|
110 | error "-test option must be a Test object. $test was given." |
---|
111 | } |
---|
112 | if {[$test hasRan]} { |
---|
113 | switch [$test getResult] { |
---|
114 | Pass {showStatus "Test passed."} |
---|
115 | Fail {showStatus "Test failed."} |
---|
116 | Error {showStatus "Error while running test."} |
---|
117 | } |
---|
118 | updateInfo $test |
---|
119 | } else { |
---|
120 | showStatus "Test has not yet ran." |
---|
121 | updateInfo |
---|
122 | } |
---|
123 | updateResults $test |
---|
124 | updateInputs $test |
---|
125 | set descr [[$test getTestobj] get test.description] |
---|
126 | if {$descr == ""} { |
---|
127 | set descr "No description." |
---|
128 | } |
---|
129 | showDescription $descr |
---|
130 | } else { |
---|
131 | # Clear everything if branch node selected |
---|
132 | reset |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | itk::usual TestView { |
---|
137 | keep -background -foreground -font |
---|
138 | } |
---|
139 | |
---|
140 | # ---------------------------------------------------------------------- |
---|
141 | # USAGE: reset |
---|
142 | # |
---|
143 | # Resets the entire TestView widget back to the default state. |
---|
144 | # ---------------------------------------------------------------------- |
---|
145 | itcl::body Rappture::Tester::TestView::reset {} { |
---|
146 | updateResults |
---|
147 | updateInfo |
---|
148 | updateInputs |
---|
149 | showStatus "" |
---|
150 | showDescription "" |
---|
151 | } |
---|
152 | |
---|
153 | # ---------------------------------------------------------------------- |
---|
154 | # USAGE: showDescription <text> |
---|
155 | # |
---|
156 | # Displays a string in the description text space near the top of the |
---|
157 | # widget. If given an empty string, disable the sunken relief effect |
---|
158 | # to partially hide the text box. |
---|
159 | # ---------------------------------------------------------------------- |
---|
160 | itcl::body Rappture::Tester::TestView::showDescription {text} { |
---|
161 | $itk_component(description) configure -state normal |
---|
162 | $itk_component(description) delete 0.0 end |
---|
163 | $itk_component(description) insert end "$text" |
---|
164 | $itk_component(description) configure -state disabled |
---|
165 | if {$text == ""} { |
---|
166 | $itk_component(description) configure -relief flat |
---|
167 | } else { |
---|
168 | $itk_component(description) configure -relief sunken |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | # ---------------------------------------------------------------------- |
---|
173 | # USAGE: showStatus <text> |
---|
174 | # |
---|
175 | # Displays a string in the status info space at the top of the widget. |
---|
176 | # ---------------------------------------------------------------------- |
---|
177 | itcl::body Rappture::Tester::TestView::showStatus {text} { |
---|
178 | $itk_component(status) configure -text "$text" |
---|
179 | } |
---|
180 | |
---|
181 | # ---------------------------------------------------------------------- |
---|
182 | # USAGE: updateResults ?test? |
---|
183 | # |
---|
184 | # Clears the analyzer and loads the given library objects. Used to load |
---|
185 | # both the golden result as well as the test result. Clears the |
---|
186 | # analyzer space if no arguments are given. |
---|
187 | # ---------------------------------------------------------------------- |
---|
188 | itcl::body Rappture::Tester::TestView::updateResults {args} { |
---|
189 | $itk_component(results) clear -nodelete |
---|
190 | if {[llength $args] == 0} { |
---|
191 | # Already cleared, do nothing. |
---|
192 | } elseif {[llength $args] == 1} { |
---|
193 | $itk_component(results) load [$test getTestobj] |
---|
194 | if {[$test hasRan]} { |
---|
195 | $itk_component(results) load [$test getRunobj] |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | } |
---|
200 | |
---|
201 | # ---------------------------------------------------------------------- |
---|
202 | # USAGE: updateInfo ?test? |
---|
203 | # |
---|
204 | # Given a set of key value pairs from the test tree, update the info |
---|
205 | # page of the testview widget. If no arguments are given, disable the |
---|
206 | # info page. |
---|
207 | # ---------------------------------------------------------------------- |
---|
208 | itcl::body Rappture::Tester::TestView::updateInfo {args} { |
---|
209 | if {[llength $args] == 0} { |
---|
210 | $itk_component(info) delete 0.0 end |
---|
211 | set index [$itk_component(tabs) index -name "Results"] |
---|
212 | $itk_component(tabs) select $index |
---|
213 | $itk_component(tabs) focus $index |
---|
214 | $itk_component(tabs) tab configure "Info" -state disabled |
---|
215 | } elseif {[llength $args] == 1} { |
---|
216 | set testxml [$test getTestxml] |
---|
217 | set runfile [$test getRunfile] |
---|
218 | $itk_component(tabs) tab configure "Info" -state normal |
---|
219 | $itk_component(info) delete 0.0 end |
---|
220 | $itk_component(info) insert end "Test xml: $testxml\n" |
---|
221 | $itk_component(info) insert end "Runfile: $runfile\n" |
---|
222 | if {[$test getResult] == "Fail"} { |
---|
223 | set diffs [$test getDiffs] |
---|
224 | set missing [$test getMissing] |
---|
225 | set added [$test getAdded] |
---|
226 | $itk_component(info) insert end "Diffs: $diffs\n" |
---|
227 | $itk_component(info) insert end "Missing: $missing\n" |
---|
228 | $itk_component(info) insert end "Added: $added\n" |
---|
229 | } |
---|
230 | } else { |
---|
231 | error "wrong # args: should be \"updateInfo ?test?\"" |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | itcl::body Rappture::Tester::TestView::updateInputs {args} { |
---|
236 | if {[llength $args] == 0} { |
---|
237 | set index [$itk_component(tabs) index -name "Results"] |
---|
238 | $itk_component(tabs) select $index |
---|
239 | $itk_component(tabs) focus $index |
---|
240 | $itk_component(tabs) tab configure "Inputs" -state disabled |
---|
241 | } elseif {[llength $args] == 1} { |
---|
242 | $itk_component(tabs) tab configure "Inputs" -state normal |
---|
243 | } else { |
---|
244 | error "wrong # args: should be \"updateInfo ?test?\"" |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|