Skip to content

Commit 66ed0b9

Browse files
author
timlinux
committed
Unit tests for raster contrast enhancements
git-svn-id: http://svn.osgeo.org/qgis/trunk@9230 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 443f735 commit 66ed0b9

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

tests/src/core/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@ ELSE (APPLE)
191191
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
192192
ENDIF (APPLE)
193193
#
194+
# Contrast Enhancements Test
195+
#
196+
SET(qgis_contrastenhancementtest_SRCS testcontrastenhancements.cpp)
197+
SET(qgis_contrastenhancementtest_MOC_CPPS testcontrastenhancements.cpp)
198+
QT4_WRAP_CPP(qgis_contrastenhancementtest_MOC_SRCS ${qgis_contrastenhancementtest_MOC_CPPS})
199+
ADD_CUSTOM_TARGET(qgis_contrastenhancementtestmoc ALL DEPENDS ${qgis_contrastenhancementtest_MOC_SRCS})
200+
ADD_EXECUTABLE(qgis_contrastenhancementtest ${qgis_contrastenhancementtest_SRCS})
201+
ADD_DEPENDENCIES(qgis_contrastenhancementtest qgis_contrastenhancementtestmoc)
202+
TARGET_LINK_LIBRARIES(qgis_contrastenhancementtest ${QT_LIBRARIES} qgis_core)
203+
SET_TARGET_PROPERTIES(qgis_contrastenhancementtest
204+
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
205+
INSTALL_RPATH_USE_LINK_PATH true)
206+
IF (APPLE)
207+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
208+
ADD_TEST(qgis_contrastenhancementtest ${CMAKE_INSTALL_PREFIX}/qgis_contrastenhancementtest)
209+
INSTALL(TARGETS qgis_contrastenhancementtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
210+
ELSE (APPLE)
211+
ADD_TEST(qgis_contrastenhancementtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_contrastenhancementtest)
212+
INSTALL(TARGETS qgis_contrastenhancementtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
213+
ENDIF (APPLE)
214+
#
194215
# QgsMapLayer test
195216
#
196217
SET(qgis_maplayertest_SRCS testqgsmaplayer.cpp ${util_SRCS})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
2 Bytes
Loading

0 commit comments

Comments
 (0)