Skip to content

Commit 2422454

Browse files
author
timlinux
committed
Added regression test for ticket #992
git-svn-id: http://svn.osgeo.org/qgis/trunk@8980 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 75f90f7 commit 2422454

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

tests/src/core/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ ELSE (APPLE)
127127
ENDIF (APPLE)
128128
129129
130+
#
131+
# Ticket 992 Regression992 test
132+
#
133+
SET(regression992_SRCS regression992.cpp ${util_SRCS})
134+
SET(regression992_MOC_CPPS regression992.cpp)
135+
QT4_WRAP_CPP(regression992_MOC_SRCS ${regression992_MOC_CPPS})
136+
ADD_CUSTOM_TARGET(regression992moc ALL DEPENDS ${regression992_MOC_SRCS})
137+
ADD_EXECUTABLE(regression992 ${regression992_SRCS})
138+
ADD_DEPENDENCIES(regression992 regression992moc)
139+
TARGET_LINK_LIBRARIES(regression992 ${QT_LIBRARIES} qgis_core)
140+
SET_TARGET_PROPERTIES(regression992
141+
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
142+
INSTALL_RPATH_USE_LINK_PATH true)
143+
IF (APPLE)
144+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
145+
INSTALL(TARGETS regression992 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
146+
ADD_TEST(regression992 ${CMAKE_INSTALL_PREFIX}/regression992)
147+
ELSE (APPLE)
148+
INSTALL(TARGETS regression992 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
149+
ADD_TEST(regression992 ${CMAKE_INSTALL_PREFIX}/bin/regression992)
150+
ENDIF (APPLE)
130151
#
131152
# Ticket 1141 Regression1141 test
132153
#

tests/src/core/regression992.cpp

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/***************************************************************************
2+
testqgsvectorfilewriter.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 <QString>
18+
#include <QStringList>
19+
#include <QObject>
20+
#include <iostream>
21+
#include <QApplication>
22+
#include <QFileInfo>
23+
#include <QDir>
24+
#include <QPainter>
25+
#include <QSettings>
26+
#include <QTime>
27+
#include <QDesktopServices>
28+
29+
30+
//qgis includes...
31+
#include <qgsrasterlayer.h>
32+
#include <qgsrasterbandstats.h>
33+
#include <qgsmaplayerregistry.h>
34+
#include <qgsapplication.h>
35+
#include <qgsmaprender.h>
36+
37+
//qgis unit test includes
38+
#include <qgsrenderchecker.h>
39+
40+
41+
/** \ingroup UnitTests
42+
* This is a regression test for ticket #992.
43+
*/
44+
class Regression992: public QObject
45+
{
46+
Q_OBJECT;
47+
private slots:
48+
void initTestCase();// will be called before the first testfunction is executed.
49+
void cleanupTestCase();// will be called after the last testfunction was executed.
50+
void init(){};// will be called before each testfunction is executed.
51+
void cleanup(){};// will be called after every testfunction.
52+
53+
void regression992();
54+
private:
55+
bool render(QString theFileName);
56+
QString mTestDataDir;
57+
QgsRasterLayer * mpRasterLayer;
58+
QgsMapRender * mpMapRenderer;
59+
QString mReport;
60+
};
61+
62+
//runs before all tests
63+
void Regression992::initTestCase()
64+
{
65+
// init QGIS's paths - true means that all path will be inited from prefix
66+
QString qgisPath = QCoreApplication::applicationDirPath ();
67+
QgsApplication::setPrefixPath(INSTALL_PREFIX, true);
68+
QgsApplication::showSettings();
69+
//create some objects that will be used in all tests...
70+
//create a raster layer that will be used in all tests...
71+
mTestDataDir = QString(TEST_DATA_DIR) + QDir::separator(); //defined in CMakeLists.txt
72+
QString myFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
73+
QFileInfo myRasterFileInfo ( myFileName );
74+
mpRasterLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
75+
myRasterFileInfo.completeBaseName() );
76+
// Register the layer with the registry
77+
QgsMapLayerRegistry::instance()->addMapLayer(mpRasterLayer);
78+
// add the test layer to the maprender
79+
mpMapRenderer = new QgsMapRender();
80+
QStringList myLayers;
81+
myLayers << mpRasterLayer->getLayerID();
82+
mpMapRenderer->setLayerSet(myLayers);
83+
mReport += "<h1>Regression 992 Test</h1>\n";
84+
mReport += "<p>See <a href=\"https://trac.osgeo.org/qgis/ticket/992\">"
85+
"trac ticket 992</a> for more details.</p>";
86+
}
87+
//runs after all tests
88+
void Regression992::cleanupTestCase()
89+
{
90+
QString myReportFile = QDir::tempPath() + QDir::separator() + "regression992.html";
91+
QFile myFile ( myReportFile);
92+
if ( myFile.open ( QIODevice::WriteOnly ) )
93+
{
94+
QTextStream myQTextStream ( &myFile );
95+
myQTextStream << mReport;
96+
myFile.close();
97+
QDesktopServices::openUrl("file://"+myReportFile);
98+
}
99+
}
100+
101+
void Regression992::regression992()
102+
{
103+
QVERIFY ( mpRasterLayer->isValid() );
104+
mpMapRenderer->setExtent(mpRasterLayer->extent());
105+
QString myDataDir (TEST_DATA_DIR); //defined in CmakeLists.txt
106+
QString myTestDataDir = myDataDir + QDir::separator();
107+
QgsRenderChecker myChecker;
108+
myChecker.setExpectedImage ( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" );
109+
myChecker.setMapRenderer ( mpMapRenderer );
110+
bool myResultFlag = myChecker.runTest("regression992");
111+
mReport += "\n\n\n" + myChecker.report();
112+
QVERIFY(myResultFlag);
113+
}
114+
115+
QTEST_MAIN(Regression992)
116+
#include "moc_regression992.cxx"
117+

tests/testdata/rgbwcmyk01_YeGeo.jp2

2.74 KB
Binary file not shown.

0 commit comments

Comments
 (0)