/hg/gfx-test: Minor refactoring of some test suites.

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Wed Jul 21 07:27:51 PDT 2010


changeset ec0b1d456477 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=ec0b1d456477
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Jul 21 16:28:07 2010 +0200

	Minor refactoring of some test suites.


diffstat:

12 files changed, 195 insertions(+), 152 deletions(-)
TODO                                                          |   17 +
src/org/gfxtest/framework/Configuration.java                  |   39 +--
src/org/gfxtest/framework/GfxTest.java                        |  117 ++++++++--
src/org/gfxtest/framework/InvalidParameterValueException.java |    2 
src/org/gfxtest/framework/Log.java                            |   28 +-
src/org/gfxtest/framework/ParameterNotFoundException.java     |    2 
src/org/gfxtest/framework/TestImage.java                      |   17 -
src/org/gfxtest/testsuites/FilledCircles.java                 |   14 +
src/org/gfxtest/testsuites/FilledEllipses.java                |    2 
src/org/gfxtest/testsuites/FilledPolygons.java                |   37 ---
src/org/gfxtest/testsuites/NormalCircles.java                 |   34 --
src/org/gfxtest/testsuites/NormalPolygons.java                |   38 ---

diffs (truncated from 768 to 500 lines):

diff -r fd811bf815e0 -r ec0b1d456477 TODO
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TODO	Wed Jul 21 16:28:07 2010 +0200
@@ -0,0 +1,17 @@
+BlankImage.java
+DashedLines.java
+DashedPolylines.java
+DashedRectangles.java
+FilledEllipses.java
+FilledRectangles.java
+FilledRoundRectangles.java
+Normal3DRectangles.java
+NormalArcs.java
+NormalEllipses.java
+NormalLines.java
+NormalPolylines.java
+NormalRectangles.java
+NormalRoundRectangles.java
+ScaledLines.java
+ScaledPolylines.java
+ScaledRectangles.java
diff -r fd811bf815e0 -r ec0b1d456477 src/org/gfxtest/framework/Configuration.java
--- a/src/org/gfxtest/framework/Configuration.java	Wed Jul 21 14:19:13 2010 +0200
+++ b/src/org/gfxtest/framework/Configuration.java	Wed Jul 21 16:28:07 2010 +0200
@@ -83,12 +83,13 @@ public class Configuration
     public Configuration(String[] args, Log log) throws ConfigurationException
     {
         this.log = log;
-        log.logBegin("read configuration");
+        log.logBegin("read configuration"); //$NON-NLS-1$
         readCommandLineParameters(args);
-        log.logEnd("read configuration");
+        log.logEnd("read configuration"); //$NON-NLS-1$
         printParameters();
     }
 
+    @SuppressWarnings("nls")
     private void readCommandLineParameters(String[] args) throws ConfigurationException
     {
         Map<String, String> options = resolveAllOptions(args);
@@ -98,28 +99,29 @@ public class Configuration
         this.outputPath = new File(getStringParameter(options, "o"));
     }
 
+    @SuppressWarnings("nls")
     private int getImageType(Map<String, String> options) throws ConfigurationException
     {
         if (!options.containsKey("t"))
         {
             throw new ParameterNotFoundException("t");
         }
-        String imageType = options.get("t");
-        if ("rgb".equals(imageType))
+        String imgType = options.get("t");
+        if ("rgb".equals(imgType))
         {
             return BufferedImage.TYPE_INT_RGB;
         }
-        else if ("gray".equals(imageType))
+        else if ("gray".equals(imgType))
         {
             return  BufferedImage.TYPE_BYTE_GRAY;
         }
-        else if ("bw".equals(imageType) || ("bit".equals(imageType)))
+        else if ("bw".equals(imgType) || ("bit".equals(imgType)))
         {
             return BufferedImage.TYPE_BYTE_INDEXED;
         }
         else
         {
-            throw new InvalidParameterValueException("t", imageType); 
+            throw new InvalidParameterValueException("t", imgType); 
         }
     }
 
@@ -149,6 +151,7 @@ public class Configuration
         return options.get(parameterName);
     }
 
+    @SuppressWarnings("nls")
     private Map<String, String> resolveAllOptions(String[] args)
     {
         Map<String, String> options = new HashMap<String, String>();
@@ -157,45 +160,45 @@ public class Configuration
             String[] splittedArg = arg.split("=");
             if (splittedArg.length >= 1 && splittedArg[0].length() >= 2)
             {
-                log.log("found option " + arg);
+                this.log.log("found option " + arg);
                 String optionName = splittedArg[0].substring(1);
                 String optionValue = splittedArg.length == 2 ? splittedArg[1] : "true";
                 options.put(optionName, optionValue);
             }
             else
             {
-                log.logError("unknown option " + arg);
+                this.log.logError("unknown option " + arg);
             }
         }
         return options;
     }
 
