|
| 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 | + |
0 commit comments