/hg/gfx-test: Updated test reporter, now it can create proper in...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Thu Sep 9 10:26:37 PDT 2010


changeset e3e509624def in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=e3e509624def
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Sep 09 19:26:50 2010 +0200

	Updated test reporter, now it can create proper index.html
	containing statistic for all tests.


diffstat:

3 files changed, 208 insertions(+), 11 deletions(-)
src/org/gfxtest/reporter/Reporter.java   |  170 ++++++++++++++++++++++++++++--
src/org/gfxtest/reporter/TestResult.java |   12 ++
template_test_result.html                |   37 ++++++

diffs (301 lines):

diff -r 44b7fc94cdca -r e3e509624def src/org/gfxtest/reporter/Reporter.java
--- a/src/org/gfxtest/reporter/Reporter.java	Mon Sep 06 18:20:13 2010 +0200
+++ b/src/org/gfxtest/reporter/Reporter.java	Thu Sep 09 19:26:50 2010 +0200
@@ -40,9 +40,10 @@ exception statement from your version.
 
 package org.gfxtest.reporter;
 
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.*;
+import java.util.*;
+import javax.xml.parsers.*;
+import org.w3c.dom.*;
 
 import org.gfxtest.common.ConfigurationException;
 import org.gfxtest.framework.Log;
@@ -52,20 +53,22 @@ import org.gfxtest.framework.Log;
  *
  * @author Pavel Tisnovsky
  */
