Class AbstractRenderingAccuracyTest

java.lang.Object
org.apache.batik.test.AbstractTest
org.apache.batik.test.svg.AbstractRenderingAccuracyTest
All Implemented Interfaces:
Test
Direct Known Subclasses:
SVGRenderingAccuracyTest

public abstract class AbstractRenderingAccuracyTest extends AbstractTest
Checks for regressions in rendering a specific SVG document. The Test will rasterize and SVG document and compare it to a reference image. The test passes if the rasterized SVG and the reference image match exactly (i.e., all pixel values are the same).
Version:
$Id: AbstractRenderingAccuracyTest.java 1808888 2017-09-19 14:22:11Z ssteiner $
  • Field Details

    • ERROR_CANNOT_CREATE_TEMP_FILE

      public static final String ERROR_CANNOT_CREATE_TEMP_FILE
      Error when temp file cannot be created {0} = IOException message
      See Also:
    • ERROR_CANNOT_CREATE_TEMP_FILE_STREAM

      public static final String ERROR_CANNOT_CREATE_TEMP_FILE_STREAM
      Error when temp file stream cannot be created {0} = temp file's cannonical path {1} = IOException message
      See Also:
    • ERROR_CANNOT_OPEN_REFERENCE_IMAGE

      public static final String ERROR_CANNOT_OPEN_REFERENCE_IMAGE
      Error when the reference image cannot be opened {0} = URI of the reference image {1} = IOException message
      See Also:
    • ERROR_CANNOT_OPEN_GENERATED_IMAGE

      public static final String ERROR_CANNOT_OPEN_GENERATED_IMAGE
      Error when the generated image cannot be read {0} = Cannonical path of the temp generated image {1} = IOException message
      See Also:
    • ERROR_ERROR_WHILE_COMPARING_FILES

      public static final String ERROR_ERROR_WHILE_COMPARING_FILES
      Error when there is an IOException while comparing the two reference raster image with the new raster image built from the SVG. {0} = URI of the reference image {1} = Connical path for the temp generated image {2} = IOException message.
      See Also:
    • ERROR_SVG_RENDERING_NOT_ACCURATE

      public static final String ERROR_SVG_RENDERING_NOT_ACCURATE
      Error when the generated image from the SVG file differs from the reference image.
      See Also:
    • ENTRY_KEY_ERROR_DESCRIPTION

      public static final String ENTRY_KEY_ERROR_DESCRIPTION
      Entry describing the error
      See Also:
    • ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI

      public static final String ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI
      Entry describing the reference/generated image file
      See Also:
    • ENTRY_KEY_DIFFERENCE_IMAGE

      public static final String ENTRY_KEY_DIFFERENCE_IMAGE
      Entry describing the generated difference image
      See Also:
    • ENTRY_KEY_INTERNAL_ERROR

      public static final String ENTRY_KEY_INTERNAL_ERROR
      Entry describing that an internal error occured while generating the test failure description
      See Also:
    • COULD_NOT_GENERATE_COMPARISON_IMAGES

      public static final String COULD_NOT_GENERATE_COMPARISON_IMAGES
      Messages expressing that comparison images could not be created: {0} : exception class {1} : exception message {2} : exception stack trace.
      See Also:
    • COULD_NOT_LOAD_IMAGE

      public static final String COULD_NOT_LOAD_IMAGE
      Messages expressing that an image could not be loaded. {0} : URL for the reference image.
      See Also:
    • COULD_NOT_OPEN_VARIATION_URL

      public static final String COULD_NOT_OPEN_VARIATION_URL
      Message expressing that the variation URL could not be open {0} : URL
      See Also:
    • CONFIGURATION_RESOURCES

      public static final String CONFIGURATION_RESOURCES
      The gui resources file name
      See Also:
    • IMAGE_TYPE_COMPARISON

      public static final String IMAGE_TYPE_COMPARISON
      Suffix used for comparison images
      See Also:
    • IMAGE_TYPE_DIFF

      public static final String IMAGE_TYPE_DIFF
      Suffix used for diff images
      See Also:
    • IMAGE_FILE_EXTENSION

      public static final String IMAGE_FILE_EXTENSION
      Suffix used for saved images (e.g., comparison and diff images)
      See Also:
    • configuration

      protected static ResourceBundle configuration
      The configuration resource bundle
    • TEMP_FILE_PREFIX

      public static final String TEMP_FILE_PREFIX
      Prefix for the temporary files created by Tests of this class
    • TEMP_FILE_SUFFIX

      public static final String TEMP_FILE_SUFFIX
      Suffix for the temporary files created by Tests of this class
    • svgURL

      protected URL svgURL
      The URL where the SVG can be found.
    • refImgURL

      protected URL refImgURL
      The URL for the reference image
    • variationURLs

      protected List variationURLs
      A list of URLs of files containing an 'accepted' variation from the reference image.
    • saveVariation

      protected File saveVariation
      The File where the newly computed variation should be saved if different from the variationURL
    • candidateReference

      protected File candidateReference
      The File where the candidate reference should be saved if there is not candidate reference or if it cannot be opened.
    • tempDirectory

      protected static File tempDirectory
      Temporary directory
  • Constructor Details

    • AbstractRenderingAccuracyTest

      public AbstractRenderingAccuracyTest(String svgURL, String refImgURL)
      Constructor.
      Parameters:
      svgURL - the URL String for the SVG document being tested.
      refImgURL - the URL for the reference image.
    • AbstractRenderingAccuracyTest

      protected AbstractRenderingAccuracyTest()
      For subclasses
  • Method Details

    • getTempDirectory

      public static File getTempDirectory()
      Returns the temporary directory
    • setConfig

      public void setConfig(String svgURL, String refImgURL)
      Sets this test's config.
    • resolveURL

      protected URL resolveURL(String url)
      Resolves the input string as follows. + First, the string is interpreted as a file description. If the file exists, then the file name is turned into a URL. + Otherwise, the string is supposed to be a URL. If it is an invalid URL, an IllegalArgumentException is thrown.
    • setSaveVariation

      public void setSaveVariation(File saveVariation)
      Sets the File where the variation from the reference image should be stored
    • getSaveVariation

      public File getSaveVariation()
    • getVariationURLs

      public String[] getVariationURLs()
    • addVariationURL

      public void addVariationURL(String variationURL)
      Adds a URL for an acceptable variation from the reference image.
    • setCandidateReference

      public void setCandidateReference(File candidateReference)
    • getCandidateReference

      public File getCandidateReference()
    • getName

      public String getName()
      Returns this Test's name. The name is the URL of the SVG being rendered.
      Specified by:
      getName in interface Test
      Overrides:
      getName in class AbstractTest
    • run

      public TestReport run()
      Requests this Test to run and produce a report.
      Specified by:
      run in interface Test
      Overrides:
      run in class AbstractTest
    • encode

      public abstract TestReport encode(URL srcURL, FileOutputStream fos)
    • compare

      protected boolean compare(InputStream refStream, InputStream newStream) throws IOException
      Compare the two input streams
      Throws:
      IOException
    • saveImage

      protected void saveImage(BufferedImage img, File imgFile) throws IOException
      Saves an image in a given File
      Throws:
      IOException
    • saveImage

      protected void saveImage(BufferedImage img, OutputStream os) throws IOException
      Saves an image in a given File
      Throws:
      IOException
    • buildDiffImage

      public static BufferedImage buildDiffImage(BufferedImage ref, BufferedImage gen)
      Builds a new BufferedImage that is the difference between the two input images
    • getImage

      protected BufferedImage getImage(File file) throws Exception
      Loads an image from a File
      Throws:
      Exception
    • getImage

      protected BufferedImage getImage(URL url) throws IOException
      Loads an image from a URL
      Throws:
      IOException
    • makeCompareImage

      protected BufferedImage makeCompareImage(BufferedImage ref, BufferedImage gen)
    • imageToFile

      protected File imageToFile(BufferedImage img, String imageType) throws IOException
      Creates a File into which the input image is saved. If there is a "file" component in the SVG url, then a temporary file is created with that name and the imageType suffix in the temp directory of the test-reports directory.
      Throws:
      IOException
    • getURLFile

      protected String getURLFile(URL url)
      Extracts the file portion of the URL
    • makeTempFileName

      protected File makeTempFileName(String svgFileName, String imageType)
    • getNextTempFileName

      protected File getNextTempFileName(String fileName)
    • getNextTempFileName

      protected File getNextTempFileName(String fileName, int instance)
    • makeRandomFileName

      protected File makeRandomFileName(String imageType) throws IOException
      Creates a temporary File into which the input image is saved.
      Throws:
      IOException