+    @SuppressWarnings("nls")
     private void printParameters()
     {
-        log.logSet("output path", this.outputPath);
-        log.logSet("image width", this.imageWidth);
-        log.logSet("image height", this.imageHeight);
-        log.logSet("image type", this.imageType);
+        this.log.logSet("output path", this.outputPath);
+        this.log.logSet("image width", Integer.valueOf(this.imageWidth));
+        this.log.logSet("image height", Integer.valueOf(this.imageHeight));
+        this.log.logSet("image type", Integer.valueOf(this.imageType));
     }
 
     public File getOutputPath()
     {
-        return outputPath;
+        return this.outputPath;
     }
 
     public int getImageWidth()
     {
-        return imageWidth;
+        return this.imageWidth;
     }
 
     public int getImageHeight()
     {
-        return imageHeight;
+        return this.imageHeight;
     }
 
     public int getImageType()
     {
-        return imageType;
+        return this.imageType;
     }
-
 }
diff -r fd811bf815e0 -r ec0b1d456477 src/org/gfxtest/framework/GfxTest.java
--- a/src/org/gfxtest/framework/GfxTest.java	Wed Jul 21 14:19:13 2010 +0200
+++ b/src/org/gfxtest/framework/GfxTest.java	Wed Jul 21 16:28:07 2010 +0200
@@ -76,8 +76,38 @@ public abstract class GfxTest
      */
     private void printDuration(long t1, long t2)
     {
-        log.logSet("duration", (t2-t1));
+        this.log.logSet("duration", Long.valueOf(t2-t1)); //$NON-NLS-1$
     }
+
+    /**
+     * Default cap style.
+     */
+    protected static final int[] DEFAULT_CAP_STYLE = {BasicStroke.CAP_ROUND};
+
+    /**
+     * All cap styles available.
+     */
+    protected static final int[] ALL_CAP_STYLES = { BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, BasicStroke.CAP_SQUARE };
+
+    /**
+     * Default join style.
+     */
+    protected static final int[] DEFAULT_JOIN_STYLE = {BasicStroke.JOIN_ROUND};
+
+    /**
+     * All available join styles.
+     */
+    protected static final int[] ALL_JOIN_STYLES = { BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, BasicStroke.CAP_ROUND };
+
+    /**
+     * Default line or curve width.
+     */
+    protected static final float[] DEFAULT_WIDTH = { 1.0f };
+
+    /**
+     * All line or curve widths.
+     */
+    protected static final float[] ALL_WIDTHS = { 1.0f, 2.0f, 5.0f, 10.0f, 20.0f, 40.0f };
 
     /**
      * Construct test suite name using full class name.
@@ -91,13 +121,13 @@ public abstract class GfxTest
     protected void runTestSuite(String[] args)
     {
         long t1 = System.currentTimeMillis();
-        log = new Log(this.getClass().getName(), true);
-        log.logBegin("testsuite");
+        this.log = new Log(this.getClass().getName(), true);
+        this.log.logBegin("testsuite"); //$NON-NLS-1$
         fillSuiteName();
         Configuration configuration;
         try
         {
-            configuration = new Configuration(args, log);
+            configuration = new Configuration(args, this.log);
             runAllTests(configuration);
         }
         catch (ConfigurationException e)
@@ -107,7 +137,7 @@ public abstract class GfxTest
         finally
         {
             long t2 = System.currentTimeMillis();
-            log.logEnd("testsuite");
+            this.log.logEnd("testsuite"); //$NON-NLS-1$
             printDuration(t1, t2);
         }
     }
@@ -124,16 +154,28 @@ public abstract class GfxTest
      */
     private void runAllTests(Configuration configuration)
     {
-        log.logBegin("common tests");
+        this.log.logBegin("common tests"); //$NON-NLS-1$
         Method[] methods = getClass().getDeclaredMethods();
         for (Method method : methods)
         {
             tryToInvokeTestMethod(configuration, method);
         }
-        log.logEnd("common tests");
-        log.logBegin("other tests");
+        this.log.logEnd("common tests"); //$NON-NLS-1$
+        this.log.logBegin("other tests"); //$NON-NLS-1$
         runOtherTests(configuration);
-        log.logEnd("other tests");
+        this.log.logEnd("other tests"); //$NON-NLS-1$
+    }
+
+    /**
+     * Method used for starts various tests which can be overridden by inherited
+     * classes.
+     *
+     * @param configuration
+     *            configuration of current test case.
+     */
+    protected void runOtherTests(Configuration configuration)
+    {
+        // to be overrided by test cases
     }
 
     /**
@@ -141,18 +183,53 @@ public abstract class GfxTest
      *
      * @param configuration configuration of current test case.
      */
