|
| 1 | +/*************************************************************************** |
| 2 | + testqgsrubberband.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : 28.4.2013 |
| 5 | + Copyright : (C) 2013 Vinayan Parameswaran |
| 6 | + Email : vinayan123 at gmail 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 | + |
| 16 | + |
| 17 | +#include <QtTest> |
| 18 | +#include <QObject> |
| 19 | +#include <QString> |
| 20 | +#include <QObject> |
| 21 | +#include <QCoreApplication> |
| 22 | +#include <QWidget> |
| 23 | + |
| 24 | +#include <qgsapplication.h> |
| 25 | +#include <qgsmapcanvas.h> |
| 26 | +#include <qgsvectorlayer.h> |
| 27 | +#include <qgsrubberband.h> |
| 28 | +#include <qgslogger.h> |
| 29 | + |
| 30 | +class TestQgsRubberband: 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 testAddSingleMultiGeometries(); //test for #7728 |
| 40 | + |
| 41 | + private: |
| 42 | + QgsMapCanvas* mCanvas; |
| 43 | + QgsVectorLayer* mPolygonLayer; |
| 44 | + QString mTestDataDir; |
| 45 | + QgsRubberBand* mRubberband; |
| 46 | +}; |
| 47 | + |
| 48 | +void TestQgsRubberband::initTestCase() |
| 49 | +{ |
| 50 | + QgsApplication::init(); |
| 51 | + QgsApplication::initQgis(); |
| 52 | + QgsApplication::showSettings(); |
| 53 | + |
| 54 | + // Setup a map canvas with a vector layer loaded... |
| 55 | + QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt |
| 56 | + mTestDataDir = myDataDir + QDir::separator(); |
| 57 | + |
| 58 | + // |
| 59 | + // load a vector layer |
| 60 | + // |
| 61 | + QString myPolygonFileName = mTestDataDir + "polys.shp"; |
| 62 | + QFileInfo myPolygonFileInfo( myPolygonFileName ); |
| 63 | + mPolygonLayer = new QgsVectorLayer( myPolygonFileInfo.filePath(), |
| 64 | + myPolygonFileInfo.completeBaseName(), "ogr" ); |
| 65 | + |
| 66 | + mCanvas = new QgsMapCanvas(); |
| 67 | + mRubberband = 0; |
| 68 | +} |
| 69 | + |
| 70 | +void TestQgsRubberband::cleanupTestCase() |
| 71 | +{ |
| 72 | + delete mRubberband; |
| 73 | + delete mPolygonLayer; |
| 74 | + delete mCanvas; |
| 75 | +} |
| 76 | + |
| 77 | +void TestQgsRubberband::init() |
| 78 | +{ |
| 79 | + |
| 80 | +} |
| 81 | + |
| 82 | +void TestQgsRubberband::cleanup() |
| 83 | +{ |
| 84 | + |
| 85 | +} |
| 86 | + |
| 87 | +void TestQgsRubberband::testAddSingleMultiGeometries() |
| 88 | +{ |
| 89 | + mRubberband = new QgsRubberBand( mCanvas, mPolygonLayer->geometryType() ); |
| 90 | + QgsGeometry* geomSinglePart = QgsGeometry::fromWkt( "POLYGON((-0.00022418 -0.00000279,-0.0001039 0.00002395,-0.00008677 -0.00005313,-0.00020705 -0.00007987,-0.00022418 -0.00000279))" ); |
| 91 | + QgsGeometry* geomMultiPart = QgsGeometry::fromWkt( "MULTIPOLYGON(((-0.00018203 0.00012178,-0.00009444 0.00014125,-0.00007861 0.00007001,-0.00016619 0.00005054,-0.00018203 0.00012178)),((-0.00030957 0.00009464,-0.00021849 0.00011489,-0.00020447 0.00005184,-0.00029555 0.00003158,-0.00030957 0.00009464)))" ); |
| 92 | + |
| 93 | + mRubberband->addGeometry( geomSinglePart, mPolygonLayer ); |
| 94 | + mRubberband->addGeometry( geomMultiPart, mPolygonLayer ); |
| 95 | + |
| 96 | + QVERIFY( mRubberband->numberOfVertices() == 15 ); |
| 97 | +} |
| 98 | + |
| 99 | +QTEST_MAIN( TestQgsRubberband ) |
| 100 | +#include "moc_testqgsrubberband.cxx" |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
0 commit comments