fpcunit.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <!-- Change the encoding here if you need it, i.e. UTF-8 -->
  4. <xsl:output method="html" encoding="UTF-8" indent="yes"
  5. doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"
  6. />
  7. <!-- ************************************ Parameters ************************************ -->
  8. <!-- expand-treeview, boolean - true if you want to expand the tree-view at the first print -->
  9. <xsl:param name="param-expand-treeview" select="'false'"/>
  10. <!-- preferred browser Netscape/Mozilla or Internet Explorer. Thanks to Bill, 90% of the sheeps use IE, but I don't so NS is the default here -->
  11. <xsl:param name="param-is-netscape" select="'true'"/>
  12. <!-- horizontal distance in pixels between a folder and its leaves -->
  13. <xsl:param name="param-shift-width" select="15"/>
  14. <!-- image source directory-->
  15. <xsl:param name="param-img-directory" select="'images/'"/>
  16. <!-- scripts and stylesheet source directory-->
  17. <xsl:param name="param-scripts-directory" select="'scripts/'"/>
  18. <!-- expand-errors-and-failures, boolean - true if you want to expand the testcase nodes (errors & failures) at the first print -->
  19. <xsl:param name="param-expand-errors-and-failures" select="'false'"/>
  20. <!-- if expand-treeview is false we can auto expand first few nodes. if 0 then expand until error or failure testcases. -->
  21. <xsl:param name="param-expand-depth" select="3"/>
  22. <!-- ************************************ Variables ************************************ -->
  23. <xsl:variable name="var-simple-quote">'</xsl:variable>
  24. <xsl:variable name="var-slash-quote">\'</xsl:variable>
  25. <xsl:template match="/">
  26. <html>
  27. <head>
  28. <title>FPCUnit Results</title>
  29. <link href="{$param-scripts-directory}fpcunit.css" rel="stylesheet" type="text/css"/>
  30. <script src="{$param-scripts-directory}treeview.js" language="javascript" type="text/javascript"/>
  31. </head>
  32. <body>
  33. <a name="Summary"/>
  34. <h2>FPCUnit Results</h2>
  35. <xsl:apply-templates/>
  36. <address>
  37. <a href="http://opensoft.homeip.net">FPCUnit Report</a> 0.4.0 [beta3] &#169; 2006-2008 by
  38. <a href="mailto:[email protected]?subject=Comments about FPCUnit Report">Graeme Geldenhuys</a>.<br/>
  39. Licensed under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License</a>.<br/>
  40. </address>
  41. <p align="right">
  42. <a href="http://validator.w3.org/check?uri=referer"><img
  43. src="http://www.w3.org/Icons/valid-html40" border="0"
  44. alt="Valid HTML 4.0 Transitional" height="31" width="88"/></a>
  45. </p>
  46. </body>
  47. </html>
  48. </xsl:template>
  49. <xsl:template name="summary" match="TestResults">
  50. <xsl:variable name="runCount" select="NumberOfRunTests"/>
  51. <xsl:variable name="failureCount" select="NumberOfFailures"/>
  52. <xsl:variable name="errorCount" select="NumberOfErrors"/>
  53. <xsl:variable name="elapsedTime" select="TotalElapsedTime"/>
  54. <xsl:variable name="dateRan" select="DateTimeRan"/>
  55. <h3>Summary</h3>
  56. <!-- Summary Table -->
  57. <table border="0" rules="none" width="100%">
  58. <tr align="left" class="title">
  59. <th width="45%" align="left">Name</th>
  60. <th width="7%" align="left">Tests</th>
  61. <th width="8%" align="left">Failures</th>
  62. <th width="8%" align="left">Errors</th>
  63. <th width="11%" align="left">Elapsed Time</th>
  64. <th width="14%" align="left">Run Date</th>
  65. </tr>
  66. <tr class="success">
  67. <!-- Set class attribute based on test results -->
  68. <xsl:if test="$failureCount &gt; 0">
  69. <xsl:attribute name="class">failure</xsl:attribute>
  70. </xsl:if>
  71. <xsl:if test="$errorCount &gt; 0">
  72. <xsl:attribute name="class">error</xsl:attribute>
  73. </xsl:if>
  74. <td>Summary</td>
  75. <td><xsl:value-of select="$runCount"/></td>
  76. <td><xsl:value-of select="$failureCount"/></td>
  77. <td><xsl:value-of select="$errorCount"/></td>
  78. <td><xsl:value-of select="$elapsedTime"/></td>
  79. <td><xsl:value-of select="$dateRan"/></td>
  80. </tr>
  81. </table>
  82. <p>Note: <i>Failures</i> are anticipated and checked for with assertions. <i>Errors</i> are
  83. unexpected results.</p>
  84. <hr/>
  85. <xsl:call-template name="test_listing"></xsl:call-template>
  86. </xsl:template>
  87. <!--
  88. **********************************************************************
  89. Represents the test suites as a treeview
  90. **********************************************************************
  91. -->
  92. <xsl:template name="test_listing">
  93. <div id="testlisting">
  94. <a name="Test_Listing"/>
  95. <h3>Test Listing</h3>
  96. <!-- Treeview Start -->
  97. <table border="0" cellspacing="0" cellpadding="0">
  98. <tr>
  99. <td>
  100. <!-- Apply the template TestSuite starting with a depth in the tree of 1-->
  101. <xsl:call-template name="test_suite">
  102. <xsl:with-param name="depth" select="1"/>
  103. </xsl:call-template>
  104. </td>
  105. </tr>
  106. </table>
  107. <!-- Treeview End -->
  108. </div> <!-- testlisting -->
  109. </xsl:template>
  110. <!--
  111. **********************************************************************
  112. Creates a image and text representing a test suite.
  113. **********************************************************************
  114. -->
  115. <xsl:template name="test_suite" match="TestSuite">
  116. <xsl:param name="depth"/>
  117. <table border="0" cellspacing="0" cellpadding="0">
  118. <tr>
  119. <!-- If first level of depth, do not shift of $param-shift-width-->
  120. <xsl:if test="$depth>1">
  121. <!-- highlight the test results -->
  122. <xsl:choose>
  123. <xsl:when test="@NumberOfErrors &gt; 0">
  124. <td width="{$param-shift-width}" class="error_">&#160;</td>
  125. </xsl:when>
  126. <xsl:when test="@NumberOfFailures &gt; 0">
  127. <td width="{$param-shift-width}" class="failure_">&#160;</td>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <td width="{$param-shift-width}">&#160;</td>
  131. </xsl:otherwise>
  132. </xsl:choose>
  133. </xsl:if>
  134. <td>
  135. <a class="folder">
  136. <xsl:attribute name="onclick">toggle(this)</xsl:attribute>
  137. <!-- If the treeview is unfold, the image minus (-) is displayed-->
  138. <xsl:if test="@expanded">
  139. <xsl:if test="@expanded='true'">
  140. <img src="{$param-img-directory}minus.gif" alt=""/>
  141. </xsl:if>
  142. <xsl:if test="@expanded='false'">
  143. <img src="{$param-img-directory}plus.gif" alt=""/>
  144. </xsl:if>
  145. </xsl:if>
  146. <xsl:if test="not(@expanded)">
  147. <xsl:if test="$param-expand-treeview = 'true'">
  148. <img src="{$param-img-directory}minus.gif" alt=""/>
  149. </xsl:if>
  150. <xsl:if test="$param-expand-treeview = 'false' or not(@expanded)">
  151. <img src="{$param-img-directory}plus.gif" alt=""/>
  152. </xsl:if>
  153. </xsl:if>
  154. <img src="{$param-img-directory}testsuite.gif" alt="">
  155. <!-- if the attribut Name is present-->
  156. <xsl:if test="@Name">
  157. <!-- if Netscape / Mozilla -->
  158. <xsl:if test="$param-is-netscape='true'">
  159. <xsl:attribute name="title"><xsl:value-of select="@Name"/></xsl:attribute>
  160. </xsl:if>
  161. <!-- if Internet Explorer -->
  162. <xsl:if test="$param-is-netscape='false'">
  163. <xsl:attribute name="alt"><xsl:value-of select="@Name"/></xsl:attribute>
  164. </xsl:if>
  165. </xsl:if>
  166. </img>
  167. <!-- Tree node text can be decorated based on the test results -->
  168. <xsl:choose>
  169. <xsl:when test="@NumberOfErrors &gt; 0">
  170. <span class="node_error"><xsl:value-of select="@Name"/></span>
  171. </xsl:when>
  172. <xsl:when test="@NumberOfFailures &gt; 0">
  173. <span class="node_failure"><xsl:value-of select="@Name"/></span>
  174. </xsl:when>
  175. <xsl:otherwise>
  176. <span class="node_success"><xsl:value-of select="@Name"/></span>
  177. </xsl:otherwise>
  178. </xsl:choose>
  179. </a>
  180. <!-- Shall we expand all the leaves of the treeview? No by default -->
  181. <div>
  182. <xsl:if test="@expanded">
  183. <xsl:if test="@expanded='true'">
  184. <xsl:attribute name="style">display:block;</xsl:attribute>
  185. </xsl:if>
  186. <!-- plus (+) otherwise-->
  187. <xsl:if test="@expanded='false'">
  188. <xsl:attribute name="style">display:none;</xsl:attribute>
  189. </xsl:if>
  190. </xsl:if>
  191. <xsl:if test="not(@expanded)">
  192. <xsl:if test="$param-expand-treeview = 'true'">
  193. <xsl:attribute name="style">display:block;</xsl:attribute>
  194. </xsl:if>
  195. <xsl:if test="$param-expand-treeview = 'false'">
  196. <xsl:attribute name="style">display:none;</xsl:attribute>
  197. </xsl:if>
  198. <!-- Auto expand any nodes containing failures or errors -->
  199. <xsl:if test="($param-expand-treeview = 'false') and ($param-expand-depth = 0)">
  200. <xsl:if test="@NumberOfErrors &gt; 0">
  201. <xsl:attribute name="style">display:block;</xsl:attribute>
  202. </xsl:if>
  203. <xsl:if test="@NumberOfFailures &gt; 0">
  204. <xsl:attribute name="style">display:block;</xsl:attribute>
  205. </xsl:if>
  206. </xsl:if>
  207. <!-- Auto expand the first few nodes as defined by param-expand-depth -->
  208. <xsl:if test="($param-expand-treeview = 'false') and ($param-expand-depth &gt; 0)">
  209. <xsl:if test="($depth &lt; $param-expand-depth)">
  210. <xsl:attribute name="style">display:block;</xsl:attribute>
  211. </xsl:if>
  212. </xsl:if>
  213. </xsl:if>
  214. <!-- Thanks to the magic of recursive calls, all the descendants of
  215. the current folder are going to be built -->
  216. <xsl:apply-templates name="test_suite">
  217. <xsl:with-param name="depth" select="$depth+1"/>
  218. </xsl:apply-templates>
  219. <!-- print all the leaves of this folder-->
  220. <xsl:apply-templates select="/Test"></xsl:apply-templates>
  221. </div>
  222. </td>
  223. </tr>
  224. </table>
  225. </xsl:template>
  226. <!--
  227. **********************************************************************
  228. Represents the actual test.
  229. **********************************************************************
  230. -->
  231. <xsl:template match="Test">
  232. <table border="0" cellspacing="1" cellpadding="0">
  233. <tr>
  234. <!-- highlight the test result -->
  235. <xsl:choose>
  236. <xsl:when test="@Result = 'Error'">
  237. <td width="{$param-shift-width}" class="error_">&#160;</td>
  238. </xsl:when>
  239. <xsl:when test="@Result = 'Failed'">
  240. <td width="{$param-shift-width}" class="failure_">&#160;</td>
  241. </xsl:when>
  242. <xsl:otherwise>
  243. <td width="{$param-shift-width}">&#160;</td>
  244. </xsl:otherwise>
  245. </xsl:choose>
  246. <td class="success">
  247. <!-- Set class attribute based on test result -->
  248. <xsl:if test="@Result = 'Error'">
  249. <xsl:attribute name="class">error</xsl:attribute>
  250. </xsl:if>
  251. <xsl:if test="@Result = 'Failed'">
  252. <xsl:attribute name="class">failure</xsl:attribute>
  253. </xsl:if>
  254. <a class="leaf">
  255. <xsl:attribute name="onclick">toggle(this)</xsl:attribute>
  256. <!-- if it is the last leaf, print a different image for the link to the folder-->
  257. <xsl:choose>
  258. <xsl:when test="($param-expand-errors-and-failures='false') and ((@Result = 'Error') or (@Result = 'Failed'))">
  259. <img src="{$param-img-directory}plus.gif" alt=""/>
  260. </xsl:when>
  261. <xsl:when test="($param-expand-errors-and-failures='true') and ((@Result = 'Error') or (@Result = 'Failed'))">
  262. <img src="{$param-img-directory}minus.gif" alt=""/>
  263. </xsl:when>
  264. <xsl:when test="position()=last()">
  265. <img src="{$param-img-directory}lastlink.gif" alt=""/>
  266. </xsl:when>
  267. <xsl:otherwise>
  268. <img src="{$param-img-directory}link.gif" alt=""/>
  269. </xsl:otherwise>
  270. </xsl:choose>
  271. <img src="{$param-img-directory}testcase.gif" alt="">
  272. <!-- if the attribut alt is present-->
  273. <xsl:if test="@ElapsedTime">
  274. <!-- if Netscape / Mozilla -->
  275. <xsl:if test="$param-is-netscape='true'">
  276. <xsl:attribute name="title"><xsl:value-of select="@ElapsedTime"/></xsl:attribute>
  277. </xsl:if>
  278. <!-- if Internet Explorer -->
  279. <xsl:if test="$param-is-netscape='false'">
  280. <xsl:attribute name="alt"><xsl:value-of select="@ElapsedTime"/></xsl:attribute>
  281. </xsl:if>
  282. </xsl:if>
  283. </img>
  284. <!-- Text background can be highlighted based on the test results -->
  285. <!-- <xsl:choose>
  286. <xsl:when test="@Result = 'Error'">
  287. <span class="node_error"><xsl:value-of select="@Name"/></span>
  288. </xsl:when>
  289. <xsl:when test="@Result = 'Failed'">
  290. <span class="node_failure"><xsl:value-of select="@Name"/></span>
  291. </xsl:when>
  292. <xsl:otherwise>
  293. <span class="node_success"><xsl:value-of select="@Name"/></span>
  294. </xsl:otherwise>
  295. </xsl:choose>
  296. -->
  297. <span class="node_success"><xsl:value-of select="@Name"/></span>
  298. </a>
  299. <!-- Show test result if they exist -->
  300. <xsl:choose>
  301. <xsl:when test="@Result = 'Error'">
  302. <xsl:call-template name="error_results"></xsl:call-template>
  303. </xsl:when>
  304. <xsl:when test="@Result = 'Failed'">
  305. <xsl:call-template name="failed_results"></xsl:call-template>
  306. </xsl:when>
  307. </xsl:choose>
  308. </td>
  309. <td width="150" align="right" class="success">
  310. <!-- Set class attribute based on test result -->
  311. <xsl:if test="@Result = 'Error'">
  312. <xsl:attribute name="class">error</xsl:attribute>
  313. </xsl:if>
  314. <xsl:if test="@Result = 'Failed'">
  315. <xsl:attribute name="class">failure</xsl:attribute>
  316. </xsl:if>
  317. <xsl:value-of select="@ElapsedTime"/>
  318. </td>
  319. </tr>
  320. </table>
  321. </xsl:template>
  322. <xsl:template name="error_results">
  323. <div style="display:none">
  324. <xsl:if test="$param-expand-errors-and-failures='true'">
  325. <xsl:attribute name="style">display:block;</xsl:attribute>
  326. </xsl:if>
  327. <table border="0">
  328. <!-- Error Table Body -->
  329. <TR>
  330. <td width="{$param-shift-width}">&#160;</td>
  331. <TD width="200" valign="top" class="title">Message:</TD>
  332. <TD valign="top" class="resultmessage"><xsl:value-of select="Message"/></TD>
  333. </TR>
  334. <TR>
  335. <td width="{$param-shift-width}">&#160;</td>
  336. <TD valign="top" class="title">Exception Class:</TD>
  337. <TD valign="top" class="resultmessage"><xsl:value-of select="ExceptionClass"/></TD>
  338. </TR>
  339. <TR>
  340. <td width="{$param-shift-width}">&#160;</td>
  341. <TD valign="top" class="title">Exception Message:</TD>
  342. <TD valign="top" class="resultmessage"><xsl:value-of select="ExceptionMessage"/></TD>
  343. </TR>
  344. <TR>
  345. <td width="{$param-shift-width}">&#160;</td>
  346. <TD valign="top" class="title">UnitName:</TD>
  347. <TD valign="top" class="resultmessage"><xsl:value-of select="SourceUnitName"/></TD>
  348. </TR>
  349. <TR>
  350. <td width="{$param-shift-width}">&#160;</td>
  351. <TD valign="top" class="title">LineNumber:</TD>
  352. <TD valign="top" class="resultmessage"><xsl:value-of select="LineNumber"/></TD>
  353. </TR>
  354. <TR>
  355. <td width="{$param-shift-width}">&#160;</td>
  356. <TD valign="top" class="title">Method Name:</TD>
  357. <TD valign="top" class="resultmessage"><xsl:value-of select="FailedMethodName"/></TD>
  358. </TR>
  359. </table>
  360. </div>
  361. </xsl:template>
  362. <xsl:template name="failed_results">
  363. <div style="display:none">
  364. <xsl:if test="$param-expand-errors-and-failures='true'">
  365. <xsl:attribute name="style">display:block;</xsl:attribute>
  366. </xsl:if>
  367. <table border="0">
  368. <!-- Error Table Body -->
  369. <tr>
  370. <td width="{$param-shift-width}">&#160;</td>
  371. <td width="200" valign="top" class="title">Message:</td>
  372. <td valign="top" class="resultmessage"><xsl:value-of select="Message"/></td>
  373. </tr>
  374. <tr>
  375. <td width="{$param-shift-width}">&#160;</td>
  376. <td valign="top" class="title">Exception Class:</td>
  377. <td valign="top" class="resultmessage"><xsl:value-of select="ExceptionClass"/></td>
  378. </tr>
  379. <tr>
  380. <td width="{$param-shift-width}">&#160;</td>
  381. <td valign="top" class="title">Exception Message:</td>
  382. <td valign="top" class="resultmessage"><xsl:value-of select="ExceptionMessage"/></td>
  383. </tr>
  384. </table>
  385. </div>
  386. </xsl:template>
  387. <xsl:template name="replace-string">
  388. <xsl:param name="text"/>
  389. <xsl:param name="from"/>
  390. <xsl:param name="to"/>
  391. <xsl:choose>
  392. <xsl:when test="contains($text, $from)">
  393. <xsl:variable name="before" select="substring-before($text, $from)"/>
  394. <xsl:variable name="after" select="substring-after($text, $from)"/>
  395. <xsl:variable name="prefix" select="concat($before, $to)"/>
  396. <xsl:value-of select="$before"/>
  397. <xsl:value-of select="$to"/>
  398. <xsl:call-template name="replace-string">
  399. <xsl:with-param name="text" select="$after"/>
  400. <xsl:with-param name="from" select="$from"/>
  401. <xsl:with-param name="to" select="$to"/>
  402. </xsl:call-template>
  403. </xsl:when>
  404. <xsl:otherwise>
  405. <xsl:value-of select="$text"/>
  406. </xsl:otherwise>
  407. </xsl:choose>
  408. </xsl:template>
  409. </xsl:stylesheet>