1<?xml version="1.0"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
3        xmlns="http://www.w3.org/1999/xhtml"
4        xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"
5        exclude-result-prefixes="stringutils">
6<xsl:output method="xml" indent="yes" encoding="UTF-8"
7  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
8  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
9<xsl:decimal-format decimal-separator="." grouping-separator="," />
10<!--
11   Licensed to the Apache Software Foundation (ASF) under one or more
12   contributor license agreements.  See the NOTICE file distributed with
13   this work for additional information regarding copyright ownership.
14   The ASF licenses this file to You under the Apache License, Version 2.0
15   (the "License"); you may not use this file except in compliance with
16   the License.  You may obtain a copy of the License at
17
18       http://www.apache.org/licenses/LICENSE-2.0
19
20   Unless required by applicable law or agreed to in writing, software
21   distributed under the License is distributed on an "AS IS" BASIS,
22   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   See the License for the specific language governing permissions and
24   limitations under the License.
25 -->
26
27<xsl:param name="qualified.bundle.version"/>
28<xsl:param name="jacoco.home.url"/>
29<xsl:param name="copyright.years"/>
30
31<!--
32
33 JaCoCo test report stylesheet.
34
35-->
36<xsl:template match="testsuites">
37    <html>
38        <head>
39            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
40            <link rel="stylesheet" href="../doc/.resources/doc.css" charset="UTF-8" type="text/css" />
41            <link rel="shortcut icon" href="../doc/.resources/report.gif" type="image/gif" />
42            <title>JaCoCo - JUnit Test Results</title>
43
44    <style type="text/css">
45      .Error {
46        font-weight:bold; color:red;
47      }
48      .Failure {
49        font-weight:bold; color:purple;
50      }
51      </style>
52        </head>
53        <body>
54            <div id="content">
55            <a name="top"></a>
56            <xsl:call-template name="pageHeader"/>
57
58            <!-- Summary part -->
59            <xsl:call-template name="summary"/>
60
61            <!-- Package List part -->
62            <xsl:call-template name="packagelist"/>
63
64            <!-- For each package create its part -->
65            <xsl:call-template name="packages"/>
66
67            <!-- For each class create the  part -->
68            <xsl:call-template name="classes"/>
69
70            </div>
71			<div class="footer">
72				<span class="right"><a href="{$jacoco.home.url}">JaCoCo</a>&#160;<xsl:value-of select="$qualified.bundle.version"/></span>
73				<a href="../doc/license.html">Copyright</a> &#169; <xsl:value-of select="$copyright.years"/> Mountainminds GmbH &amp; Co. KG and Contributors
74			</div>
75        </body>
76    </html>
77</xsl:template>
78
79
80
81<!-- ================================================================== -->
82<!-- Write a list of all packages with an hyperlink to the anchor of    -->
83<!-- of the package name.                                               -->
84<!-- ================================================================== -->
85<xsl:template name="packagelist">
86	<h2>Packages</h2>
87	<table class="coverage">
88		<xsl:call-template name="testsuite.test.header"/>
89		<tbody>
90			<!-- list all packages recursively -->
91            <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
92                <xsl:sort select="@package"/>
93                <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/>
94                <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/>
95                <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/>
96                <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/>
97                <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/>
98
99                <!-- write a summary for the package -->
100                <tr valign="top">
101                    <!-- set a nice color depending if there is an error/failure -->
102                    <xsl:attribute name="class">
103                        <xsl:choose>
104                            <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
105                            <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
106                        </xsl:choose>
107                    </xsl:attribute>
108                    <td style="width:24em"><a href="#{@package}" class="el_testsuite"><xsl:value-of select="@package"/></a></td>
109                    <td><xsl:value-of select="$testCount"/></td>
110                    <td><xsl:value-of select="$errorCount"/></td>
111                    <td><xsl:value-of select="$failureCount"/></td>
112                    <td>
113                    <xsl:call-template name="display-time">
114                        <xsl:with-param name="value" select="$timeCount"/>
115                    </xsl:call-template>
116                    </td>
117                    <td><xsl:value-of select="$testsuites-in-package/@timestamp"/></td>
118                </tr>
119            </xsl:for-each>
120		</tbody>
121	</table>
122	<p class="hint">
123        Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
124    </p>
125</xsl:template>
126
127
128    <!-- ================================================================== -->
129    <!-- Write a package level report                                       -->
130    <!-- It creates a table with values from the document:                  -->
131    <!-- Name | Tests | Errors | Failures | Time                            -->
132    <!-- ================================================================== -->
133    <xsl:template name="packages">
134        <!-- create an anchor to this package name -->
135        <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
136            <xsl:sort select="@package"/>
137                <a name="{@package}"></a>
138                <h3>Package <xsl:value-of select="@package"/></h3>
139
140                <table class="coverage">
141                    <xsl:call-template name="testsuite.test.header"/>
142
143                    <!-- match the testsuites of this package -->
144                    <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/>
145                </table>
146                <p>
147                	<a href="#top">Back to top</a>
148                </p>
149        </xsl:for-each>
150    </xsl:template>
151
152    <xsl:template name="classes">
153        <xsl:for-each select="testsuite">
154            <xsl:sort select="@name"/>
155            <!-- create an anchor to this class name -->
156            <a name="{@name}"></a>
157            <h3>TestCase <xsl:value-of select="@name"/></h3>
158
159            <table class="coverage">
160              <xsl:call-template name="testcase.test.header"/>
161              <!--
162              test can even not be started at all (failure to load the class)
163              so report the error directly
164              -->
165                <xsl:if test="./error">
166                    <tr class="Error">
167                        <td colspan="4"><xsl:apply-templates select="./error"/></td>
168                    </tr>
169                </xsl:if>
170                <xsl:apply-templates select="./testcase" mode="print.test"/>
171            </table>
172            <p>
173            	<a href="#top">Back to top</a>
174            </p>
175        </xsl:for-each>
176    </xsl:template>
177
178<xsl:template name="summary">
179	<h2>Summary</h2>
180	<xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
181	<xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
182	<xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
183	<xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
184	<xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
185	<table class="coverage">
186        <thead>
187	        <tr valign="top">
188    	        <td>Tests</td>
189        	    <td>Failures</td>
190            	<td>Errors</td>
191            	<td>Success rate</td>
192            	<td>Time</td>
193        	</tr>
194        </thead>
195        <tbody>
196			<tr valign="top">
197				<xsl:attribute name="class">
198					<xsl:choose>
199						<xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
200						<xsl:when test="$errorCount &gt; 0">Error</xsl:when>
201					</xsl:choose>
202				</xsl:attribute>
203				<td><xsl:value-of select="$testCount"/></td>
204				<td><xsl:value-of select="$failureCount"/></td>
205				<td><xsl:value-of select="$errorCount"/></td>
206				<td>
207					<xsl:call-template name="display-percent">
208						<xsl:with-param name="value" select="$successRate"/>
209					</xsl:call-template>
210				</td>
211				<td>
212					<xsl:call-template name="display-time">
213						<xsl:with-param name="value" select="$timeCount"/>
214					</xsl:call-template>
215				</td>
216			</tr>
217		</tbody>
218	</table>
219	<p class="hint">
220        Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.
221    </p>
222</xsl:template>
223
224<!-- Page HEADER -->
225<xsl:template name="pageHeader">
226	<div class="breadcrumb">
227		<a href="../index.html" class="el_report">JaCoCo</a> &gt;
228		<span class="el_testsuite">JUnit Test Results</span>
229	</div>
230    <h1>JUnit Test Results</h1>
231</xsl:template>
232
233<xsl:template match="testsuite" mode="header">
234	<thead>
235    	<tr valign="top">
236        	<td>Name</td>
237        	<td>Tests</td>
238        	<td>Errors</td>
239        	<td>Failures</td>
240        	<td nowrap="nowrap">Time(s)</td>
241    	</tr>
242    </thead>
243</xsl:template>
244
245<!-- class header -->
246<xsl:template name="testsuite.test.header">
247	<thead>
248    	<tr>
249        	<td>Name</td>
250        	<td>Tests</td>
251        	<td>Errors</td>
252        	<td>Failures</td>
253        	<td>Time(s)</td>
254        	<td>Time Stamp</td>
255    	</tr>
256    </thead>
257</xsl:template>
258
259<!-- method header -->
260<xsl:template name="testcase.test.header">
261	<thead>
262    	<tr>
263        	<td>Name</td>
264        	<td>Status</td>
265        	<td>Type</td>
266        	<td>Time(s)</td>
267	    </tr>
268    </thead>
269</xsl:template>
270
271
272<!-- class information -->
273<xsl:template match="testsuite" mode="print.test">
274    <tr valign="top">
275        <!-- set a nice color depending if there is an error/failure -->
276        <xsl:attribute name="class">
277            <xsl:choose>
278                <xsl:when test="@failures[.&gt; 0]">Failure</xsl:when>
279                <xsl:when test="@errors[.&gt; 0]">Error</xsl:when>
280            </xsl:choose>
281        </xsl:attribute>
282
283        <!-- print testsuite information -->
284        <td style="width:24em"><a href="#{@name}" class="el_testsuite"><xsl:value-of select="@name"/></a></td>
285        <td><xsl:value-of select="@tests"/></td>
286        <td><xsl:value-of select="@errors"/></td>
287        <td><xsl:value-of select="@failures"/></td>
288        <td>
289            <xsl:call-template name="display-time">
290                <xsl:with-param name="value" select="@time"/>
291            </xsl:call-template>
292        </td>
293        <td><xsl:apply-templates select="@timestamp"/></td>
294    </tr>
295</xsl:template>
296
297<xsl:template match="testcase" mode="print.test">
298    <tr valign="top">
299        <xsl:attribute name="class">
300            <xsl:choose>
301                <xsl:when test="failure | error">Error</xsl:when>
302            </xsl:choose>
303        </xsl:attribute>
304        <td style="width:24em"><span class="el_test"><xsl:value-of select="@name"/></span></td>
305        <xsl:choose>
306            <xsl:when test="failure">
307                <td>Failure</td>
308                <td><xsl:apply-templates select="failure"/></td>
309            </xsl:when>
310            <xsl:when test="error">
311                <td>Error</td>
312                <td><xsl:apply-templates select="error"/></td>
313            </xsl:when>
314            <xsl:otherwise>
315                <td>Success</td>
316                <td></td>
317            </xsl:otherwise>
318        </xsl:choose>
319        <td>
320            <xsl:call-template name="display-time">
321                <xsl:with-param name="value" select="@time"/>
322            </xsl:call-template>
323        </td>
324    </tr>
325</xsl:template>
326
327
328<xsl:template match="failure">
329    <xsl:call-template name="display-failures"/>
330</xsl:template>
331
332<xsl:template match="error">
333    <xsl:call-template name="display-failures"/>
334</xsl:template>
335
336<!-- Style for the error and failure in the tescase template -->
337<xsl:template name="display-failures">
338    <xsl:choose>
339        <xsl:when test="not(@message)">N/A</xsl:when>
340        <xsl:otherwise>
341            <xsl:value-of select="@message"/>
342        </xsl:otherwise>
343    </xsl:choose>
344    <!-- display the stacktrace -->
345    <code>
346        <br/><br/>
347        <xsl:call-template name="br-replace">
348            <xsl:with-param name="word" select="."/>
349        </xsl:call-template>
350    </code>
351    <!-- the later is better but might be problematic for non-21" monitors... -->
352    <!--pre><xsl:value-of select="."/></pre-->
353</xsl:template>
354
355<xsl:template name="JS-escape">
356    <xsl:param name="string"/>
357    <xsl:param name="tmp1" select="stringutils:replace(string($string),'\','\\')"/>
358    <xsl:param name="tmp2" select="stringutils:replace(string($tmp1),&quot;'&quot;,&quot;\&apos;&quot;)"/>
359    <xsl:value-of select="$tmp2"/>
360</xsl:template>
361
362
363<!--
364    template that will convert a carriage return into a br tag
365    @param word the text from which to convert CR to BR tag
366-->
367<xsl:template name="br-replace">
368    <xsl:param name="word"/>
369    <xsl:value-of disable-output-escaping="yes" select='stringutils:replace(string($word),"&#xA;","&lt;br/>")'/>
370</xsl:template>
371
372<xsl:template name="display-time">
373    <xsl:param name="value"/>
374    <xsl:value-of select="format-number($value,'0.000')"/>
375</xsl:template>
376
377<xsl:template name="display-percent">
378    <xsl:param name="value"/>
379    <xsl:value-of select="format-number($value,'0.00%')"/>
380</xsl:template>
381
382</xsl:stylesheet>
383