1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: testtree - provides hierarchical view of regression tests |
---|
3 | # |
---|
4 | # Used to display a collapsible view of all tests found in the test |
---|
5 | # directory. The -command configuration option will be called when |
---|
6 | # the run button is clicked. Provides methods to get all tests or all |
---|
7 | # currently selected tests. Also helps handle data stored in treeview |
---|
8 | # columns. In each test xml, a label must be located at the path |
---|
9 | # test.label. Test labels may be organized hierarchically by using |
---|
10 | # dots to separate components of the test label. |
---|
11 | # ====================================================================== |
---|
12 | # AUTHOR: Ben Rafferty, Purdue University |
---|
13 | # Copyright (c) 2010 Purdue Research Foundation |
---|
14 | # |
---|
15 | # See the file "license.terms" for information on usage and |
---|
16 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
17 | # ====================================================================== |
---|
18 | package require Itk |
---|
19 | package require BLT |
---|
20 | package require Rappture |
---|
21 | |
---|
22 | namespace eval Rappture::Tester::TestTree { #forward declaration } |
---|
23 | |
---|
24 | option add *TestTree.font \ |
---|
25 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
26 | option add *TestTree.codeFont \ |
---|
27 | -*-courier-medium-r-normal-*-12-* widgetDefault |
---|
28 | option add *TestTree.textFont \ |
---|
29 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
30 | option add *TestTree.boldTextFont \ |
---|
31 | -*-helvetica-bold-r-normal-*-12-* widgetDefault |
---|
32 | |
---|
33 | itcl::class Rappture::Tester::TestTree { |
---|
34 | inherit itk::Widget |
---|
35 | |
---|
36 | public variable command |
---|
37 | public variable selectcommand |
---|
38 | public variable testdir |
---|
39 | |
---|
40 | constructor {testdir args} { #defined later } |
---|
41 | public method getTests {{id 0}} |
---|
42 | public method getSelected {} |
---|
43 | public method getData {id} |
---|
44 | public method setData {id data} |
---|
45 | |
---|
46 | private method updateLabel {} |
---|
47 | private method populate {} |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | itk::usual TestTree { |
---|
52 | keep -background -foreground -font |
---|
53 | } |
---|
54 | |
---|
55 | # ---------------------------------------------------------------------- |
---|
56 | # CONSTRUCTOR |
---|
57 | # ---------------------------------------------------------------------- |
---|
58 | itcl::body Rappture::Tester::TestTree::constructor {args} { |
---|
59 | itk_component add scrollbars { |
---|
60 | Rappture::Scroller $itk_interior.scroller \ |
---|
61 | -xscrollmode auto -yscrollmode auto |
---|
62 | } |
---|
63 | itk_component add treeview { |
---|
64 | blt::treeview $itk_component(scrollbars).treeview -separator . \ |
---|
65 | -autocreate true -selectmode multiple |
---|
66 | } { |
---|
67 | keep -foreground -font -cursor |
---|
68 | } |
---|
69 | $itk_component(treeview) column insert 0 result -width 75 |
---|
70 | $itk_component(treeview) column insert end testxml ran diffs runfile |
---|
71 | $itk_component(treeview) column configure testxml ran diffs runfile \ |
---|
72 | -hide yes |
---|
73 | $itk_component(treeview) column configure runfile -hide no |
---|
74 | $itk_component(scrollbars) contents $itk_component(treeview) |
---|
75 | |
---|
76 | itk_component add bottomBar { |
---|
77 | frame $itk_interior.bottomBar |
---|
78 | } |
---|
79 | pack $itk_component(bottomBar) -fill x -side bottom |
---|
80 | |
---|
81 | itk_component add bSelectAll { |
---|
82 | button $itk_component(bottomBar).bSelectAll -text "Select all" \ |
---|
83 | -command "$itk_component(treeview) selection set 0 end" |
---|
84 | } |
---|
85 | pack $itk_component(bSelectAll) -side left |
---|
86 | |
---|
87 | itk_component add bSelectNone { |
---|
88 | button $itk_component(bottomBar).bSelectNone -text "Select none" \ |
---|
89 | -command "$itk_component(treeview) selection clearall" |
---|
90 | } |
---|
91 | pack $itk_component(bSelectNone) -side left |
---|
92 | |
---|
93 | itk_component add bRun { |
---|
94 | button $itk_component(bottomBar).bRun -text "Run" -state disabled |
---|
95 | } { |
---|
96 | keep -command |
---|
97 | } |
---|
98 | pack $itk_component(bRun) -side right |
---|
99 | |
---|
100 | itk_component add lSelected { |
---|
101 | label $itk_component(bottomBar).lSelected -text "0 tests selected" |
---|
102 | } |
---|
103 | pack $itk_component(lSelected) -side right -padx 5 |
---|
104 | |
---|
105 | # TODO: Fix black empty space when columns are shrunk |
---|
106 | |
---|
107 | pack $itk_component(scrollbars) -side left -expand yes -fill both |
---|
108 | |
---|
109 | eval itk_initialize $args |
---|
110 | } |
---|
111 | |
---|
112 | # Repopulate tree if test directory changed |
---|
113 | itcl::configbody Rappture::Tester::TestTree::testdir { |
---|
114 | populate |
---|
115 | } |
---|
116 | |
---|
117 | # Forward the TestTree's selectcommand to the treeview, and update the label |
---|
118 | # as well. |
---|
119 | itcl::configbody Rappture::Tester::TestTree::selectcommand { |
---|
120 | $itk_component(treeview) configure -selectcommand \ |
---|
121 | "[itcl::code $itk_interior updateLabel]; $selectcommand" |
---|
122 | } |
---|
123 | |
---|
124 | # ---------------------------------------------------------------------- |
---|
125 | # USAGE: populate |
---|
126 | # |
---|
127 | # Used internally to insert nodes into the treeview for each test xml |
---|
128 | # found in the test directory. Skips any xml files that do not contain |
---|
129 | # information at path test.label. Relies on the autocreate treeview |
---|
130 | # option so that branch nodes need not be explicitly created. Deletes |
---|
131 | # any nodes previously contained by the treeview. |
---|
132 | # ---------------------------------------------------------------------- |
---|
133 | itcl::body Rappture::Tester::TestTree::populate {} { |
---|
134 | $itk_component(treeview) delete 0 |
---|
135 | # TODO: add an appropriate icon |
---|
136 | set icon [Rappture::icon molvis-3dorth] |
---|
137 | # TODO: Descend through subdirectories inside testdir? |
---|
138 | foreach testxml [glob -nocomplain -directory $testdir *.xml] { |
---|
139 | set lib [Rappture::library $testxml] |
---|
140 | set testpath [$lib get test.label] |
---|
141 | if {$testpath != ""} { |
---|
142 | $itk_component(treeview) insert end $testpath -data \ |
---|
143 | [list testxml $testxml ran no result "" diffs ""] \ |
---|
144 | -icons "$icon $icon" -activeicons "$icon $icon" |
---|
145 | } |
---|
146 | } |
---|
147 | $itk_component(treeview) open -recurse root |
---|
148 | # TODO: Fix width of main treeview column |
---|
149 | } |
---|
150 | |
---|
151 | # ---------------------------------------------------------------------- |
---|
152 | # USAGE: getTests ?id? |
---|
153 | # |
---|
154 | # Returns a list of ids for all tests contained in the tree. If an |
---|
155 | # optional id is given as an input parameter, then the returned list |
---|
156 | # will contain the ids of all tests that are descendants of the given |
---|
157 | # id. Tests can only be leaf nodes in the tree (the ids in the returned |
---|
158 | # list will correspond to leaf nodes only). |
---|
159 | # ---------------------------------------------------------------------- |
---|
160 | itcl::body Rappture::Tester::TestTree::getTests {{id 0}} { |
---|
161 | set clist [$itk_component(treeview) entry children $id] |
---|
162 | if {$clist == "" && $id == 0} { |
---|
163 | # Return nothing if tree is empty |
---|
164 | return "" |
---|
165 | } |
---|
166 | if {$clist == ""} { |
---|
167 | return $id |
---|
168 | } |
---|
169 | set tests [list] |
---|
170 | foreach child $clist { |
---|
171 | set tests [concat $tests [getTests $child]] |
---|
172 | } |
---|
173 | return $tests |
---|
174 | } |
---|
175 | |
---|
176 | # ---------------------------------------------------------------------- |
---|
177 | # USAGE: getSelected |
---|
178 | # |
---|
179 | # Returns a list ids for all currently selected tests (leaf nodes) and |
---|
180 | # the child tests of any currently selected branch nodes. Tests can |
---|
181 | # only be leaf nodes in the tree (the ids in the returned list will |
---|
182 | # correspond to leaf nodes only). |
---|
183 | # ---------------------------------------------------------------------- |
---|
184 | itcl::body Rappture::Tester::TestTree::getSelected {} { |
---|
185 | set selection [$itk_component(treeview) curselection] |
---|
186 | set selectedTests [list] |
---|
187 | foreach id $selection { |
---|
188 | foreach node [getTests $id] { |
---|
189 | if {[lsearch -exact $selectedTests $node] == -1} { |
---|
190 | lappend selectedTests $node |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | return $selectedTests |
---|
195 | } |
---|
196 | |
---|
197 | # ---------------------------------------------------------------------- |
---|
198 | # USAGE: getData <id> |
---|
199 | # |
---|
200 | # Returns a list of key-value pairs representing the column data stored |
---|
201 | # at the tree node with the given id. |
---|
202 | # ---------------------------------------------------------------------- |
---|
203 | itcl::body Rappture::Tester::TestTree::getData {id} { |
---|
204 | return [$itk_component(treeview) entry cget $id -data] |
---|
205 | } |
---|
206 | |
---|
207 | # ---------------------------------------------------------------------- |
---|
208 | # USAGE: setData <id> <data> |
---|
209 | # |
---|
210 | # Accepts a node id and a list of key-value pairs. Stored the list as |
---|
211 | # column data associated with the tree node with the given id. |
---|
212 | # ---------------------------------------------------------------------- |
---|
213 | itcl::body Rappture::Tester::TestTree::setData {id data} { |
---|
214 | $itk_component(treeview) entry configure $id -data $data |
---|
215 | } |
---|
216 | |
---|
217 | # ---------------------------------------------------------------------- |
---|
218 | # USAGE: updateLabel |
---|
219 | # |
---|
220 | # Used internally to update the label which indicates how many tests |
---|
221 | # are currently selected. Also disables the run button if no tests are |
---|
222 | # selected. |
---|
223 | # ---------------------------------------------------------------------- |
---|
224 | itcl::body Rappture::Tester::TestTree::updateLabel {} { |
---|
225 | set n [llength [getSelected]] |
---|
226 | if {$n == 1} { |
---|
227 | $itk_component(lSelected) configure -text "1 test selected" |
---|
228 | } else { |
---|
229 | $itk_component(lSelected) configure -text "$n tests selected" |
---|
230 | } |
---|
231 | |
---|
232 | if {$n > 0} { |
---|
233 | $itk_component(bRun) configure -state normal |
---|
234 | } else { |
---|
235 | $itk_component(bRun) configure -state disabled |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|