1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: mainwin - main application window for regression tester |
---|
3 | # |
---|
4 | # This widget acts as the main window for the Rappture regression |
---|
5 | # tester. Constructor accepts the location of the tool.xml of the new |
---|
6 | # version to be tested, and the location of a directory containg test |
---|
7 | # xml files. |
---|
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 Rappture |
---|
17 | package require RapptureGUI |
---|
18 | |
---|
19 | namespace eval Rappture::Tester::MainWin { #forward declaration } |
---|
20 | |
---|
21 | itcl::class Rappture::Tester::MainWin { |
---|
22 | inherit itk::Toplevel |
---|
23 | |
---|
24 | constructor {toolxml testdir args} { #defined later } |
---|
25 | public method runAll {args} |
---|
26 | public method runSelected {args} |
---|
27 | |
---|
28 | private method selectionHandler {} |
---|
29 | private method runTest {id args} |
---|
30 | |
---|
31 | private variable _testdir |
---|
32 | private variable _toolxml |
---|
33 | private variable _toolobj |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | # ---------------------------------------------------------------------- |
---|
38 | # CONSTRUCTOR |
---|
39 | # ---------------------------------------------------------------------- |
---|
40 | itcl::body Rappture::Tester::MainWin::constructor {toolxml testdir args} { |
---|
41 | if {[file exists $toolxml]} { |
---|
42 | set _toolxml $toolxml |
---|
43 | set _toolobj [Rappture::library $_toolxml] |
---|
44 | } else { |
---|
45 | error "File \"$toolxml\" does not exist." |
---|
46 | } |
---|
47 | |
---|
48 | if {[file isdirectory $testdir]} { |
---|
49 | set _testdir $testdir |
---|
50 | } else { |
---|
51 | error "Directory \"$testdir\" does not exist." |
---|
52 | } |
---|
53 | |
---|
54 | itk_component add pw { |
---|
55 | panedwindow $itk_interior.pw |
---|
56 | } { |
---|
57 | } |
---|
58 | pack $itk_component(pw) -expand yes -fill both |
---|
59 | |
---|
60 | itk_component add tree { |
---|
61 | Rappture::Tester::TestTree $itk_component(pw).tree \ |
---|
62 | -command "[itcl::code $itk_interior runSelected]" \ |
---|
63 | -testdir $_testdir \ |
---|
64 | -selectcommand "[itcl::code $itk_interior selectionHandler]" |
---|
65 | } |
---|
66 | $itk_component(pw) add $itk_component(tree) |
---|
67 | |
---|
68 | itk_component add view { |
---|
69 | Rappture::Tester::TestView $itk_component(pw).view \ |
---|
70 | [Rappture::Tool ::#auto $_toolobj [file dirname $_toolxml]] |
---|
71 | } |
---|
72 | $itk_component(pw) add $itk_component(view) |
---|
73 | |
---|
74 | eval itk_initialize $args |
---|
75 | } |
---|
76 | |
---|
77 | # ---------------------------------------------------------------------- |
---|
78 | # USAGE: runAll ?-force? |
---|
79 | # |
---|
80 | # When this method is invoked, all tests contained in the TestTree will |
---|
81 | # be ran sequentially. |
---|
82 | # ---------------------------------------------------------------------- |
---|
83 | itcl::body Rappture::Tester::MainWin::runAll {args} { |
---|
84 | set tests [$itk_component(tree) getTests] |
---|
85 | foreach id $tests { |
---|
86 | runTest $id $args |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | # ---------------------------------------------------------------------- |
---|
91 | # USAGE: runSelected ?-force? |
---|
92 | # |
---|
93 | # When this method is invoked, all tests that are currently selected |
---|
94 | # will be ran. If a branch node (folder) is selected, all of its |
---|
95 | # descendant tests will be ran as well. |
---|
96 | # ---------------------------------------------------------------------- |
---|
97 | itcl::body Rappture::Tester::MainWin::runSelected {args} { |
---|
98 | set selected [$itk_component(tree) getSelected] |
---|
99 | foreach id $selected { |
---|
100 | runTest $id $args |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | # ---------------------------------------------------------------------- |
---|
105 | # USAGE: runTest id ?-force? |
---|
106 | # |
---|
107 | # Called by runAll and runSelected to run a single test at tree node |
---|
108 | # specified by the given id. In most cases, this method should not be |
---|
109 | # called directly. A driver object is generated by the makeDriver |
---|
110 | # procedure in compare.tcl, and the results given by the new version are |
---|
111 | # compared to the test xml by the compare procedure in compare.tcl |
---|
112 | # ---------------------------------------------------------------------- |
---|
113 | itcl::body Rappture::Tester::MainWin::runTest {id args} { |
---|
114 | array set data [$itk_component(tree) getData $id] |
---|
115 | if {$data(ran) && [lsearch -exact $args "-force"]==-1} { |
---|
116 | # Already ran. Skip. |
---|
117 | return |
---|
118 | } |
---|
119 | set data(result) "Running" |
---|
120 | $itk_component(tree) setData $id [array get data] |
---|
121 | |
---|
122 | set driver [Rappture::Tester::makeDriver $_toolxml $data(testxml)] |
---|
123 | set tool [Rappture::Tool ::#auto $driver [file dirname $_toolxml]] |
---|
124 | foreach {status result} [eval $tool run] break |
---|
125 | set data(ran) yes |
---|
126 | if {$status == 0 && [Rappture::library isvalid $result]} { |
---|
127 | set golden [Rappture::library $data(testxml)] |
---|
128 | set diffs [Rappture::Tester::compare $golden $result "output"] |
---|
129 | if {$diffs != ""} { |
---|
130 | set data(result) Fail |
---|
131 | set data(diffs) $diffs |
---|
132 | } else { |
---|
133 | set data(result) Pass |
---|
134 | } |
---|
135 | set data(runfile) [$tool getRunFile] |
---|
136 | } else { |
---|
137 | set data(result) Error |
---|
138 | set data(runfile) "" |
---|
139 | } |
---|
140 | $itk_component(tree) setData $id [array get data] |
---|
141 | |
---|
142 | # Call selectionHandler to refresh right hand side view |
---|
143 | selectionHandler |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | # ---------------------------------------------------------------------- |
---|
148 | # USAGE: selectionHandler |
---|
149 | # |
---|
150 | # Used internally to communicate between the test tree and the right |
---|
151 | # hand side whenever the tree's selection has changed. |
---|
152 | # ---------------------------------------------------------------------- |
---|
153 | itcl::body Rappture::Tester::MainWin::selectionHandler {} { |
---|
154 | array set data [$itk_component(tree) getData focus] |
---|
155 | # Data array is empty for branch nodes |
---|
156 | if {[array names data] != ""} { |
---|
157 | if {$data(testxml) != ""} { |
---|
158 | $itk_component(view) showTest $data(testxml) |
---|
159 | } else { |
---|
160 | $itk_component(view) clearTest |
---|
161 | } |
---|
162 | if {$data(ran)} { |
---|
163 | switch $data(result) { |
---|
164 | Pass {$itk_component(view) showText "Test passed."} |
---|
165 | Fail {$itk_component(view) showText "Diffs: $data(diffs)"} |
---|
166 | Error {$itk_component(view) showText "Error while running test"} |
---|
167 | } |
---|
168 | if {$data(runfile) != ""} { |
---|
169 | $itk_component(view) showResult $data(runfile) |
---|
170 | } else { |
---|
171 | $itk_component(view) clearResult |
---|
172 | } |
---|
173 | } else { |
---|
174 | $itk_component(view) showText "Test has not ben ran." |
---|
175 | $itk_component(view) clearResult |
---|
176 | } |
---|
177 | } else { |
---|
178 | $itk_component(view) showDefault |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|