Class 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 Summary

      Fields 
      Modifier and Type Field Description
      protected java.io.File candidateReference
      The File where the candidate reference should be saved if there is not candidate reference or if it cannot be opened.
      protected static java.util.ResourceBundle configuration
      The configuration resource bundle
      static java.lang.String CONFIGURATION_RESOURCES
      The gui resources file name
      static java.lang.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.
      static java.lang.String COULD_NOT_LOAD_IMAGE
      Messages expressing that an image could not be loaded.
      static java.lang.String COULD_NOT_OPEN_VARIATION_URL
      Message expressing that the variation URL could not be open {0} : URL
      static java.lang.String ENTRY_KEY_DIFFERENCE_IMAGE
      Entry describing the generated difference image
      static java.lang.String ENTRY_KEY_ERROR_DESCRIPTION
      Entry describing the error
      static java.lang.String ENTRY_KEY_INTERNAL_ERROR
      Entry describing that an internal error occured while generating the test failure description
      static java.lang.String ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI
      Entry describing the reference/generated image file
      static java.lang.String ERROR_CANNOT_CREATE_TEMP_FILE
      Error when temp file cannot be created {0} = IOException message
      static java.lang.String ERROR_CANNOT_CREATE_TEMP_FILE_STREAM
      Error when temp file stream cannot be created {0} = temp file's cannonical path {1} = IOException message
      static java.lang.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
      static java.lang.String ERROR_CANNOT_OPEN_REFERENCE_IMAGE
      Error when the reference image cannot be opened {0} = URI of the reference image {1} = IOException message
      static java.lang.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.
      static java.lang.String ERROR_SVG_RENDERING_NOT_ACCURATE
      Error when the generated image from the SVG file differs from the reference image.
      static java.lang.String IMAGE_FILE_EXTENSION
      Suffix used for saved images (e.g., comparison and diff images)
      static java.lang.String IMAGE_TYPE_COMPARISON
      Suffix used for comparison images
      static java.lang.String IMAGE_TYPE_DIFF
      Suffix used for diff images
      protected java.net.URL refImgURL
      The URL for the reference image
      protected java.io.File saveVariation
      The File where the newly computed variation should be saved if different from the variationURL
      protected java.net.URL svgURL
      The URL where the SVG can be found.
      static java.lang.String TEMP_FILE_PREFIX
      Prefix for the temporary files created by Tests of this class
      static java.lang.String TEMP_FILE_SUFFIX
      Suffix for the temporary files created by Tests of this class
      protected static java.io.File tempDirectory
      Temporary directory
      protected java.util.List variationURLs
      A list of URLs of files containing an 'accepted' variation from the reference image.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addVariationURL​(java.lang.String variationURL)
      Adds a URL for an acceptable variation from the reference image.
      static java.awt.image.BufferedImage buildDiffImage​(java.awt.image.BufferedImage ref, java.awt.image.BufferedImage gen)
      Builds a new BufferedImage that is the difference between the two input images
      protected boolean compare​(java.io.InputStream refStream, java.io.InputStream newStream)
      Compare the two input streams
      abstract TestReport encode​(java.net.URL srcURL, java.io.FileOutputStream fos)  
      java.io.File getCandidateReference()  
      protected java.awt.image.BufferedImage getImage​(java.io.File file)
      Loads an image from a File
      protected java.awt.image.BufferedImage getImage​(java.net.URL url)
      Loads an image from a URL
      java.lang.String getName()
      Returns this Test's name.
      protected java.io.File getNextTempFileName​(java.lang.String fileName)  
      protected java.io.File getNextTempFileName​(java.lang.String fileName, int instance)  
      java.io.File getSaveVariation()  
      static java.io.File getTempDirectory()
      Returns the temporary directory
      protected java.lang.String getURLFile​(java.net.URL url)
      Extracts the file portion of the URL
      java.lang.String[] getVariationURLs()  
      protected java.io.File imageToFile​(java.awt.image.BufferedImage img, java.lang.String imageType)
      Creates a File into which the input image is saved.
      protected java.awt.image.BufferedImage makeCompareImage​(java.awt.image.BufferedImage ref, java.awt.image.BufferedImage gen)  
      protected java.io.File makeRandomFileName​(java.lang.String imageType)
      Creates a temporary File into which the input image is saved.
      protected java.io.File makeTempFileName​(java.lang.String svgFileName, java.lang.String imageType)  
      protected java.net.URL resolveURL​(java.lang.String url)
      Resolves the input string as follows.
      TestReport run()
      Requests this Test to run and produce a report.
      protected void saveImage​(java.awt.image.BufferedImage img, java.io.File imgFile)
      Saves an image in a given File
      protected void saveImage​(java.awt.image.BufferedImage img, java.io.OutputStream os)
      Saves an image in a given File
      void setCandidateReference​(java.io.File candidateReference)
      void setConfig​(java.lang.String svgURL, java.lang.String refImgURL)
      Sets this test's config.
      void setSaveVariation​(java.io.File saveVariation)
      Sets the File where the variation from the reference image should be stored
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ERROR_CANNOT_CREATE_TEMP_FILE

        public static final java.lang.String ERROR_CANNOT_CREATE_TEMP_FILE
        Error when temp file cannot be created {0} = IOException message
        See Also:
        Constant Field Values
      • ERROR_CANNOT_CREATE_TEMP_FILE_STREAM

        public static final java.lang.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:
        Constant Field Values
      • ERROR_CANNOT_OPEN_REFERENCE_IMAGE

        public static final java.lang.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:
        Constant Field Values
      • ERROR_CANNOT_OPEN_GENERATED_IMAGE

        public static final java.lang.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:
        Constant Field Values
      • ERROR_ERROR_WHILE_COMPARING_FILES

        public static final java.lang.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:
        Constant Field Values
      • ERROR_SVG_RENDERING_NOT_ACCURATE

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

        public static final java.lang.String ENTRY_KEY_ERROR_DESCRIPTION
        Entry describing the error
        See Also:
        Constant Field Values
      • ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI

        public static final java.lang.String ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI
        Entry describing the reference/generated image file
        See Also:
        Constant Field Values
      • ENTRY_KEY_DIFFERENCE_IMAGE

        public static final java.lang.String ENTRY_KEY_DIFFERENCE_IMAGE
        Entry describing the generated difference image
        See Also:
        Constant Field Values
      • ENTRY_KEY_INTERNAL_ERROR

        public static final java.lang.String ENTRY_KEY_INTERNAL_ERROR
        Entry describing that an internal error occured while generating the test failure description
        See Also:
        Constant Field Values
      • COULD_NOT_GENERATE_COMPARISON_IMAGES

        public static final java.lang.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:
        Constant Field Values
      • COULD_NOT_LOAD_IMAGE

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

        public static final java.lang.String COULD_NOT_OPEN_VARIATION_URL
        Message expressing that the variation URL could not be open {0} : URL
        See Also:
        Constant Field Values
      • CONFIGURATION_RESOURCES

        public static final java.lang.String CONFIGURATION_RESOURCES
        The gui resources file name
        See Also:
        Constant Field Values
      • IMAGE_TYPE_COMPARISON

        public static final java.lang.String IMAGE_TYPE_COMPARISON
        Suffix used for comparison images
        See Also:
        Constant Field Values
      • IMAGE_TYPE_DIFF

        public static final java.lang.String IMAGE_TYPE_DIFF
        Suffix used for diff images
        See Also:
        Constant Field Values
      • IMAGE_FILE_EXTENSION

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

        protected static java.util.ResourceBundle configuration
        The configuration resource bundle
      • TEMP_FILE_PREFIX

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

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

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

        protected java.net.URL refImgURL
        The URL for the reference image
      • variationURLs

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

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

        protected java.io.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 java.io.File tempDirectory
        Temporary directory
    • Constructor Detail

      • AbstractRenderingAccuracyTest

        public AbstractRenderingAccuracyTest​(java.lang.String svgURL,
                                             java.lang.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 Detail

      • getTempDirectory

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

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

        protected java.net.URL resolveURL​(java.lang.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​(java.io.File saveVariation)
        Sets the File where the variation from the reference image should be stored
      • getSaveVariation

        public java.io.File getSaveVariation()
      • getVariationURLs

        public java.lang.String[] getVariationURLs()
      • addVariationURL

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

        public void setCandidateReference​(java.io.File candidateReference)
      • getCandidateReference

        public java.io.File getCandidateReference()
      • getName

        public java.lang.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
      • encode

        public abstract TestReport encode​(java.net.URL srcURL,
                                          java.io.FileOutputStream fos)
      • compare

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

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

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

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

        protected java.awt.image.BufferedImage getImage​(java.io.File file)
                                                 throws java.lang.Exception
        Loads an image from a File
        Throws:
        java.lang.Exception
      • getImage

        protected java.awt.image.BufferedImage getImage​(java.net.URL url)
                                                 throws java.io.IOException
        Loads an image from a URL
        Throws:
        java.io.IOException
      • makeCompareImage

        protected java.awt.image.BufferedImage makeCompareImage​(java.awt.image.BufferedImage ref,
                                                                java.awt.image.BufferedImage gen)
      • imageToFile

        protected java.io.File imageToFile​(java.awt.image.BufferedImage img,
                                           java.lang.String imageType)
                                    throws java.io.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:
        java.io.IOException
      • getURLFile

        protected java.lang.String getURLFile​(java.net.URL url)
        Extracts the file portion of the URL
      • makeTempFileName

        protected java.io.File makeTempFileName​(java.lang.String svgFileName,
                                                java.lang.String imageType)
      • getNextTempFileName

        protected java.io.File getNextTempFileName​(java.lang.String fileName)
      • getNextTempFileName

        protected java.io.File getNextTempFileName​(java.lang.String fileName,
                                                   int instance)
      • makeRandomFileName

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