/hg/gfx-test: * src/org/gfxtest/testsuites/PrintTestPaths.java:

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Tue Jul 17 01:32:53 PDT 2012


changeset bbe4d2bd6894 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=bbe4d2bd6894
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Tue Jul 17 10:35:26 2012 +0200

	* src/org/gfxtest/testsuites/PrintTestPaths.java:
	Added helper methods and three new tests to this test suite.


diffstat:

 ChangeLog                                      |    5 +
 src/org/gfxtest/testsuites/PrintTestPaths.java |  273 ++++++++++++++++++++++++-
 2 files changed, 277 insertions(+), 1 deletions(-)

diffs (303 lines):

diff -r c49d35064c61 -r bbe4d2bd6894 ChangeLog
--- a/ChangeLog	Mon Jul 16 10:34:12 2012 +0200
+++ b/ChangeLog	Tue Jul 17 10:35:26 2012 +0200
@@ -1,3 +1,8 @@
+2012-07-17  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/gfxtest/testsuites/PrintTestPaths.java:
+	Added helper methods and three new tests to this test suite.
+
 2012-07-16  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/gfxtest/framework/GrayscalePalette.java:
diff -r c49d35064c61 -r bbe4d2bd6894 src/org/gfxtest/testsuites/PrintTestPaths.java
--- a/src/org/gfxtest/testsuites/PrintTestPaths.java	Mon Jul 16 10:34:12 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestPaths.java	Tue Jul 17 10:35:26 2012 +0200
@@ -40,7 +40,17 @@
 
 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;
@@ -65,7 +75,268 @@
 @Zoom(1)
 public class PrintTestPaths 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();
+        path.moveTo(x1, y1);
+        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();
+
+        // horizontal 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;
+            }
+            else
+            {
+                y1 += DIAGONAL_STEP;
+            }
+            // second endpoint
+            if (y2 < height - BORDER * 2)
+            {
+                y2 += DIAGONAL_STEP;
+            }
+            else
+            {
+                x2 += DIAGONAL_STEP;
+            }
+            // setup can be made for each line
+            diagonalLineDrawCallbacks.iterationCallBack(d, colorIndex++);
+            // create new path which contains just one line
+            Path2D path = createLinePath(x1, y1, x2, y2);
+            // render the line
+            graphics.draw(path);
+        }
+
+        // cleanup rendering
+        diagonalLineDrawCallbacks.cleanup();
+    }
+
+    /**
+     * Test basic behavior of method Graphics.draw(Path). Horizontal lines are
+     * rendered with default width and default end caps. Color of all rendered
+     * lines are set to black. Lines 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 testDrawHorizontalLinesBasicStyle(TestImage image, Graphics2D graphics)
+    {
+        drawHorizontalLines(image, graphics, VERTICAL_STEP, new HorizontalLineDrawCallbacks()
+        {
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int y, int index)
+            {
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Test basic behavior of method Graphics.draw(Path). Vertical lines are
+     * rendered with default width and default end caps. Color of all rendered
+     * lines are set to black. Lines 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 testDrawVerticalLinesBasicStyle(TestImage image, Graphics2D graphics)
+    {
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP, new VerticalLineDrawCallbacks()
+        {
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Test basic behavior of method Graphics.draw(Path).
+     * Diagonal lines are rendered with default width and default end caps.
+     * Color of all rendered lines are set to black.
+     * Lines 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 testDrawDiagonalLinesBasicStyle(TestImage image, Graphics2D graphics)
+    {
+        drawDiagonalLines(image, graphics, DIAGONAL_STEP, new DiagonalLineDrawCallbacks()
+        {
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
     /**
      * Entry point to the test suite.
      * 



More information about the distro-pkg-dev mailing list