/hg/gfx-test: Fixed runtime exception which occured, when the gr...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Mon Jul 16 01:31:41 PDT 2012
changeset c49d35064c61 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=c49d35064c61
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Jul 16 10:34:12 2012 +0200
Fixed runtime exception which occured, when the grayscale value is
outside the awaited range.
Added three new tests to the test suite PrintTestPolylines.
diffstat:
ChangeLog | 8 +
src/org/gfxtest/framework/GrayscalePalette.java | 27 ++++-
src/org/gfxtest/testsuites/PrintTestPolylines.java | 107 ++++++++++++++++++++-
3 files changed, 138 insertions(+), 4 deletions(-)
diffs (188 lines):
diff -r 0c1ceef887ca -r c49d35064c61 ChangeLog
--- a/ChangeLog Fri Jul 13 13:59:05 2012 +0200
+++ b/ChangeLog Mon Jul 16 10:34:12 2012 +0200
@@ -1,3 +1,11 @@
+2012-07-16 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/gfxtest/framework/GrayscalePalette.java:
+ Fixed runtime exception which occured, when the grayscale value is
+ outside the awaited range.
+ * src/org/gfxtest/testsuites/PrintTestPolylines.java:
+ Added three new tests to this test suite.
+
2012-07-13 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/testsuites/PrintTestEllipses.java:
diff -r 0c1ceef887ca -r c49d35064c61 src/org/gfxtest/framework/GrayscalePalette.java
--- a/src/org/gfxtest/framework/GrayscalePalette.java Fri Jul 13 13:59:05 2012 +0200
+++ b/src/org/gfxtest/framework/GrayscalePalette.java Mon Jul 16 10:34:12 2012 +0200
@@ -63,7 +63,30 @@
*/
public static Color createGrayscaleColor(float gray)
{
- return new Color(gray, gray, gray);
+ float clampedGray = clampGrayScaleValue(gray);
+ return new Color(clampedGray, clampedGray, clampedGray);
}
-
+
+ /**
+ * Clamp grayscale value to a given range 0.0f - 1.0f
+ *
+ * @param gray
+ * input grayscale value
+ * @return output grayscale value
+ */
+ private static float clampGrayScaleValue(float gray)
+ {
+ // negative values are clamped to zero
+ if (gray < 0.0f)
+ {
+ return 0.0f;
+ }
+ // bigger positive values are clamped to one
+ if (gray > 1.0f)
+ {
+ return 1.0f;
+ }
+ return gray;
+ }
+
}
diff -r 0c1ceef887ca -r c49d35064c61 src/org/gfxtest/testsuites/PrintTestPolylines.java
--- a/src/org/gfxtest/testsuites/PrintTestPolylines.java Fri Jul 13 13:59:05 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestPolylines.java Mon Jul 16 10:34:12 2012 +0200
@@ -40,11 +40,14 @@
package org.gfxtest.testsuites;
+import java.awt.BasicStroke;
import java.awt.Graphics2D;
import org.gfxtest.callbacks.PolylineDrawCallbacks;
+import org.gfxtest.framework.ColorPalette;
+import org.gfxtest.framework.GrayscalePalette;
import org.gfxtest.framework.PrintTest;
import org.gfxtest.framework.TestImage;
import org.gfxtest.framework.TestResult;
@@ -127,9 +130,9 @@
}
/**
- * Test basic behavior of method Graphics.drawRect(). Rectangles are
+ * Test basic behavior of method Graphics.drawPolyline(). Polyline are
* rendered with default width and default end caps. Color of all rendered
- * rectangles are set to black.
+ * polylines are set to black.
*
* @param image
* image to which rectangles are to be drawn
@@ -156,6 +159,106 @@
}
/**
+ * Test basic behavior of method Graphics.drawPolyline(). Polyline are
+ * rendered with default width and default end caps. Color of all rendered
+ * polylines are selected from a palette.
+ *
+ * @param image
+ * image to which rectangles are to be drawn
+ * @param graphics2d
+ * graphics canvas
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testDrawPolylinesColorPalette(TestImage image, Graphics2D graphics2d)
+ {
+ drawPolylines(image, graphics2d, POLYLINE_STEP, new PolylineDrawCallbacks()
+ {
+ /**
+ * Callback function called before each polyline is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x1, int y1, int x2, int y2, int index)
+ {
+ // set polyline color
+ this.graphics.setColor(ColorPalette.getColor(index));
+ return;
+ }
+ });
+
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test basic behavior of method Graphics.drawPolyline(). Polyline are
+ * rendered with default width and default end caps. Color of all rendered
+ * polylines are selected from a grayscale palette.
+ *
+ * @param image
+ * image to which rectangles are to be drawn
+ * @param graphics2d
+ * graphics canvas
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testDrawPolylinesGrayScale(TestImage image, Graphics2D graphics2d)
+ {
+ drawPolylines(image, graphics2d, POLYLINE_STEP, new PolylineDrawCallbacks()
+ {
+ /**
+ * Callback function called before each polyline is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x1, int y1, int x2, int y2, int index)
+ {
+ // compute grayscale value
+ float gray = (y1 - BORDER) * 4.0f / this.image.getHeight();
+ // set polyline color
+ this.graphics.setColor(GrayscalePalette.createGrayscaleColor(gray));
+ }
+ });
+
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
+ * Test basic behavior of method Graphics.drawPolyline(). Polyline are
+ * rendered with default width and default end caps. Color of all rendered
+ * polylines are selected from a grayscale palette.
+ *
+ * @param image
+ * image to which rectangles are to be drawn
+ * @param graphics2d
+ * graphics canvas
+ * @return test result status - PASSED, FAILED or ERROR
+ */
+ public TestResult testDrawPolylinesChangeWidth(TestImage image, Graphics2D graphics2d)
+ {
+ drawPolylines(image, graphics2d, POLYLINE_STEP * 4 / 3, new PolylineDrawCallbacks()
+ {
+ /**
+ * Stroke width.
+ */
+ float strokeWidth = 0.0f;
+
+ /**
+ * Callback function called before each polyline is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x1, int y1, int x2, int y2, int index)
+ {
+ // set stroke width
+ this.graphics.setStroke(new BasicStroke(this.strokeWidth));
+ // set new stroke width
+ this.strokeWidth = this.strokeWidth < MAX_STROKE_WIDTH ? this.strokeWidth + STROKE_WIDTH_DELTA : this.strokeWidth;
+ }
+ });
+
+ // test return value
+ return TestResult.PASSED;
+ }
+
+ /**
* Entry point to the test suite.
*
* @param args
More information about the distro-pkg-dev
mailing list