+ at SuppressWarnings("nls")
 public class Reporter
 {
     private Log log = null;
 
     private ReporterConfiguration configuration = null;
 
-    @SuppressWarnings("nls")
-    private final String[] SPECTESTS = new String[] {"BlankImage"};
+    private static final String INPUT_FILE_NAME = "template_test_result.html";
 
-    @SuppressWarnings("nls")
-    private final String[] ENTITIES = new String[] {"Line", "Polyline", "Polygon", "Rectangle", "Circle", "Ellipse", "Arc"};
+    private static final String OUTPUT_FILE_NAME = "index.html";
 
-    @SuppressWarnings("nls")
-    private final String[] STYLES = new String[] {"Normal", "Filled", "Dashed", "Scaled"};
+    private static final String[] SPECTESTS = new String[] {"BlankImage"};
+
+    private static final String[] ENTITIES = new String[] {"Lines", "Polylines", "Polygons", "Rectangles", "Round Rectangles", "Circles", "Ellipses", "Arcs"};
+
+    private static final String[] STYLES = new String[] {"Normal", "Filled", "Dashed", "AA"};
 
     /**
      * Write report writer duration to the log file.
@@ -80,6 +83,8 @@ public class Reporter
 
     private void doReport(String[] args)
     {
+        BufferedReader input = null;
+        BufferedWriter output = null;
         long t1 = System.currentTimeMillis();
         this.log = new Log(this.getClass().getName(), true);
         this.log.logBegin("report"); //$NON-NLS-1$
@@ -87,16 +92,105 @@ public class Reporter
         {
             this.configuration = new ReporterConfiguration(args, this.log);
             Map<String, TestResult> testResults = readAllTestResults();
+            input = new BufferedReader(new FileReader(new File(INPUT_FILE_NAME)));
+            output = new BufferedWriter(new FileWriter(new File(this.configuration.getOutputPath(), OUTPUT_FILE_NAME)));
+            writeHtmlHeader(input, output);
+            writeHeaderForCommonTests(output);
+            for (String entity : ENTITIES)
+            {
+                writeEntityHeader(output, entity);
+                for (String style : STYLES)
+                {
+                    String testSuiteName = style + entity;
+                    TestResult testResult = testResults.get(testSuiteName);
+                    writeTestResult(output, testResult, testSuiteName);
+                    this.log.logSet(testSuiteName, testResult);
+                }
+                output.write("</tr>\n");
+            }
+            output.write("<tr><td colspan='5'>&nbsp;</td>\n");
+            for (String entity : SPECTESTS)
+            {
+                writeEntityHeader(output, entity);
+                String testSuiteName = entity;
+                TestResult testResult = testResults.get(testSuiteName);
+                writeTestResult(output, testResult, testSuiteName);
+                output.write("<td colspan='3'>&nbsp;</td></tr>\n");
+                this.log.logSet(testSuiteName, testResult);
+            }
+            writeHtmlFooter(input, output);
         }
         catch (ConfigurationException e)
         {
             e.printStackTrace();
         }
+        catch (IOException e)
+        {
+            e.printStackTrace();
+        }
         finally
         {
+            try
+            {
+                if (output != null)
+                {
+                    output.close();
+                }
+            }
+            catch (IOException e)
+            {
+                e.printStackTrace();
+            }
             long t2 = System.currentTimeMillis();
             this.log.logEnd("report"); //$NON-NLS-1$
             printDuration(t1, t2);
+        }
+    }
+
+    private void writeHeaderForCommonTests(BufferedWriter output) throws IOException
+    {
+        output.write("<tr><td class='value'>Entity</td>");
+        for (String style : STYLES)
+        {
+            output.write("<td class='value'>" + style + "</td>");
+        }
+        output.write("</tr>\n");
+    }
+
+    private void writeEntityHeader(BufferedWriter output, String entity) throws IOException
+    {
+        output.write("<tr><td class='key'>" + entity +"</td>");
+    }
+
+    private void writeTestResult(BufferedWriter output, TestResult testResult, String testSuiteName) throws IOException
+    {
+        if (testResult == null)
+        {
+            output.write("<td style='color:red'>&times;</td>");
+        }
+        else
+        {
+            output.write(String.format("<td><a href='%s/results.html'>%s</a></td>", testSuiteName, testResult.toString()));
+        }
+    }
+
+    private void writeHtmlHeader(BufferedReader input, BufferedWriter output) throws IOException
+    {
+        String line;
+        while( (line = input.readLine())!=null && !"${RESULT}".equals(line.trim()))
+        {
+            output.write(line);
+            output.write('\n');
+        }
+    }
+
+    private void writeHtmlFooter(BufferedReader input, BufferedWriter output) throws IOException
+    {
+        String line;
+        while( (line = input.readLine())!=null)
+        {
+            output.write(line);
+            output.write('\n');
         }
     }
 
@@ -111,9 +205,64 @@ public class Reporter
         }
         for (String resultDir : inputDir.list())
         {
-            System.out.println("***" + resultDir);
+            File dir = new File(inputDir, resultDir);
+            if (dir.isDirectory())
+            {
+                this.log.logBegin("processing directory " + resultDir);
+                TestResult result = readTestResult(dir);
+                results.put(resultDir, result);
+                this.log.logEnd("processing directory " + resultDir);
+            }
         }
         return results;
+    }
+
+    @SuppressWarnings({ "boxing" })
+    private TestResult readTestResult(File resultDirectory)
+    {
+        File resultFile = new File(resultDirectory, "results.xml");
+        TestResult testResult = new TestResult();
+        int totalTests = 0;
+        int sameImages = 0;
+        int differentImages = 0;
+        try
+        {
+            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+            Document document = builder.parse(resultFile);
+            NodeList nodes = document.getElementsByTagName("test");
+            for (int i = 0; i < nodes.getLength(); i++)
+            {
+                Element testNode = (Element) nodes.item(i);
+                this.log.logSet(testNode.getNodeName(), ""+i);
+
+                Element patternNode = (Element) testNode.getElementsByTagName("pattern").item(0);
+                String result = patternNode.getAttribute("result");
+                this.log.logSet("result", result);
+                totalTests ++;
+                if ("same".equals(result))
+                {
+                    sameImages++;
+                }
+                else
+                {
+                    differentImages++;
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        finally
+        {
+            testResult.setTotalTests(totalTests);
+            testResult.setSameImages(sameImages);
+            testResult.setDifferentImages(differentImages);
+            this.log.logSet("total tests", totalTests);
+            this.log.logSet("same images", sameImages);
+            this.log.logSet("different images", differentImages);
+        }
+        return testResult;
     }
 
     /**
@@ -124,5 +273,4 @@ public class Reporter
         new Reporter().doReport(args);
     }
 
-
 }
diff -r 44b7fc94cdca -r e3e509624def src/org/gfxtest/reporter/TestResult.java
--- a/src/org/gfxtest/reporter/TestResult.java	Mon Sep 06 18:20:13 2010 +0200
+++ b/src/org/gfxtest/reporter/TestResult.java	Thu Sep 09 19:26:50 2010 +0200
@@ -5,6 +5,11 @@ public class TestResult
     private int totalTests;
     private int sameImages;
     private int differentImages;
+
+    public TestResult()
+    {
+        // empty
+    }
 
     public int getTotalTests()
     {
@@ -35,4 +40,11 @@ public class TestResult
     {
         this.differentImages = differentImages;
     }
+
+    @SuppressWarnings({ "boxing", "nls" })
+    @Override
+    public String toString()
+    {
+        return String.format("all: %d, same: %d, diff: %d", this.getTotalTests(), this.getSameImages(), this.getDifferentImages());
+    }
 }
diff -r 44b7fc94cdca -r e3e509624def template_test_result.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/template_test_result.html	Thu Sep 09 19:26:50 2010 +0200
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+    <head>
+        <title>Graphics test report</title>
+        <meta name="Author" content="Pavel Tisnovsky" />
+        <meta name="Generator" content="Reporter" />
+        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+        <meta name="keywords" content="test, java" />
+        <style type="text/css">
+            <!--
+            body           {font-family: sans-serif, arial, helvetica, sans-serif; color:#000000; background-color:#ffffff; margin-left: 0px; margin-top: 0px; border:1px; border-color:#808080;border-style:solid}
+            h1             {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; text-align:center; padding-left: 1em; margin: 0}
+            h2             {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; padding-left: 1em; padding-right: 1cm}
+            a              {font-family: arial, helvetica, sans-serif; color:#0000ff; text-decoration:none}
+            a:link         {color:#0000ff}
+            a:visited      {color:#0000ff}
+            a:visited      {color:#0000ff}
+            a:hover        {color:#ffffff; background:#404040}
+            p              {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; padding-left: 1em; padding-right: 1em}
+            .key           {color: #0000aa}
+            .value         {color: #aa0000}
+            .formular      {background-color: #f0f0dd; vertical-align: top; border-collapse: collapse; border-color:#808080}
+            -->
+        </style>
+    </head>
+    <body>
+        <h1>Graphics test report</h2>
+        <table border="1" frame="border" cellspacing="3" cellpadding="1" class="formular" summary="">
+            ${RESULT}
+        </table>
+        <br clear="all" />
+        <hr noshade size="1" width="100%" />
+        <p>Generated by <strong>Reporter</strong></p>
+    </body>
+</html>
+



More information about the distro-pkg-dev mailing list