|
| 1 | +/*************************************************************************** |
| 2 | + qgsmultirenderchecker.h |
| 3 | + -------------------------------------- |
| 4 | + Date : 6.11.2014 |
| 5 | + Copyright : (C) 2014 Matthias Kuhn |
| 6 | + Email : matthias dot kuhn at gmx dot ch |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#ifndef QGSMULTIRENDERCHECKER_H |
| 17 | +#define QGSMULTIRENDERCHECKER_H |
| 18 | + |
| 19 | +#include "qgsrenderchecker.h" |
| 20 | + |
| 21 | +/** |
| 22 | + * This class allows to check rendered images against comparison images. |
| 23 | + * Its main purpose is for the unit testing framework. |
| 24 | + * |
| 25 | + * It will either |
| 26 | + * <ul> |
| 27 | + * <li>take an externally rendered image (setRenderedImage())</li> |
| 28 | + * <li>render the image based on provided mapSettings (setMapSettings())</li> |
| 29 | + * </ul> |
| 30 | + * |
| 31 | + * This image will then be compared against one or several images in a folder inside |
| 32 | + * the control directory (tests/testdata/control_images/{controlName}). |
| 33 | + * |
| 34 | + * There are modes for single and for multiple reference images. |
| 35 | + * <ul> |
| 36 | + * <li>If there are no subfolders in the control directory, it will assume an image |
| 37 | + * with the name {controlImage}.png in the control directory itself.</li> |
| 38 | + * |
| 39 | + * <li>If there are subfolders inside the control directory, it will search for images |
| 40 | + * with the name {controlImage}.png in every subfolder.</li> |
| 41 | + * </ul> |
| 42 | + * |
| 43 | + * For every control image there may be one or several randomly named anomaly images defining |
| 44 | + * allowed anomalies. |
| 45 | + * For every control image, the allowed mismatch and color tolerance values will be calculated |
| 46 | + * individually. |
| 47 | + * |
| 48 | + * @note added in 2.8 |
| 49 | + */ |
| 50 | + |
| 51 | +class CORE_EXPORT QgsMultiRenderChecker |
| 52 | +{ |
| 53 | + public: |
| 54 | + QgsMultiRenderChecker(); |
| 55 | + |
| 56 | + /** |
| 57 | + * Base directory name for the control image (with control image path |
| 58 | + * suffixed) the path to the image will be constructed like this: |
| 59 | + * controlImagePath + '/' + mControlName + '/' + mControlName + '.png' |
| 60 | + */ |
| 61 | + void setControlName( const QString& theName ); |
| 62 | + |
| 63 | + void setControlPathPrefix( const QString& prefix ); |
| 64 | + |
| 65 | + /** |
| 66 | + * Set the path to the rendered image. If this is not set or set to QString::Null, an image |
| 67 | + * will be rendered based on the provided mapsettings |
| 68 | + * |
| 69 | + * @param renderedImagePath A path to the rendered image with which control images will be compared |
| 70 | + */ |
| 71 | + void setRenderedImage( const QString& renderedImagePath ) { mRenderedImage = renderedImagePath; } |
| 72 | + |
| 73 | + /** |
| 74 | + * Set the map settings to use to render the image |
| 75 | + * |
| 76 | + * @param mapSettings The map settings |
| 77 | + */ |
| 78 | + void setMapSettings( const QgsMapSettings& mapSettings ); |
| 79 | + |
| 80 | + /** |
| 81 | + * Set tolerance for color components used by runTest() |
| 82 | + * Default value is 0. |
| 83 | + * |
| 84 | + * @param theColorTolerance The maximum difference for each color component |
| 85 | + * including alpha to be considered correct. |
| 86 | + */ |
| 87 | + void setColorTolerance( unsigned int theColorTolerance ) { mColorTolerance = theColorTolerance; } |
| 88 | + |
| 89 | + /** |
| 90 | + * Test using renderer to generate the image to be compared. |
| 91 | + * |
| 92 | + * @param theTestName - to be used as the basis for writing a file to |
| 93 | + * e.g. /tmp/theTestName.png |
| 94 | + * |
| 95 | + * @param theMismatchCount - defaults to 0 - the number of pixels that |
| 96 | + * are allowed to be different from the control image. In some cases |
| 97 | + * rendering may be non-deterministic. This parameter allows you to account |
| 98 | + * for that by providing a tolerance. |
| 99 | + * |
| 100 | + * @note make sure to call setExpectedImage and setMapSettings first |
| 101 | + */ |
| 102 | + bool runTest( const QString& theTestName, unsigned int theMismatchCount = 0 ); |
| 103 | + |
| 104 | + /** |
| 105 | + * Returns a report for this test |
| 106 | + * |
| 107 | + * @return A report |
| 108 | + */ |
| 109 | + const QString& report() const { return mReport; } |
| 110 | + |
| 111 | + /** |
| 112 | + * @brief controlImagePath |
| 113 | + * @return |
| 114 | + */ |
| 115 | + const QString controlImagePath() const; |
| 116 | + |
| 117 | + private: |
| 118 | + QString mReport; |
| 119 | + QString mRenderedImage; |
| 120 | + QString mControlName; |
| 121 | + QString mControlPathPrefix; |
| 122 | + unsigned int mColorTolerance; |
| 123 | + QgsMapSettings mMapSettings; |
| 124 | +}; |
| 125 | + |
| 126 | +#endif // QGSMULTIRENDERCHECKER_H |
0 commit comments