/hg/gfx-test: Refactoring - all tests and helper methods from Pr...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Wed Aug 8 02:57:08 PDT 2012


changeset 8d8b962d5731 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=8d8b962d5731
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Aug 08 11:59:40 2012 +0200

	Refactoring - all tests and helper methods from PrintTestPaths test
	are now divided into three other tests: lines, quadratic curves and
	cubic curves rendering.


diffstat:

 ChangeLog                                                       |   11 +
 Makefile                                                        |    6 +
 src/org/gfxtest/testsuites/PrintTestCubicCurvesAsPaths.java     |  201 +++++
 src/org/gfxtest/testsuites/PrintTestLinesAsPaths.java           |  358 +++++++++
 src/org/gfxtest/testsuites/PrintTestPaths.java                  |  380 +---------
 src/org/gfxtest/testsuites/PrintTestQuadraticCurvesAsPaths.java |  196 +++++
 6 files changed, 774 insertions(+), 378 deletions(-)

diffs (truncated from 1223 to 500 lines):

diff -r f5a7ad12f58d -r 8d8b962d5731 ChangeLog
--- a/ChangeLog	Mon Aug 06 12:37:20 2012 +0200
+++ b/ChangeLog	Wed Aug 08 11:59:40 2012 +0200
@@ -1,3 +1,14 @@
+2012-08-08  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/gfxtest/testsuites/PrintTestPaths.java:
+	* src/org/gfxtest/testsuites/PrintTestCubicCurvesAsPaths.java:
+	* src/org/gfxtest/testsuites/PrintTestLinesAsPaths.java:
+	* src/org/gfxtest/testsuites/PrintTestQuadraticCurvesAsPaths.java:
+	Refactoring - all tests and helper methods from PrintTestPaths test
+	are now divided into three other tests: lines, quadratic curves and
+	cubic curves rendering.
+	* Makefile: Updated - added new classes to compile and new tests to run.
+
 2012-08-06  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/gfxtest/callbacks/CommonCallbacks.java:
diff -r f5a7ad12f58d -r 8d8b962d5731 Makefile
--- a/Makefile	Mon Aug 06 12:37:20 2012 +0200
+++ b/Makefile	Wed Aug 08 11:59:40 2012 +0200
@@ -193,7 +193,9 @@
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestBasic.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestArcs.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestCubicCurves.class \
+	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestCubicCurvesAsPaths.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestLines.class \
+	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestLinesAsPaths.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestSlopedLines.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestRectangles.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestRoundRectangles.class \
@@ -201,6 +203,7 @@
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestPolylines.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestPolygons.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestQuadraticCurves.class \
+	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestQuadraticCurvesAsPaths.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestBitBlt.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestCircles.class \
 	$(CLASSES)/$(TESTSUITE_DIR)/PrintTestEllipses.class \
@@ -282,7 +285,9 @@
 	$(RESULTS)/PrintTestBasic \
 	$(RESULTS)/PrintTestArcs \
 	$(RESULTS)/PrintTestCubicCurves \
+	$(RESULTS)/PrintTestCubicCurvesAsPaths \
 	$(RESULTS)/PrintTestLines \
+	$(RESULTS)/PrintTestLinesAsPaths \
 	$(RESULTS)/PrintTestSlopedLines \
 	$(RESULTS)/PrintTestRectangles \
 	$(RESULTS)/PrintTestRoundRectangles \
@@ -290,6 +295,7 @@
 	$(RESULTS)/PrintTestPolylines \
 	$(RESULTS)/PrintTestPolygons \
 	$(RESULTS)/PrintTestQuadraticCurves \
+	$(RESULTS)/PrintTestQuadraticCurvesAsPaths \
 	$(RESULTS)/PrintTestArcs \
 	$(RESULTS)/PrintTestBitBlt \
 	$(RESULTS)/PrintTestCircles \
