/hg/gfx-test: 2012-04-13 Pavel Tisnovsky <ptisnovs at redhat.com>

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Fri Apr 13 05:12:41 PDT 2012


changeset cba2ae48526e in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=cba2ae48526e
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri Apr 13 14:15:12 2012 +0200

	2012-04-13  Pavel Tisnovsky  <ptisnovs at redhat.com>

		* src/org/gfxtest/framework/GfxTest.java:
		* src/org/gfxtest/framework/PrintingTest.java:
		* src/org/gfxtest/framework/TestImage.java:
		Added basic support for printing tests.
		* Makefile: Updated


diffstat:

 ChangeLog                                   |    8 +
 Makefile                                    |    1 +
 src/org/gfxtest/framework/GfxTest.java      |   54 +++++++++-
 src/org/gfxtest/framework/PrintingTest.java |  155 ++++++++++++++++++++++++++++
 src/org/gfxtest/framework/TestImage.java    |   41 +++++++
 5 files changed, 257 insertions(+), 2 deletions(-)

diffs (331 lines):

diff -r 4a4eb075c03f -r cba2ae48526e ChangeLog
--- a/ChangeLog	Thu Apr 12 14:59:12 2012 +0200
+++ b/ChangeLog	Fri Apr 13 14:15:12 2012 +0200
@@ -1,3 +1,11 @@
+2012-04-13  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/gfxtest/framework/GfxTest.java:
+	* src/org/gfxtest/framework/PrintingTest.java:
+	* src/org/gfxtest/framework/TestImage.java:
+	Added basic support for printing tests.
+	* Makefile: Updated
+
 2012-04-12  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/gfxtest/ImageDiffer/Main.java:
diff -r 4a4eb075c03f -r cba2ae48526e Makefile
--- a/Makefile	Thu Apr 12 14:59:12 2012 +0200
+++ b/Makefile	Fri Apr 13 14:15:12 2012 +0200
@@ -88,6 +88,7 @@
 	$(CLASSES)/$(FRAMEWORK_DIR)/GfxTestConfiguration.class \
 	$(CLASSES)/$(FRAMEWORK_DIR)/TestImage.class \
 	$(CLASSES)/$(FRAMEWORK_DIR)/GfxTest.class \
+	$(CLASSES)/$(FRAMEWORK_DIR)/PrintingTest.class \
 	$(CLASSES)/$(FRAMEWORK_DIR)/Log.class \
 	$(CLASSES)/$(FRAMEWORK_DIR)/ProceduralTextureFactory.class \
 	$(CLASSES)/$(FRAMEWORK_DIR)/ImageFactory.class \
diff -r 4a4eb075c03f -r cba2ae48526e src/org/gfxtest/framework/GfxTest.java
--- a/src/org/gfxtest/framework/GfxTest.java	Thu Apr 12 14:59:12 2012 +0200
+++ b/src/org/gfxtest/framework/GfxTest.java	Fri Apr 13 14:15:12 2012 +0200
@@ -1,7 +1,7 @@
 /*
   Java gfx-test framework
 
-   Copyright (C) 2010, 2011  Red Hat
+   Copyright (C) 2010, 2011, 2012  Red Hat
 
 This file is part of IcedTea.
 
@@ -43,10 +43,25 @@
 import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Graphics2D;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
+
+
+import javax.print.DocFlavor;
+import javax.print.StreamPrintService;
+import javax.print.StreamPrintServiceFactory;
+import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.MediaSizeName;
+
 import org.gfxtest.common.ConfigurationException;
 import org.gfxtest.framework.annotations.TestType;
 import org.gfxtest.framework.annotations.Zoom;
@@ -442,6 +457,8 @@
     }
 
     /**
+     * Run test configured to use bitmap as its output.
+     *
      * @param configuration
      * @param method
      * @param methodName
@@ -478,13 +495,46 @@
     }
 
     /**
+     * Run test configured to use printer as its output.
+     *
      * @param configuration
      * @param method
      * @param methodName
      */
     private void tryToRunPrintTest(GfxTestConfiguration configuration, Method method, String methodName)
     {
-        // TODO
+        String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType(); // only this works!
+        File printOutputFile;
+        StreamPrintService streamPrintService;
+        StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(psMimeType);
+        if (factories.length == 0)
+        {
+            System.err.println("No factories found");
+        }
+        else
+        {
+            PrinterJob printerJob = PrinterJob.getPrinterJob();
+            try
+            {
+                printOutputFile = new File(this.suiteName + "_" + methodName + ".ps");
+                streamPrintService = factories[0].getPrintService(new FileOutputStream(printOutputFile));
+                // streamPrintService can now be set as the service on a PrinterJob
+                printerJob.setPrintService(streamPrintService);
+                PrintRequestAttributeSet printAttributeSet = new HashPrintRequestAttributeSet();
+                printAttributeSet.add(MediaSizeName.ISO_A4);
+                printAttributeSet.add(new Copies(1));
+                printerJob.setPrintable(new PrintingTest(this, method));
+                printerJob.print(printAttributeSet);
+            }
+            catch (FileNotFoundException e)
+            {
+                e.printStackTrace();
+            }
+            catch (PrinterException e)
+            {
+                e.printStackTrace();
+            }
+        }
     }
 
     private void writeZoomedImage(GfxTestConfiguration configuration, TestImage sourceImage, String methodName, int zoom) throws IOException