-    protected void runOtherTests(Configuration configuration)
+    protected void drawEntity(TestImage image, Graphics2D graphics, int testNumber, float scale, float width, int cap, int join, float[] dash)
     {
+        // to be overrided by test cases
+    }
+
+    protected void drawEntityWithVariousStyles(Configuration configuration, boolean changeCap, boolean changeJoin, boolean changeWidth, boolean changeScale, boolean changeDash)
+    {
+        int[] caps  =    changeCap ? ALL_CAP_STYLES : DEFAULT_CAP_STYLE; 
+        int[] joins =    changeJoin ? ALL_JOIN_STYLES : DEFAULT_JOIN_STYLE;
+        float[] widths = changeWidth ? ALL_WIDTHS : DEFAULT_WIDTH;
+        int testNumber = 0;
+        for (int cap : caps)
+        {
+            for (int join : joins)
+            {
+                for (float width : widths)
+                {
+                    String testName = "test" + testNumber; //$NON-NLS-1$
+                    this.log.logBegin(testName);
+                    TestImage image = new TestImage(configuration);
+                    Graphics2D graphics = image.getGraphics();
+                    /* TODO: add support to various scales and dashes */ 
+                    drawEntity(image, graphics, testNumber, 1.0f, width, cap, join, null);
+                    graphics.dispose();
+                    try
+                    {
+                        image.writeImage(configuration, this.suiteName, testName);
+                    }
+                    catch (IOException e)
+                    {
+                        e.printStackTrace();
+                    }
+                    this.log.logEnd(testName);
+                    testNumber++;
+                }
+            }
+        }
     }
 
     private void tryToInvokeTestMethod(Configuration configuration, Method method)
     {
         String methodName = method.getName();
-        if (method.getName().startsWith("test"))
+        if (method.getName().startsWith("test")) //$NON-NLS-1$
         {
-            log.logBegin(methodName);
+            this.log.logBegin(methodName);
             TestImage image = new TestImage(configuration);
-            Graphics2D gc = (Graphics2D) image.getGraphics();
+            Graphics2D gc = image.getGraphics();
             TestResult result = null;
             try
             {
@@ -169,13 +246,13 @@ public abstract class GfxTest
                 logTestResult(result);
                 try
                 {
-                    image.writeImage(configuration, suiteName, methodName);
+                    image.writeImage(configuration, this.suiteName, methodName);
                 }
                 catch (IOException e)
                 {
                     e.printStackTrace();
                 }
-                log.logEnd(methodName);
+                this.log.logEnd(methodName);
             }
         }
     }
@@ -187,20 +264,20 @@ public abstract class GfxTest
      */
     protected void logTestResult(TestResult result)
     {
-        String resultText = "";
+        String resultText = ""; //$NON-NLS-1$
         switch (result)
         {
         case PASSED:
-            resultText = "$GREEN$PASSED";
+            resultText = "$GREEN$PASSED"; //$NON-NLS-1$
             break;
         case FAILED:
-            resultText = "$RED$FAILED";
+            resultText = "$RED$FAILED"; //$NON-NLS-1$
             break;
         case ERROR:
-            resultText = "$BLUE$ERROR";
+            resultText = "$BLUE$ERROR"; //$NON-NLS-1$
             break;
         }
-        log.logSet("test result", resultText);
+        this.log.logSet("test result", resultText); //$NON-NLS-1$
     }
 
     /**
diff -r fd811bf815e0 -r ec0b1d456477 src/org/gfxtest/framework/InvalidParameterValueException.java
--- a/src/org/gfxtest/framework/InvalidParameterValueException.java	Wed Jul 21 14:19:13 2010 +0200
+++ b/src/org/gfxtest/framework/InvalidParameterValueException.java	Wed Jul 21 16:28:07 2010 +0200
@@ -53,7 +53,7 @@ public class InvalidParameterValueExcept
 
     public InvalidParameterValueException(String parameterName, String value)
     {
-        super("invalid value of parameter " + parameterName + ": " + value);
+        super("invalid value of parameter " + parameterName + ": " + value); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
 }
diff -r fd811bf815e0 -r ec0b1d456477 src/org/gfxtest/framework/Log.java
--- a/src/org/gfxtest/framework/Log.java	Wed Jul 21 14:19:13 2010 +0200
+++ b/src/org/gfxtest/framework/Log.java	Wed Jul 21 16:28:07 2010 +0200
@@ -49,6 +49,7 @@ import java.util.HashMap;
  *
  * @author Pavel Tisnovsky
  */
+ at SuppressWarnings("nls")
 public class Log
 {
     static HashMap<String, String> colors = new HashMap<String, String>(10);
@@ -105,8 +106,9 @@ public class Log
         this.log(this.className, str);
     }
 
