Skip to content

Commit

Permalink
Unit tests for raster contrast enhancements
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9230 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 31, 2008
1 parent 443f735 commit 66ed0b9
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -191,6 +191,27 @@ ELSE (APPLE)
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
ENDIF (APPLE)
#
# Contrast Enhancements Test
#
SET(qgis_contrastenhancementtest_SRCS testcontrastenhancements.cpp)
SET(qgis_contrastenhancementtest_MOC_CPPS testcontrastenhancements.cpp)
QT4_WRAP_CPP(qgis_contrastenhancementtest_MOC_SRCS ${qgis_contrastenhancementtest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_contrastenhancementtestmoc ALL DEPENDS ${qgis_contrastenhancementtest_MOC_SRCS})
ADD_EXECUTABLE(qgis_contrastenhancementtest ${qgis_contrastenhancementtest_SRCS})
ADD_DEPENDENCIES(qgis_contrastenhancementtest qgis_contrastenhancementtestmoc)
TARGET_LINK_LIBRARIES(qgis_contrastenhancementtest ${QT_LIBRARIES} qgis_core)
SET_TARGET_PROPERTIES(qgis_contrastenhancementtest
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
INSTALL_RPATH_USE_LINK_PATH true)
IF (APPLE)
# For Mac OS X, the executable must be at the root of the bundle's executable folder
ADD_TEST(qgis_contrastenhancementtest ${CMAKE_INSTALL_PREFIX}/qgis_contrastenhancementtest)
INSTALL(TARGETS qgis_contrastenhancementtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
ELSE (APPLE)
ADD_TEST(qgis_contrastenhancementtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_contrastenhancementtest)
INSTALL(TARGETS qgis_contrastenhancementtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
ENDIF (APPLE)
#
# QgsMapLayer test
#
SET(qgis_maplayertest_SRCS testqgsmaplayer.cpp ${util_SRCS})
Expand Down
83 changes: 83 additions & 0 deletions tests/src/core/testcontrastenhancements.cpp
@@ -0,0 +1,83 @@
/***************************************************************************
testcontrastenhancements.cpp
--------------------------------------
Date : Frida Nov 23 2007
Copyright : (C) 2007 by Tim Sutton
Email : tim@linfiniti.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QtTest>
#include <QObject>
#include <QApplication>
#include <QDesktopServices>


//qgis includes...
#include <qgsrasterlayer.h>
#include <qgscliptominmaxenhancement.h>
#include <qgscontrastenhancement.h>
#include <qgslinearminmaxenhancement.h>

/** \ingroup UnitTests
* This is a unit test for the ContrastEnhancements contrast enhancement classes.
*/
class TestContrastEnhancements: public QObject
{
Q_OBJECT;
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init() {};// will be called before each testfunction is executed.
void cleanup() {};// will be called after every testfunction.

void minMaxEnhancementTest();
void linearMinMaxEnhancementTest();
private:
QString mReport;
};

//runs before all tests
void TestContrastEnhancements::initTestCase()
{
mReport += "<h1>Raster Contrast Enhancement Tests</h1>\n";
}
//runs after all tests
void TestContrastEnhancements::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "contrastenhancementest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
QDesktopServices::openUrl( "file://" + myReportFile );
}

}


void TestContrastEnhancements::minMaxEnhancementTest()
{
QgsClipToMinMaxEnhancement myEnhancement(QgsContrastEnhancement::QGS_Byte, 10.0, 240.0);
QVERIFY(!myEnhancement.isValueInDisplayableRange(0.0));
QVERIFY(10.0 == myEnhancement.enhanceValue(0.0)) ;
QVERIFY(250.0 == myEnhancement.enhanceValue(240.0)) ;
}
void TestContrastEnhancements::linearMinMaxEnhancementTest()
{
QgsLinearMinMaxEnhancement myEnhancement(QgsContrastEnhancement::QGS_Byte, 10.0, 240.0);
//0 should be scaled to 10 and not clipped
QVERIFY(myEnhancement.isValueInDisplayableRange(0.0));
QVERIFY(10.0 == myEnhancement.enhanceValue(0.0)) ;
QVERIFY(250.0 == myEnhancement.enhanceValue(240.0)) ;
}
QTEST_MAIN( TestContrastEnhancements )
#include "moc_testcontrastenhancements.cxx"

Binary file modified tests/testdata/expected_rgbwcmyk01_YeGeo.jp2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 66ed0b9

Please sign in to comment.