[1963] | 1 | # ---------------------------------------------------------------------- |
---|
[2019] | 2 | # COMPONENT: testview - display the results of a test |
---|
[1963] | 3 | # |
---|
[2026] | 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 |
---|
[2055] | 6 | # has been ran. Also show tree representation of all inputs and |
---|
| 7 | # outputs. The -test configuration option is used to provide a Test |
---|
| 8 | # object to display. |
---|
[1963] | 9 | # ====================================================================== |
---|
| 10 | # AUTHOR: Ben Rafferty, Purdue University |
---|
| 11 | # Copyright (c) 2010 Purdue Research Foundation |
---|
| 12 | # |
---|
| 13 | # See the file "license.terms" for information on usage and |
---|
| 14 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 15 | # ====================================================================== |
---|
| 16 | package require Itk |
---|
[2012] | 17 | package require BLT |
---|
[1963] | 18 | |
---|
[1968] | 19 | namespace eval Rappture::Tester::TestView { #forward declaration } |
---|
[1963] | 20 | |
---|
[1968] | 21 | option add *TestView.font \ |
---|
| 22 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
| 23 | option add *TestView.codeFont \ |
---|
| 24 | -*-courier-medium-r-normal-*-12-* widgetDefault |
---|
| 25 | option add *TestView.textFont \ |
---|
| 26 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
| 27 | option add *TestView.boldTextFont \ |
---|
| 28 | -*-helvetica-bold-r-normal-*-12-* widgetDefault |
---|
[1963] | 29 | |
---|
[1968] | 30 | itcl::class Rappture::Tester::TestView { |
---|
| 31 | inherit itk::Widget |
---|
| 32 | |
---|
[2034] | 33 | itk_option define -test test Test "" |
---|
[2019] | 34 | |
---|
[2027] | 35 | constructor {args} { #defined later } |
---|
[2019] | 36 | |
---|
| 37 | protected method reset |
---|
| 38 | protected method showDescription {text} |
---|
| 39 | protected method showStatus {text} |
---|
[2054] | 40 | protected method updateResults {} |
---|
| 41 | protected method updateInputs {} |
---|
| 42 | protected method updateOutputs {} |
---|
[2053] | 43 | |
---|
[1963] | 44 | } |
---|
| 45 | |
---|
[1965] | 46 | # ---------------------------------------------------------------------- |
---|
| 47 | # CONSTRUCTOR |
---|
| 48 | # ---------------------------------------------------------------------- |
---|
[2019] | 49 | itcl::body Rappture::Tester::TestView::constructor {args} { |
---|
| 50 | |
---|
[2009] | 51 | itk_component add status { |
---|
| 52 | label $itk_interior.status |
---|
[1963] | 53 | } |
---|
[2009] | 54 | pack $itk_component(status) -expand no -fill none -side top -anchor w |
---|
[1964] | 55 | |
---|
[2053] | 56 | itk_component add descScroller { |
---|
| 57 | Rappture::Scroller $itk_interior.descScroller \ |
---|
[2009] | 58 | -xscrollmode auto -yscrollmode auto |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | itk_component add description { |
---|
[2053] | 62 | text $itk_interior.descScroller.description -height 0 -wrap word \ |
---|
[2009] | 63 | -relief flat |
---|
| 64 | } |
---|
[2053] | 65 | $itk_component(descScroller) contents $itk_component(description) |
---|
| 66 | pack $itk_component(descScroller) -expand no -fill x -side top |
---|
[2009] | 67 | |
---|
[2010] | 68 | itk_component add tabs { |
---|
| 69 | blt::tabset $itk_interior.tabs -borderwidth 0 -relief flat \ |
---|
| 70 | -side left -tearoff 0 -highlightthickness 0 \ |
---|
[2011] | 71 | -selectbackground $itk_option(-background) |
---|
[2010] | 72 | } { |
---|
| 73 | } |
---|
[2030] | 74 | $itk_component(tabs) insert end "Results" -ipady 25 -fill both |
---|
[2031] | 75 | $itk_component(tabs) insert end "Inputs" -ipady 25 -fill both \ |
---|
[2012] | 76 | -state disabled |
---|
[2053] | 77 | $itk_component(tabs) insert end "Outputs" -ipady 25 -fill both \ |
---|
| 78 | -state disabled |
---|
[2010] | 79 | |
---|
[2031] | 80 | itk_component add results { |
---|
| 81 | Rappture::ResultsPage $itk_component(tabs).results |
---|
| 82 | } |
---|
| 83 | $itk_component(tabs) tab configure "Results" \ |
---|
| 84 | -window $itk_component(tabs).results |
---|
[2010] | 85 | |
---|
[2053] | 86 | itk_component add inputScroller { |
---|
| 87 | Rappture::Scroller $itk_component(tabs).inputScroller \ |
---|
| 88 | -xscrollmode auto -yscrollmode auto |
---|
[1968] | 89 | } |
---|
| 90 | |
---|
[2031] | 91 | itk_component add inputs { |
---|
[2053] | 92 | blt::treeview $itk_component(inputScroller).inputs -separator . \ |
---|
| 93 | -autocreate true |
---|
[2031] | 94 | } { |
---|
| 95 | keep -foreground -font -cursor |
---|
| 96 | } |
---|
[2053] | 97 | $itk_component(inputs) column insert end "Value" |
---|
| 98 | $itk_component(inputScroller) contents $itk_component(inputs) |
---|
| 99 | $itk_component(tabs) tab configure "Inputs" \ |
---|
| 100 | -window $itk_component(inputScroller) |
---|
[2031] | 101 | |
---|
[2053] | 102 | itk_component add outputScroller { |
---|
| 103 | Rappture::Scroller $itk_component(tabs).outputScroller \ |
---|
| 104 | -xscrollmode auto -yscrollmode auto |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | itk_component add outputs { |
---|
| 108 | blt::treeview $itk_component(outputScroller).outputs -separator . \ |
---|
| 109 | -autocreate true |
---|
| 110 | } { |
---|
| 111 | keep -foreground -font -cursor |
---|
| 112 | } |
---|
| 113 | $itk_component(outputs) column insert end "Status" |
---|
| 114 | $itk_component(outputScroller) contents $itk_component(outputs) |
---|
| 115 | $itk_component(tabs) tab configure "Outputs" \ |
---|
| 116 | -window $itk_component(outputScroller) |
---|
| 117 | |
---|
| 118 | pack $itk_component(tabs) -expand yes -fill both -side top |
---|
| 119 | |
---|
[1964] | 120 | eval itk_initialize $args |
---|
[2019] | 121 | |
---|
[1963] | 122 | } |
---|
| 123 | |
---|
[2013] | 124 | # ---------------------------------------------------------------------- |
---|
[2055] | 125 | # CONFIGURATION OPTION: -test |
---|
| 126 | # |
---|
[2019] | 127 | # When the -test configuration option is modified, update the display |
---|
[2054] | 128 | # accordingly. The data passed in should be a Test object, or an empty |
---|
| 129 | # string to clear the display. |
---|
[2019] | 130 | # ---------------------------------------------------------------------- |
---|
| 131 | itcl::configbody Rappture::Tester::TestView::test { |
---|
[2034] | 132 | set test $itk_option(-test) |
---|
[2054] | 133 | # If an empty string is passed in then clear everything |
---|
| 134 | if {$test == ""} { |
---|
| 135 | reset |
---|
| 136 | } else { |
---|
[2019] | 137 | if {![$test isa Test]} { |
---|
| 138 | error "-test option must be a Test object. $test was given." |
---|
| 139 | } |
---|
| 140 | if {[$test hasRan]} { |
---|
| 141 | switch [$test getResult] { |
---|
[2013] | 142 | Pass {showStatus "Test passed."} |
---|
| 143 | Fail {showStatus "Test failed."} |
---|
| 144 | Error {showStatus "Error while running test."} |
---|
| 145 | } |
---|
| 146 | } else { |
---|
| 147 | showStatus "Test has not yet ran." |
---|
| 148 | } |
---|
[2034] | 149 | updateResults |
---|
| 150 | updateInputs |
---|
[2053] | 151 | updateOutputs |
---|
[2031] | 152 | set descr [[$test getTestobj] get test.description] |
---|
[2013] | 153 | if {$descr == ""} { |
---|
| 154 | set descr "No description." |
---|
| 155 | } |
---|
| 156 | showDescription $descr |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
[1966] | 160 | itk::usual TestView { |
---|
| 161 | keep -background -foreground -font |
---|
| 162 | } |
---|
| 163 | |
---|
[2008] | 164 | # ---------------------------------------------------------------------- |
---|
[2013] | 165 | # USAGE: reset |
---|
[2008] | 166 | # |
---|
[2011] | 167 | # Resets the entire TestView widget back to the default state. |
---|
[2008] | 168 | # ---------------------------------------------------------------------- |
---|
[2013] | 169 | itcl::body Rappture::Tester::TestView::reset {} { |
---|
[2031] | 170 | updateResults |
---|
| 171 | updateInputs |
---|
[2053] | 172 | updateOutputs |
---|
[2009] | 173 | showStatus "" |
---|
| 174 | showDescription "" |
---|
[1977] | 175 | } |
---|
| 176 | |
---|
[2008] | 177 | # ---------------------------------------------------------------------- |
---|
[2019] | 178 | # USAGE: showDescription <text> |
---|
| 179 | # |
---|
| 180 | # Displays a string in the description text space near the top of the |
---|
| 181 | # widget. If given an empty string, disable the sunken relief effect |
---|
| 182 | # to partially hide the text box. |
---|
| 183 | # ---------------------------------------------------------------------- |
---|
| 184 | itcl::body Rappture::Tester::TestView::showDescription {text} { |
---|
| 185 | $itk_component(description) configure -state normal |
---|
| 186 | $itk_component(description) delete 0.0 end |
---|
| 187 | $itk_component(description) insert end "$text" |
---|
| 188 | $itk_component(description) configure -state disabled |
---|
| 189 | if {$text == ""} { |
---|
| 190 | $itk_component(description) configure -relief flat |
---|
| 191 | } else { |
---|
| 192 | $itk_component(description) configure -relief sunken |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | # ---------------------------------------------------------------------- |
---|
| 197 | # USAGE: showStatus <text> |
---|
| 198 | # |
---|
| 199 | # Displays a string in the status info space at the top of the widget. |
---|
| 200 | # ---------------------------------------------------------------------- |
---|
| 201 | itcl::body Rappture::Tester::TestView::showStatus {text} { |
---|
| 202 | $itk_component(status) configure -text "$text" |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | # ---------------------------------------------------------------------- |
---|
[2034] | 206 | # USAGE: updateResults |
---|
[2055] | 207 | |
---|
| 208 | # Used internally to update the results tab according to the test |
---|
| 209 | # currently specified by the -test configuration option. Show the |
---|
| 210 | # golden results contained in the test xml, and if the the test has been |
---|
| 211 | # ran, show the new results as well. |
---|
[2008] | 212 | # ---------------------------------------------------------------------- |
---|
[2034] | 213 | itcl::body Rappture::Tester::TestView::updateResults {} { |
---|
[2031] | 214 | $itk_component(results) clear -nodelete |
---|
[2034] | 215 | set test $itk_option(-test) |
---|
| 216 | if {$test == ""} { |
---|
[2031] | 217 | # Already cleared, do nothing. |
---|
[2032] | 218 | # TODO: Eventually display some kinds of message here. |
---|
[2034] | 219 | } else { |
---|
| 220 | set test $itk_option(-test) |
---|
[2031] | 221 | $itk_component(results) load [$test getTestobj] |
---|
[2053] | 222 | if {[$test hasRan] && [Rappture::library isvalid [$test getRunobj]]} { |
---|
[2031] | 223 | $itk_component(results) load [$test getRunobj] |
---|
| 224 | } |
---|
[2011] | 225 | } |
---|
[1968] | 226 | } |
---|
| 227 | |
---|
[2055] | 228 | # ---------------------------------------------------------------------- |
---|
| 229 | # USAGE: updateInputs |
---|
| 230 | # |
---|
| 231 | # Used internally to update the inputs tab according to the test |
---|
| 232 | # currently specified by the -test configuration option. Shows a tree |
---|
| 233 | # representation of all inputs given in the test xml and their given |
---|
| 234 | # values. |
---|
| 235 | # ---------------------------------------------------------------------- |
---|
[2054] | 236 | itcl::body Rappture::Tester::TestView::updateInputs {} { |
---|
[2053] | 237 | $itk_component(inputs) delete 0 |
---|
[2034] | 238 | set test $itk_option(-test) |
---|
[2053] | 239 | if {$test != ""} { |
---|
| 240 | $itk_component(tabs) tab configure "Inputs" -state normal |
---|
| 241 | foreach {path val} [$test getInputs] { |
---|
| 242 | $itk_component(inputs) insert end $path -data [list Value $val] |
---|
[2012] | 243 | } |
---|
[2053] | 244 | $itk_component(inputs) open -recurse root |
---|
[2012] | 245 | } |
---|
[1977] | 246 | } |
---|
| 247 | |
---|
[2055] | 248 | # ---------------------------------------------------------------------- |
---|
| 249 | # USAGE: updateOutputs |
---|
| 250 | # |
---|
| 251 | # Used internally to update the outputs tab according to the test |
---|
| 252 | # currently specified by the -test configuration option. Shows a tree |
---|
| 253 | # representation of all outputs in the runfile generated by the last run |
---|
| 254 | # of the test, along with their status (ok, diff, added, or missing). |
---|
| 255 | # Disable the outputs tab if test has not been ran, or resulted in an |
---|
| 256 | # error. |
---|
| 257 | # ---------------------------------------------------------------------- |
---|
[2054] | 258 | itcl::body Rappture::Tester::TestView::updateOutputs {} { |
---|
[2053] | 259 | $itk_component(outputs) delete 0 |
---|
[2034] | 260 | set test $itk_option(-test) |
---|
[2053] | 261 | if {$test != "" && [$test hasRan] && [$test getResult] != "Error"} { |
---|
| 262 | $itk_component(tabs) tab configure "Outputs" -state normal |
---|
| 263 | foreach {path status} [$test getOutputs] { |
---|
| 264 | $itk_component(outputs) insert end $path -data [list Status $status] |
---|
| 265 | } |
---|
| 266 | $itk_component(outputs) open -recurse root |
---|
[2034] | 267 | } else { |
---|
[2053] | 268 | $itk_component(tabs) tab configure "Outputs" -state disabled |
---|
| 269 | # Switch back to results tab if the outputs tab is open and the |
---|
| 270 | # selected test has not been ran. |
---|
| 271 | if {[$itk_component(tabs) index select] == \ |
---|
| 272 | [$itk_component(tabs) index -name "Outputs"]} { |
---|
| 273 | set index [$itk_component(tabs) index -name "Results"] |
---|
| 274 | $itk_component(tabs) select $index |
---|
| 275 | $itk_component(tabs) focus $index |
---|
| 276 | } |
---|
| 277 | } |
---|
[2031] | 278 | } |
---|
[2053] | 279 | |
---|
| 280 | |
---|
[2031] | 281 | |
---|