-    public void log(String className, String str)
+    public void log(String clsName, String message)
     {
+        String str = message;
         StringBuffer spaces = new StringBuffer();
         for (int i = 0; i < this.indent; i++)
         {
@@ -114,14 +116,14 @@ public class Log
         }
 
         StringBuffer output = new StringBuffer();
-        if (useColors)
+        if (this.useColors)
         {
-            str = "$GREEN$GfxTest  $LIGHT_BLUE$" + this.getDate() + "  $ORANGE$" + String.format("%-40s", className)
+            str = "$GREEN$GfxTest  $LIGHT_BLUE$" + this.getDate() + "  $ORANGE$" + String.format("%-40s", clsName)
                     + spaces + "  $GRAY$" + str;
         }
         else
         {
-            str = "GfxTest  " + this.getDate() + "  " +  String.format("%-40s", className) + spaces + "  " + str;
+            str = "GfxTest  " + this.getDate() + "  " +  String.format("%-40s", clsName) + spaces + "  " + str;
         }
 
         String[] pieces = str.split("\\$");
@@ -130,7 +132,7 @@ public class Log
         {
             if (colors.containsKey(piece.toUpperCase()))
             {
-                if (useColors)
+                if (this.useColors)
                 {
                     output.append("\033[0;" + colors.get(piece.toUpperCase()) + "m");
                 }
@@ -141,7 +143,7 @@ public class Log
             }
         }
         // vypis vytvoreneho retezce na standardni vystup
-        if (useColors)
+        if (this.useColors)
         {
             System.out.println(output.append("\033[0m"));
         }
@@ -157,9 +159,9 @@ public class Log
         this.log("$LIGHT_BLUE$" + str + "$ORANGE$ = " + value);
     }
 
-    public void logBegin(String className, String str)
+    public void logBegin(String clsName, String str)
     {
-        this.log(className, str + " $GREEN$begin");
+        this.log(clsName, str + " $GREEN$begin");
         this.indent += this.indentDelta;
     }
 
@@ -168,13 +170,13 @@ public class Log
         this.logBegin(this.className, str);
     }
 
-    public void logEnd(String className, String str)
+    public void logEnd(String clsName, String str)
     {
         if (this.indent >= this.indentDelta)
         {
             this.indent -= this.indentDelta;
         }
-        this.log(className, str + " $VIOLET$end");
+        this.log(clsName, str + " $VIOLET$end");
     }
 
     public void logEnd(String str)
@@ -187,9 +189,9 @@ public class Log
         this.logError(this.className, str);
     }
 
-    public void logError(String className, String str)
+    public void logError(String clsName, String str)
     {
-        this.log(className, "$RED$error $GRAY$" + str);
+        this.log(clsName, "$RED$error $GRAY$" + str);
     }
 
     public static void main(String[] args)
@@ -198,7 +200,7 @@ public class Log
         System.out.println("test end");
     }
 
-    @SuppressWarnings("deprecation")
+    @SuppressWarnings({ "deprecation", "boxing" })
     private String getDate()
     {
         // vytvorime pomocny buffer, do ktereho seskladame retezec
diff -r fd811bf815e0 -r ec0b1d456477 src/org/gfxtest/framework/ParameterNotFoundException.java
--- a/src/org/gfxtest/framework/ParameterNotFoundException.java	Wed Jul 21 14:19:13 2010 +0200
+++ b/src/org/gfxtest/framework/ParameterNotFoundException.java	Wed Jul 21 16:28:07 2010 +0200
@@ -53,7 +53,7 @@ public class ParameterNotFoundException 
 
     public ParameterNotFoundException(String parameterName)
     {
-        super("parameter " + parameterName + " not found");
+        super("parameter " + parameterName + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
 }
diff -r fd811bf815e0 -r ec0b1d456477 src/org/gfxtest/framework/TestImage.java
--- a/src/org/gfxtest/framework/TestImage.java	Wed Jul 21 14:19:13 2010 +0200
+++ b/src/org/gfxtest/framework/TestImage.java	Wed Jul 21 16:28:07 2010 +0200
@@ -56,7 +56,7 @@ public class TestImage
 
     public TestImage(Configuration configuration)
     {
-        log = new Log(this.getClass().getName(), true);
+        this.log = new Log(this.getClass().getName(), true);
         this.createImage(configuration);
     }
 
@@ -85,16 +85,18 @@ public class TestImage
         graphics.dispose();
     }
 
+    @SuppressWarnings("nls")
     protected BufferedImage readImage(File directory, String fileName) throws IOException
     {
-        log.log("reading image " + fileName + " from directory " + directory);
+        this.log.log("reading image " + fileName + " from directory " + directory);
         File imageFile = new File(directory, fileName);
         return ImageIO.read(imageFile);
     }
 
+    @SuppressWarnings("nls")
     private void writeImage(File directory, String fileName) throws IOException



More information about the distro-pkg-dev mailing list