diff -r 4a4eb075c03f -r cba2ae48526e src/org/gfxtest/framework/PrintingTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/framework/PrintingTest.java	Fri Apr 13 14:15:12 2012 +0200
@@ -0,0 +1,155 @@
+/*
+  Java gfx-test framework
+
+   Copyright (C) 2010, 2011, 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.framework;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class PrintingTest implements Printable
+{
+    private GfxTest gfxTest;
+    private Method method;
+    private TestResult result = null;
+
+    public PrintingTest(GfxTest gfxTest, Method method)
+    {
+        setGfxTest(gfxTest);
+        setMethod(method);
+    }
+
+    /**
+     * @return the method
+     */
+    public Method getMethod()
+    {
+        return this.method;
+    }
+
+    /**
+     * @param method the method to set
+     */
+    public void setMethod(Method method)
+    {
+        this.method = method;
+    }
+
+    /**
+     * @return the result
+     */
+    public TestResult getResult()
+    {
+        return this.result;
+    }
+
+    /**
+     * @param result the result to set
+     */
+    public void setResult(TestResult result)
+    {
+        this.result = result;
+    }
+
+    /**
+     * @return the gfxTest
+     */
+    public GfxTest getGfxTest()
+    {
+        return this.gfxTest;
+    }
+
+    /**
+     * @param gfxTest the gfxTest to set
+     */
+    public void setGfxTest(GfxTest gfxTest)
+    {
+        this.gfxTest = gfxTest;
+    }
+
+    @Override
+    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
+    {
+        if (pageIndex > 0) { /* We have only one page, and 'page' is zero-based */
+            return NO_SUCH_PAGE;
+        }
+ 
+        /* Origin (0,0) is typically outside the imageable area, so we must
+         * translate by the X and Y values in the PageFormat to avoid clipping
+         */
+        Graphics2D gc = (Graphics2D)graphics;
+        gc.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
+        TestImage image = new TestImage(pageFormat.getWidth(), pageFormat.getHeight());
+        try
+        {
+            setResult((TestResult) this.method.invoke(getGfxTest(), new Object[] { image, gc }));
+        }
+        catch (IllegalArgumentException e)
+        {
+            e.printStackTrace();
+            setResult(TestResult.ERROR);
+        }
+        catch (IllegalAccessException e)
+        {
+            e.printStackTrace();
+            setResult(TestResult.ERROR);
+        }
+        catch (InvocationTargetException e)
+        {
+            e.printStackTrace();
+            setResult(TestResult.ERROR);
+        }
+
+        /*
+        graphics.setColor(Color.RED);
+        graphics.drawLine(0, 0, (int)pageFormat.getWidth(), (int)pageFormat.getHeight());
+        graphics.drawLine((int)pageFormat.getWidth(), 0, 0, (int)pageFormat.getHeight());
+
+        graphics.drawString("Hello world!", 100, 100);
+        */
+        /* tell the caller that this page is part of the printed document */
+        return PAGE_EXISTS;
+    }
+
+}
diff -r 4a4eb075c03f -r cba2ae48526e src/org/gfxtest/framework/TestImage.java
--- a/src/org/gfxtest/framework/TestImage.java	Thu Apr 12 14:59:12 2012 +0200
+++ b/src/org/gfxtest/framework/TestImage.java	Fri Apr 13 14:15:12 2012 +0200
@@ -96,6 +96,47 @@
     }
 
     /**
+     * Initialization of TestImage object.
+     * 
+     * @param width
+     *            image width
+     * @param height
+     *            image height
+     */
+    public TestImage(int width, int height)
+    {
+        this.log = new Log(this.getClass().getName(), false);
+        this.createImage(width, height);
+    }
+
+    /**
+     * Initialization of TestImage object.
+     * 
+     * @param width
+     *            image width
+     * @param height
+     *            image height
+     */
+    public TestImage(double width, double height)
+    {
+        this.log = new Log(this.getClass().getName(), false);
+        this.createImage((int)width, (int)height);
+    }
+
+    /**
+     * Create new buffered image with given width and height.
+     * 
+     * @param width
+     *            image width
+     * @param height
+     *            image height
+     */
+    public void createImage(int width, int height)
+    {
+        this.image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+    }
+
+    /**
      * Create new buffered image with given width, height and image type.
      * 
      * @param configuration



More information about the distro-pkg-dev mailing list