This page describes the visual testing facility found in the test/java/org/apache/fop/visual directory:

The idea

There are several ways to test FOP's output. We have an approach which compares generated files against a set of reference files by checking the hash values of the files. These hashes may change simply due to a different timestamp in the metadata of the output file or after a tiny change in the sources which doesn't change the output. That makes the approach quite shaky and unattractive.

The layout engine tests are ideal to test the layout engine itself, but not the individual renderers. So even though the layout engine does the right thing, a renderer may still paint an element in the wrong place or not at all.

The middle way between the two approaches is to visually check and compare bitmaps generated from the output files created through FOP. Output from the Java2D renderer can be converted to bitmaps directly through our bitmap renderer. Output from PDF and PS can also be converted to bitmaps using external converters such as GhostScript.

What you (will) get

The application

Just run the org.apache.fop.visual.BatchDiffer class with a configuration file as sole parameter to the application.

The configuration

For simplicity, the configuration is done using an XML file and with the help of the Avalon Framework's configuration package. Here's a sample configuration file:

<?xml version="1.0" encoding="UTF-8"?>
    <producer classname="org.apache.fop.visual.BitmapProducerPDF">
      <converter>C:\Dev\GhostScript\gs8.50\bin\gswin32c -sDEVICE=pngalpha -dNOPAUSE -dBATCH -dSAFER -r{2} -dFirstPage=1 -dLastPage=1 -sOutputFile="{1}" "{0}"</converter>
    <producer classname="org.apache.fop.visual.BitmapProducerPS">
      <converter>C:\Dev\GhostScript\gs8.50\bin\gswin32c -sDEVICE=pngalpha -dNOPAUSE -dBATCH -dSAFER -r{2} -dFirstPage=1 -dLastPage=1 -sOutputFile="{1}" "{0}"</converter>
    <producer classname="org.apache.fop.visual.BitmapProducerJava2D">
    <!--producer classname="org.apache.fop.visual.ReferenceBitmapLoader">

The details on the configuration values can be found in the javadocs of BatchDiffer and the BitmapProducer implementations.

The above sample file shows how to use an external GhostScript to convert PDF and PS to bitmaps. But you can also use any other external converter that does the job. For licensing reasons, the code is designed not to have any direct reference to GhostScript or any other external converter. You simply have to provide the right command-line to call your own converter.

Additional ideas

VisualTestingFacility (last edited 2009-09-20 23:52:12 by localhost)