Skip to content
Permalink
Browse files
Unit tests for raster contrast enhancements
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9230 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 31, 2008
1 parent 8ed66c3 commit df6ba8ca4a719525d6845764a4aa116b40b05c23
@@ -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})
@@ -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 not shown.

0 comments on commit df6ba8c

Please sign in to comment.