Mercurial > hg > gfx-test
changeset 0:73045f8d6b30
Initial import of gfxtests.
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="build"/> +</classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>gfxtests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,38 @@ +Java gfx-test framework + + Copyright (C) 2010 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. +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,72 @@ +SOURCEPATH=src +CLASSES=build +OUTPUT=output +FRAMEWORK_DIR=org/gfxtest/framework +TESTSUITE_DIR=org/gfxtest/testsuites +TEST_PACKAGE=org.gfxtest.testsuites +RUN_OPTIONS=-w=640 -h=480 -t=rgb -o=$(OUTPUT) +#JAVA=/usr/java/default/bin/java +JAVA=java +JAVAC=javac + +FRAMEWORK_CLASSES = \ + $(CLASSES)/$(FRAMEWORK_DIR)/TestResult.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/ConfigurationException.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/InvalidParameterValueException.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/ParameterNotFoundException.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/Configuration.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/TestImage.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/GfxTest.class \ + $(CLASSES)/$(FRAMEWORK_DIR)/Log.class + +TESTSUITE_CLASSES = \ + $(CLASSES)/$(TESTSUITE_DIR)/BlankImage.class \ + $(CLASSES)/$(TESTSUITE_DIR)/ScaledLines.class \ + $(CLASSES)/$(TESTSUITE_DIR)/DashedLines.class \ + $(CLASSES)/$(TESTSUITE_DIR)/ScaledPolylines.class \ + $(CLASSES)/$(TESTSUITE_DIR)/DashedPolylines.class \ + $(CLASSES)/$(TESTSUITE_DIR)/ScaledRectangles.class \ + $(CLASSES)/$(TESTSUITE_DIR)/DashedRectangles.class + +# targets for all test suites +TESTSUITES = $(shell ls -1 src/org/gfxtest/testsuites | sed -n -e 's/\([A-Za-z0-9]*\)\.java/\1/p') + +all: build runtests compareresults + +build: gfxtest.jar + +test_framework: $(FRAMEWORK_CLASSES) + +test_suites: $(TESTSUITE_CLASSES) + +$(CLASSES)/$(FRAMEWORK_DIR)/%.class: $(SOURCEPATH)/$(FRAMEWORK_DIR)/%.java + $(JAVAC) -d $(CLASSES) -sourcepath src/ $< + +$(CLASSES)/$(TESTSUITE_DIR)/%.class: $(SOURCEPATH)/$(TESTSUITE_DIR)/%.java + $(JAVAC) -d $(CLASSES) -sourcepath src/ $< + +gfxtest.jar: $(FRAMEWORK_CLASSES) $(TESTSUITE_CLASSES) + jar cvf gfxtest.jar -C $(CLASSES) . + +runtests: gfxtest.jar $(TESTSUITES) + +# multiple targets - one for each test suite +$(TESTSUITES): gfxtest.jar + mkdir -p $(OUTPUT) + $(JAVA) -cp gfxtest.jar $(TEST_PACKAGE).$@ $(RUN_OPTIONS) + +compareresults: + echo "***TODO***" + +cleanall: clean clean-results + +clean-all: cleanall + +clean: + rm -rf $(CLASSES) + rm -f gfxtest.jar + mkdir -p $(CLASSES) + +clean-results: + rm -rf $(OUTPUT) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/Configuration.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,161 @@ +package org.gfxtest.framework; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +/** + * This class is used to store actual configuration of graphics test framework. + * Configuration can be changed via command line switches. + * + * @author Pavel Tisnovsky + */ +public class Configuration +{ + /** + * Instance of logger class. + */ + private Log log; + + /** + * Path to generated output files. + */ + private File outputPath; + + /** + * Width (measured in pixels) of the generated images. + */ + private int imageWidth; + + /** + * Height (measured in pixels) of the generated images. + */ + private int imageHeight; + + /** + * Image type. Currently are supported these image types: + * BufferedImage.TYPE_INT_RGB, BufferedImage.TYPE_BYTE_GRAY and + * BufferedImage.TYPE_BYTE_INDEXED. + */ + private int imageType; + + public Configuration(String[] args, Log log) throws ConfigurationException + { + this.log = log; + log.logBegin("read configuration"); + readCommandLineParameters(args); + log.logEnd("read configuration"); + printParameters(); + } + + private void readCommandLineParameters(String[] args) throws ConfigurationException + { + Map<String, String> options = resolveAllOptions(args); + this.imageWidth = getIntegerParameter(options, "w"); + this.imageHeight = getIntegerParameter(options, "h"); + this.imageType = getImageType(options); + this.outputPath = new File(getStringParameter(options, "o")); + } + + 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)) + { + return BufferedImage.TYPE_INT_RGB; + } + else if ("gray".equals(imageType)) + { + return BufferedImage.TYPE_BYTE_GRAY; + } + else if ("bw".equals(imageType) || ("bit".equals(imageType))) + { + return BufferedImage.TYPE_BYTE_INDEXED; + } + else + { + throw new InvalidParameterValueException("t", imageType); + } + } + + private int getIntegerParameter(Map<String, String> options, String parameterName) throws ConfigurationException + { + if (!options.containsKey(parameterName)) + { + throw new ParameterNotFoundException(parameterName); + } + String parameterValue = options.get(parameterName); + try + { + return Integer.parseInt(parameterValue); + } + catch (NumberFormatException e) + { + throw new InvalidParameterValueException(parameterName, parameterValue); + } + } + + private String getStringParameter(Map<String, String> options, String parameterName) throws ConfigurationException + { + if (!options.containsKey(parameterName)) + { + throw new ParameterNotFoundException(parameterName); + } + return options.get(parameterName); + } + + private Map<String, String> resolveAllOptions(String[] args) + { + Map<String, String> options = new HashMap<String, String>(); + for (String arg : args) + { + String[] splittedArg = arg.split("="); + if (splittedArg.length >= 1 && splittedArg[0].length() >= 2) + { + 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); + } + } + return options; + } + + 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); + } + + public File getOutputPath() + { + return outputPath; + } + + public int getImageWidth() + { + return imageWidth; + } + + public int getImageHeight() + { + return imageHeight; + } + + public int getImageType() + { + return imageType; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/ConfigurationException.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,18 @@ +package org.gfxtest.framework; + +/** + * + * @author Pavel Tisnovsky + */ +public abstract class ConfigurationException extends Exception +{ + /** + * Generated serial version ID + */ + private static final long serialVersionUID = -2168810923554713703L; + + public ConfigurationException(String message) + { + super(message); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/GfxTest.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,166 @@ +package org.gfxtest.framework; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public abstract class GfxTest +{ + protected Log log = null; + protected String suiteName = null; + protected static final int CROSS_SIZE = 20; + + /** + * Write test suite duration to the log file. + * + * @param t1 time when the test suite has been started + * @param t2 time when the test suite was completed + */ + private void printDuration(long t1, long t2) + { + log.logSet("duration", (t2-t1)); + } + + /** + * Construct test suite name using full class name. + */ + private void fillSuiteName() + { + String className = this.getClass().getName(); + this.suiteName = className.substring(1 + className.lastIndexOf('.')); + } + + protected void runTestSuite(String[] args) + { + long t1 = System.currentTimeMillis(); + log = new Log(this.getClass().getName(), true); + log.logBegin("testsuite"); + fillSuiteName(); + Configuration configuration; + try + { + configuration = new Configuration(args, log); + runAllTests(configuration); + } + catch (ConfigurationException e) + { + e.printStackTrace(); + } + finally + { + long t2 = System.currentTimeMillis(); + log.logEnd("testsuite"); + printDuration(t1, t2); + } + } + + /** + * Invoke all methods which names start with "test" prefix. These methods + * should accept one parameter of type Buffered image. + * + * @param configuration + * @throws IOException + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws InvocationTargetException + */ + private void runAllTests(Configuration configuration) + { + log.logBegin("common tests"); + Method[] methods = getClass().getDeclaredMethods(); + for (Method method : methods) + { + tryToInvokeTestMethod(configuration, method); + } + log.logEnd("common tests"); + log.logBegin("other tests"); + runOtherTests(configuration); + log.logEnd("other tests"); + } + + /** + * Method which can be overridden by inherited classes. + * + * @param configuration configuration of current test case. + */ + protected void runOtherTests(Configuration configuration) + { + } + + private void tryToInvokeTestMethod(Configuration configuration, Method method) + { + String methodName = method.getName(); + if (method.getName().startsWith("test")) + { + log.logBegin(methodName); + TestImage image = new TestImage(configuration); + Graphics2D gc = (Graphics2D) image.getGraphics(); + TestResult result = null; + try + { + result = (TestResult) method.invoke(this, new Object[] { image, gc }); + } + catch (Exception e) + { + e.printStackTrace(); + result = TestResult.ERROR; + } + finally + { + gc.dispose(); + logTestResult(result); + try + { + image.writeImage(configuration, suiteName, methodName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(methodName); + } + } + } + + /** + * Write test result to log file. + * + * @param result status of the last invoked test + */ + protected void logTestResult(TestResult result) + { + String resultText = ""; + switch (result) + { + case PASSED: + resultText = "$GREEN$PASSED"; + break; + case FAILED: + resultText = "$RED$FAILED"; + break; + case ERROR: + resultText = "$BLUE$ERROR"; + break; + } + log.logSet("test result", resultText); + } + + /** + * + * @param graphics graphics context for the image created by test case + * @param x x-coordinate of the cross center + * @param y y-coordinate of the cross center + * @param size size of cross (measured in pixels) + */ + protected void drawCross(Graphics2D graphics, int x, int y, int size) + { + graphics.setStroke(new BasicStroke(1.0f)); + graphics.setColor(Color.RED); + graphics.drawLine(x, y - size, x, y + size); + graphics.drawLine(x - size, y, x + size, y); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/InvalidParameterValueException.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,19 @@ +package org.gfxtest.framework; + +/** + * + * @author Pavel Tisnovsky + */ +public class InvalidParameterValueException extends ConfigurationException +{ + /** + * Genereated serial version ID. + */ + private static final long serialVersionUID = 3027080845460577282L; + + public InvalidParameterValueException(String parameterName, String value) + { + super("invalid value of parameter " + parameterName + ": " + value); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/Log.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,170 @@ +package org.gfxtest.framework; + +import java.util.Date; +import java.util.HashMap; + +/** + * Simple logger that writes everything out to standard output and can use color + * codes for ANSI-compatible terminals. + * + * @author Pavel Tisnovsky + */ +public class Log +{ + static HashMap<String, String> colors = new HashMap<String, String>(10); + + static + { + colors.put("RED", "31"); + colors.put("GREEN", "32"); + colors.put("ORANGE", "33"); + colors.put("BLUE", "34"); + colors.put("VIOLET", "35"); + colors.put("MAGENTA", "35"); + colors.put("LIGHT_BLUE", "36"); + colors.put("GRAY", "38"); + colors.put("GREY", "38"); + } + + /** + * Current indentation level. Increased in logBegin() and decreased in + * logEnd() methods. + */ + private int indent = 0; + + /** + * Indentation level rate. + */ + private int indentDelta = 2; + + /** + * Name of class containing Log instance. + */ + private String className = null; + + /** + * Whether to use colorified output. Useful when logging to terminal, less + * useful when log is redirected to a file. + */ + private boolean useColors; + + /** + * Constructor. + * + * @param className name of class containing Log instance. + * @param useColors whether to use colorified output. + */ + public Log(String className, boolean useColors) + { + this.className = className; + this.useColors = useColors; + } + + public void log(String str) + { + this.log(this.className, str); + } + + public void log(String className, String str) + { + StringBuffer spaces = new StringBuffer(); + for (int i = 0; i < this.indent; i++) + { + spaces.append(' '); + } + + StringBuffer output = new StringBuffer(); + if (useColors) + { + str = "$GREEN$GfxTest $LIGHT_BLUE$" + this.getDate() + " $ORANGE$" + String.format("%-40s", className) + + spaces + " $GRAY$" + str; + } + else + { + str = "GfxTest " + this.getDate() + " " + String.format("%-40s", className) + spaces + " " + str; + } + + String[] pieces = str.split("\\$"); + + for (String piece : pieces) + { + if (colors.containsKey(piece.toUpperCase())) + { + if (useColors) + { + output.append("\033[0;" + colors.get(piece.toUpperCase()) + "m"); + } + } + else + { + output.append(piece); + } + } + // vypis vytvoreneho retezce na standardni vystup + if (useColors) + { + System.out.println(output.append("\033[0m")); + } + else + { + System.out.println(output); + } + } + + public void logSet(String str, Object o) + { + String value = o == null ? "$RED$null" : "$GRAY$" + o.toString(); + this.log("$LIGHT_BLUE$" + str + "$ORANGE$ = " + value); + } + + public void logBegin(String className, String str) + { + this.log(className, str + " $GREEN$begin"); + this.indent += this.indentDelta; + } + + public void logBegin(String str) + { + this.logBegin(this.className, str); + } + + public void logEnd(String className, String str) + { + if (this.indent >= this.indentDelta) + { + this.indent -= this.indentDelta; + } + this.log(className, str + " $VIOLET$end"); + } + + public void logEnd(String str) + { + this.logEnd(this.className, str); + } + + public void logError(String str) + { + this.logError(this.className, str); + } + + public void logError(String className, String str) + { + this.log(className, "$RED$error $GRAY$" + str); + } + + public static void main(String[] args) + { + System.out.println("test start"); + System.out.println("test end"); + } + + @SuppressWarnings("deprecation") + private String getDate() + { + // vytvorime pomocny buffer, do ktereho seskladame retezec + Date date = new Date(); + return String.format("%04d-%02d-%02d %02d:%02d:%02d", 1900 + date.getYear(), date.getMonth(), date.getDay(), + date.getHours(), date.getMinutes(), date.getSeconds()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/ParameterNotFoundException.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,19 @@ +package org.gfxtest.framework; + +/** + * + * @author Pavel Tisnovsky + */ +public class ParameterNotFoundException extends ConfigurationException +{ + /** + * Generated serial version ID. + */ + private static final long serialVersionUID = 7620739193719604017L; + + public ParameterNotFoundException(String parameterName) + { + super("parameter " + parameterName + " not found"); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/TestImage.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,108 @@ +package org.gfxtest.framework; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public class TestImage +{ + private Log log = null; + private static final int GRID_SIZE = 20; + private BufferedImage image = null; + + public TestImage(Configuration configuration) + { + log = new Log(this.getClass().getName(), true); + this.createImage(configuration); + } + + /** + * Create new buffered image with given width, height and image type. + * @param configuration configuration of current test suite + * @return + */ + public void createImage(Configuration configuration) + { + this.image = new BufferedImage(configuration.getImageWidth(), configuration.getImageHeight(), configuration.getImageType()); + this.clearImage(); + this.drawGrid(); + } + + protected void clearImage() + { + fillImage(Color.WHITE); + } + + public void fillImage(Color color) + { + Graphics2D graphics = this.image.createGraphics(); + graphics.setColor(color); + graphics.fillRect(0, 0, this.image.getWidth(), this.image.getHeight()); + graphics.dispose(); + } + + protected BufferedImage readImage(File directory, String fileName) throws IOException + { + log.log("reading image " + fileName + " from directory " + directory); + File imageFile = new File(directory, fileName); + return ImageIO.read(imageFile); + } + + private void writeImage(File directory, String fileName) throws IOException + { + log.log("writing image " + fileName + " into directory " + directory); + ImageIO.write(this.image, "png", new File(directory, fileName)); + } + + /** + * Write given buffered image to PNG file. + * + * @param image + * @param configuration + * @param testName + * @throws IOException + */ + public void writeImage(Configuration configuration, String suiteName, String testName) throws IOException + { + this.writeImage(configuration.getOutputPath(), suiteName + "_" + testName + ".png"); + } + + /** + * This method draws grid below the test (rendered) pattern. + * @param image reference to the image created by test case + */ + private void drawGrid() + { + Graphics2D graphics = this.image.createGraphics(); + graphics.setColor(new Color(0xa0, 0xa0, 0xff)); + for (int x = 0; x < image.getWidth(); x += GRID_SIZE) + { + graphics.drawLine(x, 0, x, image.getHeight() - 1); + } + for (int y = 0; y < image.getHeight(); y += GRID_SIZE) + { + graphics.drawLine(0, y, image.getWidth() - 1, y); + } + graphics.dispose(); + } + + public Graphics2D getGraphics() + { + return (Graphics2D) this.image.getGraphics(); + } + + public int getWidth() + { + return this.image.getWidth(); + } + + public int getHeight() + { + return this.image.getHeight(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/framework/TestResult.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,12 @@ +package org.gfxtest.framework; + +/** + * + * @author Pavel Tisnovsky + */ +public enum TestResult +{ + PASSED, + FAILED, + ERROR +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/BlankImage.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,55 @@ +package org.gfxtest.testsuites; + +import java.awt.*; + +import org.gfxtest.framework.*; + +public class BlankImage extends GfxTest +{ + + public TestResult test0(TestImage image, Graphics2D graphics) + { + return TestResult.PASSED; + } + + public TestResult test1(TestImage image, Graphics2D graphics) + { + image.fillImage(Color.BLACK); + return TestResult.PASSED; + } + + public TestResult test2(TestImage image, Graphics2D graphics) + { + image.fillImage(Color.RED); + return TestResult.PASSED; + } + + public TestResult test3(TestImage image, Graphics2D graphics) + { + image.fillImage(Color.GREEN); + return TestResult.PASSED; + } + + public TestResult test4(TestImage image, Graphics2D graphics) + { + image.fillImage(Color.BLUE); + return TestResult.PASSED; + } + + public TestResult test5(TestImage image, Graphics2D graphics) + { + image.fillImage(new Color(0x7f, 0x7f, 0x00)); + return TestResult.PASSED; + } + + public TestResult test6(TestImage image, Graphics2D graphics) + { + image.fillImage(new Color(0.5f, 0.0f, 1.0f)); + return TestResult.PASSED; + } + + public static void main(String[] args) + { + new BlankImage().runTestSuite(args); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/DashedLines.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,71 @@ +package org.gfxtest.testsuites; + +import java.awt.*; +import java.awt.geom.*; +import java.io.IOException; + +import org.gfxtest.framework.*; + +public class DashedLines extends GfxTest +{ + private static final float DEFAULT_SCALE = 20.0f; + private static final int OFFSET = 80; + + private void drawDashedLine(TestImage image, Graphics2D graphics, float scale, int cap, float[] dash) + { + graphics.setColor(Color.BLACK); + graphics.setStroke(new BasicStroke(1, // width + cap, // cap + BasicStroke.JOIN_ROUND, // join + 1.0f, + dash, // dash + 0.0f)); // dash phase + graphics.scale(scale, scale); + int x1 = (int) (OFFSET / scale); + int y1 = (int) (OFFSET / scale); + int x2 = (int) ((image.getWidth() - OFFSET) / scale); + int y2 = (int) ((image.getHeight() - OFFSET) / scale); + graphics.drawLine(x1, y1, x2, y2); + + graphics.setTransform(new AffineTransform()); + drawCross(graphics, OFFSET, OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() - OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + } + + protected void runOtherTests(Configuration configuration) + { + int[] caps = { BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND }; + int testNumber = 0; + for (int cap : caps) + { + for (float dash1 = 0.25f; dash1 <= 4.0; dash1 *= 2) + { + for (float dash2 = 0.25f; dash2 <= 4.0; dash2 *= 2) + { + String testName = "test" + testNumber; + log.logBegin(testName); + TestImage image = new TestImage(configuration); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + drawDashedLine(image, graphics, DEFAULT_SCALE, cap, new float[] + { dash1, dash2 }); + graphics.dispose(); + try + { + image.writeImage(configuration, suiteName, testName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(testName); + testNumber++; + } + } + } + } + + public static void main(String[] args) + { + new DashedLines().runTestSuite(args); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/DashedPolylines.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,85 @@ +package org.gfxtest.testsuites; + +import java.awt.*; +import java.awt.geom.*; +import java.io.IOException; + +import org.gfxtest.framework.*; + +public class DashedPolylines extends GfxTest +{ + private static final int OFFSET = 80; + private static final float DEFAULT_SCALE = 20.0f; + + private void drawDashedPolyline(TestImage image, Graphics2D graphics, float scale, int cap, int join, float[] dash) + { + graphics.setColor(Color.BLACK); + graphics.setStroke(new BasicStroke(1, // width + cap, // cap + join, // join + 1.0f, + dash, + 0.0f)); + graphics.scale(scale, scale); + int x1 = (int) (OFFSET / scale); + int y1 = (int) ((image.getHeight() - OFFSET) / scale); + int x2 = (int) ((image.getWidth() / 2) / scale); + int y2 = (int) (OFFSET / scale); + int x3 = (int) ((image.getWidth() - OFFSET) / scale); + int y3 = y1; + + GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); + polyline.moveTo(x1, y1); + polyline.lineTo(x2, y2); + polyline.lineTo(x3, y3); + graphics.draw(polyline); + + graphics.setTransform(new AffineTransform()); + drawCross(graphics, OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() / 2, OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() - OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + } + + protected void runOtherTests(Configuration configuration) + { + int[] caps = { BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND }; + int[] joins = { BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, BasicStroke.CAP_ROUND }; + int testNumber = 0; + for (int join : joins) + { + for (int cap : caps) + { + for (float dash1 = 0.25f; dash1 <= 4.0; dash1 *= 2.0) + { + for (float dash2 = 0.25f; dash2 <= 4.0; dash2 *= 2.0) + { + String testName = "test" + testNumber; + log.logBegin(testName); + TestImage image = new TestImage(configuration); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + drawDashedPolyline(image, graphics, DEFAULT_SCALE, cap, join, new float[] + { dash1, dash2 }); + graphics.dispose(); + try + { + image.writeImage(configuration, suiteName, testName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(testName); + testNumber++; + } + } + } + } + } + + public static void main(String[] args) + { + new DashedPolylines().runTestSuite(args); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/DashedRectangles.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,75 @@ +package org.gfxtest.testsuites; + +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.io.IOException; + +import org.gfxtest.framework.*; + +public class DashedRectangles extends GfxTest +{ + private static final float DEFAULT_SCALE = 20.0f; + private static final int OFFSET = 80; + + private void drawRectangle(TestImage image, Graphics2D graphics, float scale, int cap, int join, float[] dash) + { + graphics.setColor(Color.BLACK); + graphics.setStroke(new BasicStroke(1, // width + cap, // cap + join, // join + 1.0f, + dash, // dash + 0.0f)); // dash phase + graphics.scale(scale, scale); + int x1 = (int) (OFFSET / scale); + int y1 = (int) (OFFSET / scale); + int x2 = (int) ((image.getWidth() - OFFSET) / scale); + int y2 = (int) ((image.getHeight() - OFFSET) / scale); + graphics.drawRect(x1, y1, x2 - x1, y2 - y1); + + graphics.setTransform(new AffineTransform()); + drawCross(graphics, OFFSET, OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() - OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + } + + protected void runOtherTests(Configuration configuration) + { + int[] caps = { BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND }; + int[] joins = { BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, BasicStroke.CAP_ROUND }; + int testNumber = 0; + for (int join : joins) + { + for (int cap : caps) + { + for (float dash1 = 0.25f; dash1 <= 4.0; dash1 *= 2.0) + { + for (float dash2 = 0.25f; dash2 <= 4.0; dash2 *= 2.0) + { + String testName = "test" + testNumber; + log.logBegin(testName); + TestImage image = new TestImage(configuration); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + drawRectangle(image, graphics, DEFAULT_SCALE, cap, join, new float[] + { dash1, dash2 }); + graphics.dispose(); + try + { + image.writeImage(configuration, suiteName, testName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(testName); + testNumber++; + } + } + } + } + } + + public static void main(String[] args) + { + new DashedRectangles().runTestSuite(args); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/ScaledLines.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,64 @@ +package org.gfxtest.testsuites; + +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.io.IOException; + +import org.gfxtest.framework.*; + +public class ScaledLines extends GfxTest +{ + private static final int OFFSET = 80; + + private void drawScaledLine(TestImage image, Graphics2D graphics, float scale, int cap) + { + graphics.setColor(Color.BLACK); + graphics.setStroke(new BasicStroke(1, // width + cap, // cap + BasicStroke.JOIN_ROUND)); // join + graphics.scale(scale, scale); + int x1 = (int) (OFFSET / scale); + int y1 = (int) (OFFSET / scale); + int x2 = (int) ((image.getWidth() - OFFSET) / scale); + int y2 = (int) ((image.getHeight() - OFFSET) / scale); + graphics.drawLine(x1, y1, x2, y2); + + graphics.setTransform(new AffineTransform()); + drawCross(graphics, OFFSET, OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() - OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + } + + protected void runOtherTests(Configuration configuration) + { + float[] scales = { 1.0f, 10.0f, 20.0f, 40.0f, 80.0f }; + int[] caps = { BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND }; + int testNumber = 0; + for (int cap : caps) + { + for (float scale : scales) + { + String testName = "test" + testNumber; + log.logBegin(testName); + TestImage image = new TestImage(configuration); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + drawScaledLine(image, graphics, scale, cap); + graphics.dispose(); + try + { + image.writeImage(configuration, suiteName, testName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(testName); + testNumber++; + } + } + } + + public static void main(String[] args) + { + new ScaledLines().runTestSuite(args); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/ScaledPolylines.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,77 @@ +package org.gfxtest.testsuites; + +import java.awt.*; +import java.awt.geom.*; +import java.io.IOException; + +import org.gfxtest.framework.*; + +public class ScaledPolylines extends GfxTest +{ + private static final int OFFSET = 80; + + private void drawScaledPolyline(TestImage image, Graphics2D graphics, float scale, int cap, int join) + { + graphics.setColor(Color.BLACK); + graphics.setStroke(new BasicStroke(1, // width + cap, // cap + join)); // join + graphics.scale(scale, scale); + int x1 = (int) (OFFSET / scale); + int y1 = (int) ((image.getHeight() - OFFSET) / scale); + int x2 = (int) ((image.getWidth() / 2) / scale); + int y2 = (int) (OFFSET / scale); + int x3 = (int) ((image.getWidth() - OFFSET) / scale); + int y3 = y1; + + GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); + polyline.moveTo(x1, y1); + polyline.lineTo(x2, y2); + polyline.lineTo(x3, y3); + graphics.draw(polyline); + + graphics.setTransform(new AffineTransform()); + drawCross(graphics, OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() / 2, OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() - OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + } + + protected void runOtherTests(Configuration configuration) + { + float[] scales = { 1.0f, 10.0f, 20.0f, 40.0f, 80.0f }; + int[] caps = { BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND }; + int[] joins = { BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, BasicStroke.CAP_ROUND }; + int testNumber = 0; + for (int join : joins) + { + for (int cap : caps) + { + for (float scale : scales) + { + String testName = "test" + testNumber; + log.logBegin(testName); + TestImage image = new TestImage(configuration); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + drawScaledPolyline(image, graphics, scale, cap, join); + graphics.dispose(); + try + { + image.writeImage(configuration, suiteName, testName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(testName); + testNumber++; + } + } + } + } + + public static void main(String[] args) + { + new ScaledPolylines().runTestSuite(args); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/gfxtest/testsuites/ScaledRectangles.java Thu Jul 08 12:35:51 2010 +0000 @@ -0,0 +1,66 @@ +package org.gfxtest.testsuites; + +import java.awt.*; +import java.awt.geom.*; +import java.io.IOException; + +import org.gfxtest.framework.*; + +public class ScaledRectangles extends GfxTest +{ + private static final int OFFSET = 80; + + private void drawScaledRectangle(TestImage image, Graphics2D graphics, float scale, int cap, int join) + { + graphics.setColor(Color.BLACK); + graphics.setStroke(new BasicStroke(1, // width + cap, // cap + join)); // join + graphics.scale(scale, scale); + int x1 = (int) (OFFSET / scale); + int y1 = (int) (OFFSET / scale); + int x2 = (int) ((image.getWidth() - OFFSET) / scale); + int y2 = (int) ((image.getHeight() - OFFSET) / scale); + + graphics.drawRect(x1, y1, x2 - x1, y2 - y1); + + graphics.setTransform(new AffineTransform()); + drawCross(graphics, OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() / 2, OFFSET, CROSS_SIZE); + drawCross(graphics, image.getWidth() - OFFSET, image.getHeight() - OFFSET, CROSS_SIZE); + } + + protected void runOtherTests(Configuration configuration) + { + float[] scales = { 1.0f, 10.0f, 20.0f, 40.0f, 80.0f }; + int[] joins = { BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, BasicStroke.CAP_ROUND }; + int testNumber = 0; + for (int join : joins) + { + for (float scale : scales) + { + String testName = "test" + testNumber; + log.logBegin(testName); + TestImage image = new TestImage(configuration); + Graphics2D graphics = (Graphics2D) image.getGraphics(); + drawScaledRectangle(image, graphics, scale, BasicStroke.CAP_BUTT, join); + graphics.dispose(); + try + { + image.writeImage(configuration, suiteName, testName); + } + catch (IOException e) + { + e.printStackTrace(); + } + log.logEnd(testName); + testNumber++; + } + } + } + + public static void main(String[] args) + { + new ScaledRectangles().runTestSuite(args); + } +}