1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: testview - display the results of a test |
---|
3 | # |
---|
4 | # Entire right hand side of the regression tester. Contains a small |
---|
5 | # text widget, plus two TestAnalyzer widgets. The analyzers are used to |
---|
6 | # show the golden set of results, and the new results if the test has |
---|
7 | # been ran. Constructor requires a tool.xml for the tool being tested. |
---|
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 | |
---|
17 | namespace eval Rappture::Tester::TestView { #forward declaration } |
---|
18 | |
---|
19 | option add *TestView.font \ |
---|
20 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
21 | option add *TestView.codeFont \ |
---|
22 | -*-courier-medium-r-normal-*-12-* widgetDefault |
---|
23 | option add *TestView.textFont \ |
---|
24 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
25 | option add *TestView.boldTextFont \ |
---|
26 | -*-helvetica-bold-r-normal-*-12-* widgetDefault |
---|
27 | |
---|
28 | itcl::class Rappture::Tester::TestView { |
---|
29 | inherit itk::Widget |
---|
30 | |
---|
31 | protected method updateAnalyzer {args} |
---|
32 | protected method showResult {runfile} |
---|
33 | protected method showStatus {text} |
---|
34 | protected method showDescription {text} |
---|
35 | public method update {datapairs} |
---|
36 | public method clear |
---|
37 | |
---|
38 | protected variable _toolobj |
---|
39 | |
---|
40 | constructor {toolxml args} { #defined later } |
---|
41 | } |
---|
42 | |
---|
43 | # ---------------------------------------------------------------------- |
---|
44 | # CONSTRUCTOR |
---|
45 | # ---------------------------------------------------------------------- |
---|
46 | itcl::body Rappture::Tester::TestView::constructor {toolxml args} { |
---|
47 | |
---|
48 | set _toolobj [Rappture::Tool ::#auto [Rappture::library $toolxml] \ |
---|
49 | [file dirname $toolxml]] |
---|
50 | |
---|
51 | itk_component add status { |
---|
52 | label $itk_interior.status |
---|
53 | } |
---|
54 | pack $itk_component(status) -expand no -fill none -side top -anchor w |
---|
55 | |
---|
56 | itk_component add scroller { |
---|
57 | Rappture::Scroller $itk_interior.scroller \ |
---|
58 | -xscrollmode auto -yscrollmode auto |
---|
59 | } |
---|
60 | |
---|
61 | itk_component add description { |
---|
62 | text $itk_interior.scroller.description -height 0 -wrap word \ |
---|
63 | -relief flat |
---|
64 | } |
---|
65 | $itk_component(scroller) contents $itk_component(description) |
---|
66 | pack $itk_component(scroller) -expand no -fill x -side top |
---|
67 | |
---|
68 | itk_component add tabs { |
---|
69 | blt::tabset $itk_interior.tabs -borderwidth 0 -relief flat \ |
---|
70 | -side left -tearoff 0 -highlightthickness 0 \ |
---|
71 | -selectbackground $itk_option(-background) |
---|
72 | } { |
---|
73 | } |
---|
74 | $itk_component(tabs) insert end "Analyzer" -ipady 25 -fill both |
---|
75 | $itk_component(tabs) insert end "Result" -ipady 25 -fill both |
---|
76 | pack $itk_component(tabs) -expand yes -fill both -side top |
---|
77 | |
---|
78 | itk_component add analyzer { |
---|
79 | Rappture::Tester::TestAnalyzer $itk_component(tabs).analyzer $_toolobj |
---|
80 | } |
---|
81 | $itk_component(tabs) tab configure "Analyzer" \ |
---|
82 | -window $itk_component(tabs).analyzer |
---|
83 | |
---|
84 | itk_component add result { |
---|
85 | text $itk_component(tabs).result |
---|
86 | } |
---|
87 | $itk_component(tabs) tab configure "Result" -window $itk_component(result) |
---|
88 | |
---|
89 | eval itk_initialize $args |
---|
90 | } |
---|
91 | |
---|
92 | itk::usual TestView { |
---|
93 | keep -background -foreground -font |
---|
94 | } |
---|
95 | |
---|
96 | # ---------------------------------------------------------------------- |
---|
97 | # USAGE: clear |
---|
98 | # |
---|
99 | # Resets the entire TestView widget back to the default state. |
---|
100 | # ---------------------------------------------------------------------- |
---|
101 | itcl::body Rappture::Tester::TestView::clear {} { |
---|
102 | catch { |
---|
103 | $itk_component(analyzer) clear |
---|
104 | destroy $itk_component(analyzer) |
---|
105 | } |
---|
106 | $itk_component(tabs) invoke [$itk_component(tabs) index -name "Result"] |
---|
107 | $itk_component(tabs) tab configure "Result" -state disabled |
---|
108 | showStatus "" |
---|
109 | showDescription "" |
---|
110 | } |
---|
111 | |
---|
112 | # ---------------------------------------------------------------------- |
---|
113 | # USAGE: updateAnalyzer ?<lib> <lib>...? |
---|
114 | # |
---|
115 | # Clears the analyzer and loads the given library objects. Used to load |
---|
116 | # both the golden result as well as the test result. |
---|
117 | # Destroys the existing analyzer widget and creates a new one. |
---|
118 | # Eventually this should be able to keep the same widget and swap in |
---|
119 | # and out different result sets. |
---|
120 | # ---------------------------------------------------------------------- |
---|
121 | itcl::body Rappture::Tester::TestView::updateAnalyzer {args} { |
---|
122 | catch { |
---|
123 | $itk_component(analyzer) clear |
---|
124 | destroy $itk_component(analyzer) |
---|
125 | } |
---|
126 | itk_component add analyzer { |
---|
127 | Rappture::Tester::TestAnalyzer $itk_component(tabs).analyzer $_toolobj |
---|
128 | } |
---|
129 | $itk_component(tabs) tab configure "Analyzer" \ |
---|
130 | -window $itk_component(analyzer) |
---|
131 | foreach lib $args { |
---|
132 | $itk_component(analyzer) display $lib |
---|
133 | } |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | # ---------------------------------------------------------------------- |
---|
138 | # TODO: fill this in |
---|
139 | # ---------------------------------------------------------------------- |
---|
140 | itcl::body Rappture::Tester::TestView::showResult {runfile} { |
---|
141 | $itk_component(tabs) tab configure "Result" -state normal |
---|
142 | $itk_component(result) delete 0.0 end |
---|
143 | $itk_component(result) insert end $runfile |
---|
144 | } |
---|
145 | |
---|
146 | # ---------------------------------------------------------------------- |
---|
147 | # USAGE: showStatus <text> |
---|
148 | # |
---|
149 | # Displays a string in the status info space at the top of the widget. |
---|
150 | # ---------------------------------------------------------------------- |
---|
151 | itcl::body Rappture::Tester::TestView::showStatus {text} { |
---|
152 | $itk_component(status) configure -text "$text" |
---|
153 | } |
---|
154 | |
---|
155 | # ---------------------------------------------------------------------- |
---|
156 | # USAGE: showDescription <text> |
---|
157 | # |
---|
158 | # Displays a string in the description text space near the top of the |
---|
159 | # widget. If given an empty string, disable the sunken relief effect |
---|
160 | # to partially hide the text box. |
---|
161 | # ---------------------------------------------------------------------- |
---|
162 | itcl::body Rappture::Tester::TestView::showDescription {text} { |
---|
163 | $itk_component(description) configure -state normal |
---|
164 | $itk_component(description) delete 0.0 end |
---|
165 | $itk_component(description) insert end "$text" |
---|
166 | $itk_component(description) configure -state disabled |
---|
167 | if {$text == ""} { |
---|
168 | $itk_component(description) configure -relief flat |
---|
169 | } else { |
---|
170 | $itk_component(description) configure -relief sunken |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | # ---------------------------------------------------------------------- |
---|
175 | # USAGE: update <datapairs> |
---|
176 | # |
---|
177 | # Given a list of key value pairs from the test tree, update both the |
---|
178 | # analyzer and the result tab. |
---|
179 | # ---------------------------------------------------------------------- |
---|
180 | itcl::body Rappture::Tester::TestView::update {datapairs} { |
---|
181 | array set data $datapairs |
---|
182 | # Data array is empty for branch nodes. |
---|
183 | if {[array names data] != ""} { |
---|
184 | if {$data(ran)} { |
---|
185 | switch $data(result) { |
---|
186 | Pass {showStatus "Test passed."} |
---|
187 | Fail {showStatus "Test failed."} |
---|
188 | Error {showStatus "Error while running test."} |
---|
189 | } |
---|
190 | if {$data(runfile) != ""} { |
---|
191 | # HACK: Add a new input to differentiate between golden and |
---|
192 | # test result. Otherwise, the slider at the bottom won't |
---|
193 | # be enabled. |
---|
194 | set golden [Rappture::library $data(testxml)] |
---|
195 | $golden put input.run.current "Golden" |
---|
196 | set result [Rappture::library $data(runfile)] |
---|
197 | $result put input.run.current "Test" |
---|
198 | updateAnalyzer $golden $result |
---|
199 | showResult $data(runfile) |
---|
200 | } |
---|
201 | } else { |
---|
202 | showStatus "Test has not yet ran." |
---|
203 | if {$data(testxml) != ""} { |
---|
204 | updateAnalyzer [Rappture::library $data(testxml)] |
---|
205 | } |
---|
206 | } |
---|
207 | set descr [[Rappture::library $data(testxml)] get test.description] |
---|
208 | if {$descr == ""} { |
---|
209 | set descr "No description." |
---|
210 | } |
---|
211 | showDescription $descr |
---|
212 | } else { |
---|
213 | # clear entire screen if branch node selected |
---|
214 | # clear |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|