blob: f63265722a93174e97c83f0a44c31eb870f49cdf [file] [log] [blame]
ndaib8cedc82005-09-13 18:00:32 +00001<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
2<xsl:output method="html" indent="yes"/>
3<xsl:decimal-format decimal-separator="." grouping-separator="," />
4
5<xsl:template match="testsuites">
6 <HTML>
7 <HEAD>
8 <style type="text/css">
9 body {
10 font:normal 68% verdana,arial,helvetica;
11 color:#000000;
12 }
13 table tr td, table tr th {
14 font-size: 68%;
15 }
16 table.details tr th{
17 font-weight: bold;
18 text-align:left;
19 background:#a6caf0;
20 }
21 table.details tr td{
22 background:#eeeee0;
23 }
24
25 p {
26 line-height:1.5em;
27 margin-top:0.5em; margin-bottom:1.0em;
28 }
29 h1 {
30 margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
31 }
32 h2 {
33 margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
34 }
35 h3 {
36 margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
37 }
38 h4 {
39 margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
40 }
41 h5 {
42 margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
43 }
44 h6 {
45 margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
46 }
47 .Error {
48 font-weight:bold; color:red;
49 }
50 .Failure {
51 font-weight:bold; color:purple;
52 }
53 .Properties {
54 text-align:right;
55 }
56 </style>
57 <script language="JavaScript">
58 var TestCases = new Array();
59 var cur;
60 <xsl:for-each select="./testsuite">
61 <xsl:apply-templates select="properties"/>
62 </xsl:for-each>
63
64 </script>
65 <script language="JavaScript"><![CDATA[
66 function displayProperties (name) {
67 var win = window.open('','JUnitSystemProperties','scrollbars=1,resizable=1');
68 var doc = win.document.open();
69 doc.write("<html><head><title>Properties of " + name + "</title>");
70 doc.write("<style>")
71 doc.write("body {font:normal 68% verdana,arial,helvetica; color:#000000; }");
72 doc.write("table tr td, table tr th { font-size: 68%; }");
73 doc.write("table.properties { border-collapse:collapse; border-left:solid 1 #cccccc; border-top:solid 1 #cccccc; padding:5px; }");
74 doc.write("table.properties th { text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#eeeeee; }");
75 doc.write("table.properties td { font:normal; text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#fffffff; }");
76 doc.write("h3 { margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica }");
77 doc.write("</style>");
78 doc.write("</head><body>");
79 doc.write("<h3>Properties of " + name + "</h3>");
80 doc.write("<div align=\"right\"><a href=\"javascript:window.close();\">Close</a></div>");
81 doc.write("<table class='properties'>");
82 doc.write("<tr><th>Name</th><th>Value</th></tr>");
83 for (prop in TestCases[name]) {
84 doc.write("<tr><th>" + prop + "</th><td>" + TestCases[name][prop] + "</td></tr>");
85 }
86 doc.write("</table>");
87 doc.write("</body></html>");
88 doc.close();
89 win.focus();
90 }
91 ]]>
92 </script>
93 </HEAD>
94 <body>
95 <a name="top"></a>
96 <xsl:call-template name="pageHeader"/>
97
98 <!-- Summary part -->
99 <xsl:call-template name="summary"/>
100 <hr size="1" width="95%" align="left"/>
101
102 <!-- Package List part -->
103 <xsl:call-template name="packagelist"/>
104 <hr size="1" width="95%" align="left"/>
105
106 <!-- For each package create its part -->
107 <xsl:call-template name="packages"/>
108 <hr size="1" width="95%" align="left"/>
109
110 <!-- For each class create the part -->
111 <xsl:call-template name="classes"/>
112
113 </body>
114 </HTML>
115</xsl:template>
116
117
118
119 <!-- ================================================================== -->
120 <!-- Write a list of all packages with an hyperlink to the anchor of -->
121 <!-- of the package name. -->
122 <!-- ================================================================== -->
123 <xsl:template name="packagelist">
124 <h2>Packages</h2>
125 Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
126 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
127 <xsl:call-template name="testsuite.test.header"/>
128 <!-- list all packages recursively -->
129 <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
130 <xsl:sort select="@package"/>
131 <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/>
132 <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/>
133 <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/>
134 <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/>
135 <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/>
136
137 <!-- write a summary for the package -->
138 <tr valign="top">
139 <!-- set a nice color depending if there is an error/failure -->
140 <xsl:attribute name="class">
141 <xsl:choose>
142 <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
143 <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
144 </xsl:choose>
145 </xsl:attribute>
146 <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td>
147 <td><xsl:value-of select="$testCount"/></td>
148 <td><xsl:value-of select="$errorCount"/></td>
149 <td><xsl:value-of select="$failureCount"/></td>
150 <td>
151 <xsl:call-template name="display-time">
152 <xsl:with-param name="value" select="$timeCount"/>
153 </xsl:call-template>
154 </td>
155 </tr>
156 </xsl:for-each>
157 </table>
158 </xsl:template>
159
160
161 <!-- ================================================================== -->
162 <!-- Write a package level report -->
163 <!-- It creates a table with values from the document: -->
164 <!-- Name | Tests | Errors | Failures | Time -->
165 <!-- ================================================================== -->
166 <xsl:template name="packages">
167 <!-- create an anchor to this package name -->
168 <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
169 <xsl:sort select="@package"/>
170 <a name="{@package}"></a>
171 <h3>Package <xsl:value-of select="@package"/></h3>
172
173 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
174 <xsl:call-template name="testsuite.test.header"/>
175
176 <!-- match the testsuites of this package -->
177 <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/>
178 </table>
179 <a href="#top">Back to top</a>
180 <p/>
181 <p/>
182 </xsl:for-each>
183 </xsl:template>
184
185 <xsl:template name="classes">
186 <xsl:for-each select="testsuite">
187 <xsl:sort select="@name"/>
188 <!-- create an anchor to this class name -->
189 <a name="{@name}"></a>
190 <h3>TestCase <xsl:value-of select="@name"/></h3>
191
192 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
193 <xsl:call-template name="testcase.test.header"/>
194 <!--
195 test can even not be started at all (failure to load the class)
196 so report the error directly
197 -->
198 <xsl:if test="./error">
199 <tr class="Error">
200 <td colspan="4"><xsl:apply-templates select="./error"/></td>
201 </tr>
202 </xsl:if>
203 <xsl:apply-templates select="./testcase" mode="print.test"/>
204 </table>
205 <div class="Properties">
206 <a>
207 <xsl:attribute name="href">javascript:displayProperties('<xsl:value-of select="@package"/>.<xsl:value-of select="@name"/>');</xsl:attribute>
208 Properties &gt;&gt;
209 </a>
210 </div>
211 <p/>
212
213 <a href="#top">Back to top</a>
214 </xsl:for-each>
215 </xsl:template>
216
217 <xsl:template name="summary">
218 <h2>Summary</h2>
219 <xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
220 <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
221 <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
222 <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
223 <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
224 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
225 <tr valign="top">
226 <th>Tests</th>
227 <th>Failures</th>
228 <th>Errors</th>
229 <th>Success rate</th>
230 <th>Time</th>
231 </tr>
232 <tr valign="top">
233 <xsl:attribute name="class">
234 <xsl:choose>
235 <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
236 <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
237 </xsl:choose>
238 </xsl:attribute>
239 <td><xsl:value-of select="$testCount"/></td>
240 <td><xsl:value-of select="$failureCount"/></td>
241 <td><xsl:value-of select="$errorCount"/></td>
242 <td>
243 <xsl:call-template name="display-percent">
244 <xsl:with-param name="value" select="$successRate"/>
245 </xsl:call-template>
246 </td>
247 <td>
248 <xsl:call-template name="display-time">
249 <xsl:with-param name="value" select="$timeCount"/>
250 </xsl:call-template>
251 </td>
252
253 </tr>
254 </table>
255 <table border="0" width="95%">
256 <tr>
257 <td style="text-align: justify;">
258 Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.
259 </td>
260 </tr>
261 </table>
262 </xsl:template>
263
264 <!--
265 Write properties into a JavaScript data structure.
266 This is based on the original idea by Erik Hatcher (erik@hatcher.net)
267 -->
268 <xsl:template match="properties">
269 cur = TestCases['<xsl:value-of select="../@package"/>.<xsl:value-of select="../@name"/>'] = new Array();
270 <xsl:for-each select="property">
271 <xsl:sort select="@name"/>
272 cur['<xsl:value-of select="@name"/>'] = '<xsl:call-template name="JS-escape"><xsl:with-param name="string" select="@value"/></xsl:call-template>';
273 </xsl:for-each>
274 </xsl:template>
275
276<!-- Page HEADER -->
277<xsl:template name="pageHeader">
278 <h1>Unit Test Results</h1>
279 <table width="100%">
280 <tr>
281 <td align="left"></td>
282 <td align="right">Designed for use with <a href='http://www.junit.org'>JUnit</a> and <a href='http://jakarta.apache.org/ant'>Ant</a>.</td>
283 </tr>
284 </table>
285 <hr size="1"/>
286</xsl:template>
287
288<xsl:template match="testsuite" mode="header">
289 <tr valign="top">
290 <th width="80%">Name</th>
291 <th>Tests</th>
292 <th>Errors</th>
293 <th>Failures</th>
294 <th nowrap="nowrap">Time(s)</th>
295 </tr>
296</xsl:template>
297
298<!-- class header -->
299<xsl:template name="testsuite.test.header">
300 <tr valign="top">
301 <th width="80%">Name</th>
302 <th>Tests</th>
303 <th>Errors</th>
304 <th>Failures</th>
305 <th nowrap="nowrap">Time(s)</th>
306 </tr>
307</xsl:template>
308
309<!-- method header -->
310<xsl:template name="testcase.test.header">
311 <tr valign="top">
312 <th>Name</th>
313 <th>Status</th>
314 <th width="80%">Type</th>
315 <th nowrap="nowrap">Time(s)</th>
316 </tr>
317</xsl:template>
318
319
320<!-- class information -->
321<xsl:template match="testsuite" mode="print.test">
322 <tr valign="top">
323 <!-- set a nice color depending if there is an error/failure -->
324 <xsl:attribute name="class">
325 <xsl:choose>
326 <xsl:when test="@failures[.&gt; 0]">Failure</xsl:when>
327 <xsl:when test="@errors[.&gt; 0]">Error</xsl:when>
328 </xsl:choose>
329 </xsl:attribute>
330
331 <!-- print testsuite information -->
332 <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td>
333 <td><xsl:value-of select="@tests"/></td>
334 <td><xsl:value-of select="@errors"/></td>
335 <td><xsl:value-of select="@failures"/></td>
336 <td>
337 <xsl:call-template name="display-time">
338 <xsl:with-param name="value" select="@time"/>
339 </xsl:call-template>
340 </td>
341 </tr>
342</xsl:template>
343
344<xsl:template match="testcase" mode="print.test">
345 <tr valign="top">
346 <xsl:attribute name="class">
347 <xsl:choose>
348 <xsl:when test="failure | error">Error</xsl:when>
349 </xsl:choose>
350 </xsl:attribute>
351 <td><xsl:value-of select="@name"/></td>
352 <xsl:choose>
353 <xsl:when test="failure">
354 <td>Failure</td>
355 <td><xsl:apply-templates select="failure"/></td>
356 </xsl:when>
357 <xsl:when test="error">
358 <td>Error</td>
359 <td><xsl:apply-templates select="error"/></td>
360 </xsl:when>
361 <xsl:otherwise>
362 <td>Success</td>
363 <td></td>
364 </xsl:otherwise>
365 </xsl:choose>
366 <td>
367 <xsl:call-template name="display-time">
368 <xsl:with-param name="value" select="@time"/>
369 </xsl:call-template>
370 </td>
371 </tr>
372</xsl:template>
373
374
375<xsl:template match="failure">
376 <xsl:call-template name="display-failures"/>
377</xsl:template>
378
379<xsl:template match="error">
380 <xsl:call-template name="display-failures"/>
381</xsl:template>
382
383<!-- Style for the error and failure in the tescase template -->
384<xsl:template name="display-failures">
385 <xsl:choose>
386 <xsl:when test="not(@message)">N/A</xsl:when>
387 <xsl:otherwise>
388 <xsl:value-of select="@message"/>
389 </xsl:otherwise>
390 </xsl:choose>
391 <!-- display the stacktrace -->
392 <code>
393 <p/>
394 <xsl:call-template name="br-replace">
395 <xsl:with-param name="word" select="."/>
396 </xsl:call-template>
397 </code>
398 <!-- the later is better but might be problematic for non-21" monitors... -->
399 <!--pre><xsl:value-of select="."/></pre-->
400</xsl:template>
401
402<xsl:template name="JS-escape">
403 <xsl:param name="string"/>
404 <xsl:choose><!-- something isn't right here, basically all single quotes need to be replaced with backslash-single-quote
405 <xsl:when test="contains($string,'&apos;')">
406 <xsl:value-of select="substring-before($string,'&apos;')"/>
407 \&apos;
408 <xsl:call-template name="JS-escape">
409 <xsl:with-param name="string" select="substring-after($string,'&apos;')"/>
410 </xsl:call-template>
411 </xsl:when> -->
412 <xsl:when test="contains($string,'\')">
413 <xsl:value-of select="substring-before($string,'\')"/>\\<xsl:call-template name="JS-escape">
414 <xsl:with-param name="string" select="substring-after($string,'\')"/>
415 </xsl:call-template>
416 </xsl:when>
417 <xsl:otherwise>
418 <xsl:value-of select="$string"/>
419 </xsl:otherwise>
420 </xsl:choose>
421</xsl:template>
422
423
424<!--
425 template that will convert a carriage return into a br tag
426 @param word the text from which to convert CR to BR tag
427-->
428<xsl:template name="br-replace">
429 <xsl:param name="word"/>
430 <xsl:choose>
431 <xsl:when test="contains($word,'&#xA;')">
432 <xsl:value-of select="substring-before($word,'&#xA;')"/>
433 <br/>
434 <xsl:call-template name="br-replace">
435 <xsl:with-param name="word" select="substring-after($word,'&#xA;')"/>
436 </xsl:call-template>
437 </xsl:when>
438 <xsl:otherwise>
439 <xsl:value-of select="$word"/>
440 </xsl:otherwise>
441 </xsl:choose>
442</xsl:template>
443
444<xsl:template name="display-time">
445 <xsl:param name="value"/>
446 <xsl:value-of select="format-number($value,'0.000')"/>
447</xsl:template>
448
449<xsl:template name="display-percent">
450 <xsl:param name="value"/>
451 <xsl:value-of select="format-number($value,'0.00%')"/>
452</xsl:template>
453
454</xsl:stylesheet>
455