/hg/gfx-test: * src/org/gfxtest/testsuites/PrintTestColorPaint.j...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Mon Jun 18 06:25:59 PDT 2012


changeset 91cef43793d3 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=91cef43793d3
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Jun 18 15:28:39 2012 +0200

	* src/org/gfxtest/testsuites/PrintTestColorPaint.java:
	Five new tests were added to this test suite.


diffstat:

 ChangeLog                                           |    5 +
 src/org/gfxtest/testsuites/PrintTestColorPaint.java |  362 ++++++++++++++++++++
 2 files changed, 367 insertions(+), 0 deletions(-)

diffs (394 lines):

diff -r 0036389a51c8 -r 91cef43793d3 ChangeLog
--- a/ChangeLog	Fri Jun 15 15:55:10 2012 +0200
+++ b/ChangeLog	Mon Jun 18 15:28:39 2012 +0200
@@ -1,3 +1,8 @@
+2012-06-18  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/gfxtest/testsuites/PrintTestColorPaint.java:
+	Five new tests were added to this test suite.
+
 2012-06-15  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/gfxtest/callbacks/CommonCircleDrawCallbacks.java:
diff -r 0036389a51c8 -r 91cef43793d3 src/org/gfxtest/testsuites/PrintTestColorPaint.java
--- a/src/org/gfxtest/testsuites/PrintTestColorPaint.java	Fri Jun 15 15:55:10 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestColorPaint.java	Mon Jun 18 15:28:39 2012 +0200
@@ -40,7 +40,18 @@
 
 package org.gfxtest.testsuites;
 
+import java.awt.Graphics2D;
+
+
+
+import org.gfxtest.callbacks.CommonCircleDrawCallbacks;
+import org.gfxtest.callbacks.DiagonalLineDrawCallbacks;
+import org.gfxtest.callbacks.HorizontalLineDrawCallbacks;
+import org.gfxtest.callbacks.VerticalLineDrawCallbacks;
+import org.gfxtest.framework.ColorPalette;
 import org.gfxtest.framework.PrintTest;
+import org.gfxtest.framework.TestImage;
+import org.gfxtest.framework.TestResult;
 import org.gfxtest.framework.annotations.RenderStyle;
 import org.gfxtest.framework.annotations.RenderStyles;
 import org.gfxtest.framework.annotations.TestType;
@@ -62,8 +73,359 @@
 @Zoom(1)
 public class PrintTestColorPaint extends PrintTest
 {
+
+    /**
+     * 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.
+     * 
+     * @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++);
+            // render the line
+            graphics.drawLine(x1, y, x2, y);
+        }
+
+        // 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.
+     * 
+     * @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++);
+            // render the line
+            graphics.drawLine(x, y1, x, y2);
+        }
+
+        // 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.
+     * 
+     * @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++);
+            // render the line
+            graphics.drawLine(x1, y1, x2, y2);
+        }
+
+        // cleanup rendering
+        diagonalLineDrawCallbacks.cleanup();
+    }
+
+    /**
+     * Test basic behavior of method Graphics.drawLine().
+     * Horizontal lines are rendered with default width and default end caps.
+     * Lines color are selected from a palette.
+     *
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawHorizontalLinesColorPalette(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)
+            {
+                // set line color
+                this.graphics.setColor(ColorPalette.getColor(index));
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Test basic behavior of method Graphics.drawLine().
+     * Vertical lines are rendered with default width and default end caps.
+     * Lines color are selected from a palette.
+     *
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawVerticalLinesColorPalette(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)
+            {
+                // set line color
+                this.graphics.setColor(ColorPalette.getColor(index));
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
     
     /**
+     * Test basic behavior of method Graphics.drawLine().
+     * Diagonal lines are rendered with default width and default end caps.
+     * Lines color are selected from a palette.
+     *
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawDiagonalLinesColorPalette(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)
+            {
+                // set line color
+                this.graphics.setColor(ColorPalette.getColor(index));
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Test basic behavior of method Graphics.drawOval().
+     * Circles color are selected from a palette.
+     *
+     * @param image
+     *            image to which circles are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawCircleColorPalette(TestImage image, Graphics2D graphics2d)
+    {
+        drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP, new CommonCircleDrawCallbacks()
+        {
+            /**
+             * Callback function called before each circle is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+            {
+                // set new circle color to index
+                this.graphics.setColor(ColorPalette.getColor(index));
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Test basic behavior of method Graphics.drawOval().
+     * Circles color are selected from a palette.
+     *
+     * @param image
+     *            image to which circles are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawCircleColorPaletteInv(TestImage image, Graphics2D graphics2d)
+    {
+        drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP, new CommonCircleDrawCallbacks()
+        {
+            /**
+             * Callback function called before each circle is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+            {
+                // set new circle color according to index
+                this.graphics.setColor(ColorPalette.getColor(MAX_COLOR_INDEX - index));
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Method which renders set of circles using various colors and
+     * stroke styles. For each circle, the callback function/method is called to
+     * perform all required setup.
+     * 
+     * @param image
+     *            image to which circles are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @param radiusStep
+     *            between two near circles
+     * @param circleDrawCallback
+     *            class containing set of callback methods
+     */
+    private void drawCircle(TestImage image, Graphics2D graphics2d, int radiusStep, CommonCircleDrawCallbacks circleDrawCallback)
+    {
+        // setup rendering
+        circleDrawCallback.setup(image, graphics2d);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // horizontal coordinates of circle center
+        final int xc = width >> 1;
+        final int yc = height >> 1;
+
+        // maximum radius
+        final int maxRadius = Math.min(width, height) - BORDER;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all circles onto a paper
+        for (int radius = MINIMUM_RADIUS; radius < maxRadius; radius += radiusStep)
+        {
+            // setup can be made for each circle
+            circleDrawCallback.iterationCallBack(xc, yc, radius, maxRadius, colorIndex++);
+            // render the circle
+            graphics2d.drawOval(xc - radius, yc - radius, radius << 1, radius << 1);
+        }
+
+        // cleanup rendering
+        circleDrawCallback.cleanup();
+    }
+
+    /**
      * Entry point to the test suite.
      * 
      * @param args



More information about the distro-pkg-dev mailing list