PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/src/core/regression992.cpp

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