diff -r f5a7ad12f58d -r 8d8b962d5731 src/org/gfxtest/testsuites/PrintTestCubicCurvesAsPaths.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/testsuites/PrintTestCubicCurvesAsPaths.java	Wed Aug 08 11:59:40 2012 +0200
@@ -0,0 +1,201 @@
+/*
+  Java gfx-test framework
+
+   Copyright (C) 2012  Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.gfxtest.testsuites;
+
+import java.awt.Graphics2D;
+import java.awt.geom.Path2D;
+
+
+
+import org.gfxtest.callbacks.CubicCurveDrawCallbacks;
+import org.gfxtest.framework.PrintTest;
+import org.gfxtest.framework.TestImage;
+import org.gfxtest.framework.TestResult;
+import org.gfxtest.framework.annotations.GraphicsPrimitive;
+import org.gfxtest.framework.annotations.GraphicsPrimitives;
+import org.gfxtest.framework.annotations.RenderStyle;
+import org.gfxtest.framework.annotations.RenderStyles;
+import org.gfxtest.framework.annotations.TestType;
+import org.gfxtest.framework.annotations.TestTypes;
+import org.gfxtest.framework.annotations.Transformation;
+import org.gfxtest.framework.annotations.Transformations;
+import org.gfxtest.framework.annotations.Zoom;
+
+
+
+/**
+ * This test suite checks rendering of various cubic curves. Cubic curves are
+ * rendered as paths which consists of only one segment - the curve itself.
+ * 
+ * @author Pavel Tisnovsky
+ */
+ at TestType(TestTypes.PRINT_TEST)
+ at GraphicsPrimitive(GraphicsPrimitives.CUBIC_CURVE)
+ at RenderStyle(RenderStyles.NORMAL)
+ at Transformation(Transformations.NONE)
+ at Zoom(1)
+public class PrintTestCubicCurvesAsPaths extends PrintTest
+{
+
+    /**
+     * Create Path2D which contains only one cubic curve.
+     * 
+     * @param x1
+     *            x coordinate of the first control point
+     * @param y1
+     *            y coordinate of the first control point
+     * @param x2
+     *            x coordinate of the second control point
+     * @param y2
+     *            y coordinate of the second control point
+     * @param x3
+     *            x coordinate of third control point
+     * @param y3
+     *            y coordinate of third control point
+     * @param x4
+     *            x coordinate of fourth control point
+     * @param y4
+     *            y coordinate of fourth control point
+     * @return newly created path
+     */
+    private static Path2D createCubicCurvePath(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+    {
+        Path2D path = new Path2D.Float();
+        // first control point
+        path.moveTo(x1, y1);
+        // second, third and fourth control point
+        path.curveTo(x2, y2, x3, y3, x4, y4);
+        return path;
+    }
+
+    /**
+     * Method which renders set of cubic curves using various colors and
+     * stroke styles. For each curve, the callback function/method is called to
+     * perform all required setup. Curves are represented by a Path object.
+     * 
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @param verticalStep
+     *            between two near curves
+     * @param cubicCurveCallback
+     *            class containing set of callback methods
+     */
+    private static void drawCubicCurve(TestImage image, Graphics2D graphics, int verticalStep, CubicCurveDrawCallbacks cubicCurveCallback)
+    {
+        // setup rendering
+        cubicCurveCallback.setup(image, graphics);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // horizontal coordinates of curve endpoints
+        final int x1 = BORDER;
+        final int x4 = width - BORDER;
+        final int x2 = (x1 + x4) * 1 / 3;
+        final int x3 = (x1 + x4) * 2 / 3;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all lines onto a paper
+        for (int y = BORDER * 10; y < height - BORDER * 10; y += verticalStep)
+        {
+            // compute other control points coordinates
+            final int y1 = y;
+            final int y2 = y - (BORDER << 4);
+            final int y3 = y + (BORDER << 4);
+            final int y4 = y;
+            // setup can be made for each line
+            cubicCurveCallback.iterationCallBack(x1, y1, x2, y2, x3, y3, x4, y4, colorIndex++);
+            // create new path which contains just one line
+            Path2D path = createCubicCurvePath(x1, y1, x2, y2, x3, y3, x4, y4);
+            // render the line
+            graphics.draw(path);
+        }
+
+        // cleanup rendering
+        cubicCurveCallback.cleanup();
+    }
+
+    /**
+     * Test basic behavior of method Graphics.draw(Path).
+     * Cubic curves are rendered with default width and default end caps.
+     * Color of all rendered curves are set to black.
+     * All rendered cubic curves are represented by a Path object.
+     *
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawCubicCurvesBasicStyle(TestImage image, Graphics2D graphics)
+    {
+        drawCubicCurve(image, graphics, CUBIC_CURVE_STEP, new CubicCurveDrawCallbacks()
+        {
+            /**
+             * Callback function called before each cubic curve is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int index)
+            {
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Entry point to the test suite.
+     * 
+     * @param args
+     *            not used in this case
+     */
+    public static void main(String[] args)
+    {
+        new PrintTestCubicCurvesAsPaths().runTestSuite(args);
+    }
+}
diff -r f5a7ad12f58d -r 8d8b962d5731 src/org/gfxtest/testsuites/PrintTestLinesAsPaths.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/testsuites/PrintTestLinesAsPaths.java	Wed Aug 08 11:59:40 2012 +0200
@@ -0,0 +1,358 @@
+/*
+  Java gfx-test framework
+
+   Copyright (C) 2012  Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.gfxtest.testsuites;
+
+import java.awt.Graphics2D;
+import java.awt.geom.Path2D;
+
+
+
+import org.gfxtest.callbacks.DiagonalLineDrawCallbacks;
+import org.gfxtest.callbacks.HorizontalLineDrawCallbacks;
+import org.gfxtest.callbacks.VerticalLineDrawCallbacks;
+import org.gfxtest.framework.PrintTest;
+import org.gfxtest.framework.TestImage;
+import org.gfxtest.framework.TestResult;
+import org.gfxtest.framework.annotations.GraphicsPrimitive;
+import org.gfxtest.framework.annotations.GraphicsPrimitives;
+import org.gfxtest.framework.annotations.RenderStyle;
+import org.gfxtest.framework.annotations.RenderStyles;
+import org.gfxtest.framework.annotations.TestType;
+import org.gfxtest.framework.annotations.TestTypes;
+import org.gfxtest.framework.annotations.Transformation;
+import org.gfxtest.framework.annotations.Transformations;
+import org.gfxtest.framework.annotations.Zoom;
+
+
+
+/**
+ * This test suite checks rendering of various lines. Lines are rendered as
+ * paths which consists of only one segment - the line itself.
+ * 
+ * @author Pavel Tisnovsky
+ */
+ at TestType(TestTypes.PRINT_TEST)
+ at GraphicsPrimitive(GraphicsPrimitives.LINE)
+ at RenderStyle(RenderStyles.NORMAL)
+ at Transformation(Transformations.NONE)
+ at Zoom(1)
+public class PrintTestLinesAsPaths extends PrintTest
+{
+    /**
+     * Create Path2D which contains just one line.
+     * 
+     * @param x1
+     *            the first point's x coordinate.
+     * @param y1
+     *            the first point's y coordinate.
+     * @param x2
+     *            the second point's x coordinate.
+     * @param y2
+     *            the second point's y coordinate.
+     * @return newly created path
+     */
+    private static Path2D createLinePath(int x1, int y1, int x2, int y2)
+    {
+        Path2D path = new Path2D.Float();
+        // first endpoint
+        path.moveTo(x1, y1);
+        // second endpoint
+        path.lineTo(x2, y2);
+        return path;
+    }
+
+    /**
+     * Method which renders set of horizontal lines using various colors and
+     * stroke styles. For each line, the callback function/method is called to
+     * perform all required setup. Lines are represented by a Path object.
+     * 
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @param verticalStep
+     *            between two near lines
+     * @param horizontalLineDrawCallbacks
+     *            class containing set of callback methods
+     */
+    private static void drawHorizontalLines(TestImage image, Graphics2D graphics, int verticalStep, HorizontalLineDrawCallbacks horizontalLineDrawCallbacks)
+    {
+        // setup rendering
+        horizontalLineDrawCallbacks.setup(image, graphics);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // horizontal coordinates of line endpoints
+        final int x1 = BORDER;
+        final int x2 = width - BORDER;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all lines onto a paper
+        for (int y = 0; y < height; y += verticalStep)
+        {
+            // setup can be made for each line
+            horizontalLineDrawCallbacks.iterationCallBack(y, colorIndex++);
+            // create new path which contains just one line
+            Path2D path = createLinePath(x1, y, x2, y);
+            // render the line
+            graphics.draw(path);
+        }
+
+        // cleanup rendering
+        horizontalLineDrawCallbacks.cleanup();
+    }
+
+    /**
+     * Method which renders set of vertical lines using various colors and
+     * stroke styles. For each line, the callback function/method is called to
+     * perform all required setup. Lines are represented by a Path object.
+     * 
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @param horizontalStep
+     *            between two near lines
+     * @param verticalLineDrawCallbacks
+     *            class containing set of callback methods
+     */
+    private static void drawVerticalLines(TestImage image, Graphics2D graphics, int horizontalStep, VerticalLineDrawCallbacks verticalLineDrawCallbacks)
+    {
+        // setup rendering
+        verticalLineDrawCallbacks.setup(image, graphics);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // vertical coordinates of line endpoints
+        final int y1 = BORDER;
+        final int y2 = height - BORDER;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all lines onto a paper
+        for (int x = 0; x < width; x += horizontalStep)
+        {
+            // setup can be made for each line
+            verticalLineDrawCallbacks.iterationCallBack(x, colorIndex++);
+            // create new path which contains just one line
+            Path2D path = createLinePath(x, y1, x, y2);
+            // render the line
+            graphics.draw(path);
+        }
+
+        // cleanup rendering
+        verticalLineDrawCallbacks.cleanup();
+    }
+
+    /**
+     * Method which renders set of diagonal lines using various colors and
+     * stroke styles. For each line, the callback function/method is called to
+     * perform all required setup. Lines are represented by a Path object.
+     * 
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @param diagonalStep
+     *            between two near lines
+     * @param diagonalLineDrawCallbacks
+     *            class containing set of callback methods
+     */
+    private static void drawDiagonalLines(TestImage image, Graphics2D graphics, int diagonalStep, DiagonalLineDrawCallbacks diagonalLineDrawCallbacks)
+    {
+        // setup rendering
+        diagonalLineDrawCallbacks.setup(image, graphics);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // length of the "path"
+        final int length = width + height - BORDER * 8;
+
+        // coordinates of the first line
+        int x1 = BORDER;
+        int y1 = BORDER;
+        int x2 = BORDER;
+        int y2 = BORDER;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all lines onto a paper
+        for (int d = 0; d < length; d += DIAGONAL_STEP)
+        {
+            // first endpoint
+            if (x1 < width - BORDER * 2)
+            {
+                x1 += DIAGONAL_STEP;
+            }



More information about the distro-pkg-dev mailing list