|
| 1 | +/*************************************************************************** |
| 2 | + test_template.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : Sun Sep 16 12:22:23 AKDT 2007 |
| 5 | + Copyright : (C) 2007 by Gary E. Sherman |
| 6 | + Email : sherman at mrcc dot 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 <QObject> |
| 19 | +#include <QApplication> |
| 20 | +#include <QFileInfo> |
| 21 | +#include <QDir> |
| 22 | +#include <QDesktopServices> |
| 23 | + |
| 24 | +#include <iostream> |
| 25 | +//qgis includes... |
| 26 | +#include <qgsapplication.h> |
| 27 | +#include <qgsgeometry.h> |
| 28 | +//header for class being tested |
| 29 | +#include <qgspoint.h> |
| 30 | + |
| 31 | +class TestQgsPoint: public QObject |
| 32 | +{ |
| 33 | + Q_OBJECT; |
| 34 | + private slots: |
| 35 | + void initTestCase();// will be called before the first testfunction is executed. |
| 36 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 37 | + void init();// will be called before each testfunction is executed. |
| 38 | + void cleanup();// will be called after every testfunction. |
| 39 | + void toString(); |
| 40 | + void toDegreesMinutesSeconds(); |
| 41 | + void wellKnownText(); |
| 42 | + void sqrDist(); |
| 43 | + void multiply(); |
| 44 | + void onSegment(); |
| 45 | + private: |
| 46 | + QgsPoint mPoint1; |
| 47 | + QgsPoint mPoint2; |
| 48 | + QgsPoint mPoint3; |
| 49 | + QgsPoint mPoint4; |
| 50 | + QString mReport; |
| 51 | +}; |
| 52 | + |
| 53 | +void TestQgsPoint::init() |
| 54 | +{ |
| 55 | + // |
| 56 | + // Reset / reinitialise the geometries before each test is run |
| 57 | + // |
| 58 | + mPoint1 = QgsPoint( 20.0, -20.0 ); |
| 59 | + mPoint2 = QgsPoint( -80.0, 20.0 ); |
| 60 | + mPoint3 = QgsPoint( -80.0, -20.0 ); |
| 61 | + mPoint4 = QgsPoint( 80.0, 20.0 ); |
| 62 | +} |
| 63 | + |
| 64 | +void TestQgsPoint::cleanup() |
| 65 | +{ |
| 66 | + // will be called after every testfunction. |
| 67 | +} |
| 68 | + |
| 69 | +void TestQgsPoint::initTestCase() |
| 70 | +{ |
| 71 | + // |
| 72 | + // Runs once before any tests are run |
| 73 | + // |
| 74 | + // init QGIS's paths - true means that all path will be inited from prefix |
| 75 | + QString qgisPath = QCoreApplication::applicationDirPath(); |
| 76 | + QgsApplication::setPrefixPath( INSTALL_PREFIX, true ); |
| 77 | + QgsApplication::showSettings(); |
| 78 | + mReport += "<h1>Point Tests</h1>\n"; |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +void TestQgsPoint::cleanupTestCase() |
| 83 | +{ |
| 84 | + // |
| 85 | + // Runs once after all tests are run |
| 86 | + // |
| 87 | + QString myReportFile = QDir::tempPath() + QDir::separator() + "qgspointtest.html"; |
| 88 | + QFile myFile( myReportFile ); |
| 89 | + if ( myFile.open( QIODevice::WriteOnly ) ) |
| 90 | + { |
| 91 | + QTextStream myQTextStream( &myFile ); |
| 92 | + myQTextStream << mReport; |
| 93 | + myFile.close(); |
| 94 | + QDesktopServices::openUrl( "file://" + myReportFile ); |
| 95 | + } |
| 96 | + |
| 97 | +} |
| 98 | + |
| 99 | +void TestQgsPoint::toString() |
| 100 | +{ |
| 101 | + mReport += "<p>Testing toString()</p>"; |
| 102 | + mReport += "<p>" + mPoint1.toString( 2 ) + "</p>"; |
| 103 | + mReport += "<p>" + mPoint2.toString( 2 ) + "</p>"; |
| 104 | + mReport += "<p>" + mPoint3.toString( 2 ) + "</p>"; |
| 105 | + mReport += "<p>" + mPoint4.toString( 2 ) + "</p>"; |
| 106 | + QVERIFY( mPoint1.toString( 2 ) == QString("20.00,-20.00") ); |
| 107 | +}; |
| 108 | +void TestQgsPoint::toDegreesMinutesSeconds() |
| 109 | +{ |
| 110 | + mReport += "<p>Testing toDegreesMinutesSecods()</p>"; |
| 111 | + mReport += "<p>" + mPoint1.toDegreesMinutesSeconds( 2 ) + "</p>"; |
| 112 | + mReport += "<p>" + mPoint2.toDegreesMinutesSeconds( 2 ) + "</p>"; |
| 113 | + mReport += "<p>" + mPoint3.toDegreesMinutesSeconds( 2 ) + "</p>"; |
| 114 | + mReport += "<p>" + mPoint4.toDegreesMinutesSeconds( 2 ) + "</p>"; |
| 115 | + QVERIFY( mPoint4.toString( 2 ) == QString("80°0'0.00\"E,20°0'0.00\"N") ); |
| 116 | + |
| 117 | +}; |
| 118 | +void TestQgsPoint::wellKnownText() |
| 119 | +{ |
| 120 | + |
| 121 | +}; |
| 122 | +void TestQgsPoint::sqrDist() |
| 123 | +{ |
| 124 | + |
| 125 | +}; |
| 126 | +void TestQgsPoint::multiply() |
| 127 | +{ |
| 128 | + |
| 129 | +}; |
| 130 | +void TestQgsPoint::onSegment() |
| 131 | +{ |
| 132 | + |
| 133 | +}; |
| 134 | + |
| 135 | + |
| 136 | +QTEST_MAIN(TestQgsPoint) |
| 137 | +#include "moc_testqgspoint.cxx" |
0 commit comments