|
| 1 | +/*************************************************************************** |
| 2 | + testcontrastenhancements.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : Frida Nov 23 2007 |
| 5 | + Copyright : (C) 2007 by Tim Sutton |
| 6 | + Email : tim@linfiniti.com |
| 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 | +#include <QtTest> |
| 16 | +#include <QObject> |
| 17 | +#include <QApplication> |
| 18 | +#include <QDesktopServices> |
| 19 | + |
| 20 | + |
| 21 | +//qgis includes... |
| 22 | +#include <qgsrasterlayer.h> |
| 23 | +#include <qgscliptominmaxenhancement.h> |
| 24 | +#include <qgscontrastenhancement.h> |
| 25 | +#include <qgslinearminmaxenhancement.h> |
| 26 | + |
| 27 | +/** \ingroup UnitTests |
| 28 | + * This is a unit test for the ContrastEnhancements contrast enhancement classes. |
| 29 | + */ |
| 30 | +class TestContrastEnhancements: public QObject |
| 31 | +{ |
| 32 | + Q_OBJECT; |
| 33 | + private slots: |
| 34 | + void initTestCase();// will be called before the first testfunction is executed. |
| 35 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 36 | + void init() {};// will be called before each testfunction is executed. |
| 37 | + void cleanup() {};// will be called after every testfunction. |
| 38 | + |
| 39 | + void minMaxEnhancementTest(); |
| 40 | + void linearMinMaxEnhancementTest(); |
| 41 | + private: |
| 42 | + QString mReport; |
| 43 | +}; |
| 44 | + |
| 45 | +//runs before all tests |
| 46 | +void TestContrastEnhancements::initTestCase() |
| 47 | +{ |
| 48 | + mReport += "<h1>Raster Contrast Enhancement Tests</h1>\n"; |
| 49 | +} |
| 50 | +//runs after all tests |
| 51 | +void TestContrastEnhancements::cleanupTestCase() |
| 52 | +{ |
| 53 | + QString myReportFile = QDir::tempPath() + QDir::separator() + "contrastenhancementest.html"; |
| 54 | + QFile myFile( myReportFile ); |
| 55 | + if ( myFile.open( QIODevice::WriteOnly ) ) |
| 56 | + { |
| 57 | + QTextStream myQTextStream( &myFile ); |
| 58 | + myQTextStream << mReport; |
| 59 | + myFile.close(); |
| 60 | + QDesktopServices::openUrl( "file://" + myReportFile ); |
| 61 | + } |
| 62 | + |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +void TestContrastEnhancements::minMaxEnhancementTest() |
| 67 | +{ |
| 68 | + QgsClipToMinMaxEnhancement myEnhancement(QgsContrastEnhancement::QGS_Byte, 10.0, 240.0); |
| 69 | + QVERIFY(!myEnhancement.isValueInDisplayableRange(0.0)); |
| 70 | + QVERIFY(10.0 == myEnhancement.enhanceValue(0.0)) ; |
| 71 | + QVERIFY(250.0 == myEnhancement.enhanceValue(240.0)) ; |
| 72 | +} |
| 73 | +void TestContrastEnhancements::linearMinMaxEnhancementTest() |
| 74 | +{ |
| 75 | + QgsLinearMinMaxEnhancement myEnhancement(QgsContrastEnhancement::QGS_Byte, 10.0, 240.0); |
| 76 | + //0 should be scaled to 10 and not clipped |
| 77 | + QVERIFY(myEnhancement.isValueInDisplayableRange(0.0)); |
| 78 | + QVERIFY(10.0 == myEnhancement.enhanceValue(0.0)) ; |
| 79 | + QVERIFY(250.0 == myEnhancement.enhanceValue(240.0)) ; |
| 80 | +} |
| 81 | +QTEST_MAIN( TestContrastEnhancements ) |
| 82 | +#include "moc_testcontrastenhancements.cxx" |
| 83 | + |
0 commit comments