|
| 1 | +/*************************************************************************** |
| 2 | + testqgsmaptopixelgeometrysimplifier.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : 20 Jan 2008 |
| 5 | + Copyright : (C) 2016 by Sandro Santilli |
| 6 | + Email : strk @ keybit.net |
| 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/QtTest> |
| 16 | +#include <QObject> |
| 17 | +#include <QString> |
| 18 | +#include <QStringList> |
| 19 | +#include <QApplication> |
| 20 | +#include <QFileInfo> |
| 21 | +#include <QDir> |
| 22 | +#include <QDesktopServices> |
| 23 | +#include <QVector> |
| 24 | +#include <QPointF> |
| 25 | +#include <QImage> |
| 26 | +#include <QPainter> |
| 27 | + |
| 28 | +//qgis includes... |
| 29 | +#include <qgsapplication.h> |
| 30 | +#include <qgsgeometry.h> |
| 31 | +#include <qgsmaptopixelgeometrysimplifier.h> |
| 32 | +#if 0 |
| 33 | +#include <qgspoint.h> |
| 34 | +#include "qgsgeometryutils.h" |
| 35 | +#include "qgspointv2.h" |
| 36 | +#include "qgslinestringv2.h" |
| 37 | +#include "qgspolygonv2.h" |
| 38 | +#include "qgscircularstringv2.h" |
| 39 | +#endif |
| 40 | + |
| 41 | +//qgs unit test utility class |
| 42 | +#include "qgsrenderchecker.h" |
| 43 | + |
| 44 | +/** \ingroup UnitTests |
| 45 | + * This is a unit test for the QgsMapToPixelGeometrySimplifier class |
| 46 | + */ |
| 47 | +class TestQgsMapToPixelGeometrySimplifier : public QObject |
| 48 | +{ |
| 49 | + Q_OBJECT |
| 50 | + |
| 51 | + public: |
| 52 | + TestQgsMapToPixelGeometrySimplifier(); |
| 53 | + |
| 54 | + private slots: |
| 55 | + void initTestCase();// will be called before the first testfunction is executed. |
| 56 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 57 | + void init();// will be called before each testfunction is executed. |
| 58 | + void cleanup();// will be called after every testfunction. |
| 59 | + |
| 60 | + void testDefaultGeometry(); |
| 61 | + void testLine1(); |
| 62 | + void testIsGeneralizableByMapBoundingBox(); |
| 63 | + void testMismatchWKB(); |
| 64 | + |
| 65 | +}; |
| 66 | + |
| 67 | +TestQgsMapToPixelGeometrySimplifier::TestQgsMapToPixelGeometrySimplifier() |
| 68 | +{ |
| 69 | +} |
| 70 | + |
| 71 | +void TestQgsMapToPixelGeometrySimplifier::initTestCase() |
| 72 | +{ |
| 73 | + // Runs once before any tests are run |
| 74 | + // init QGIS's paths - true means that all path will be inited from prefix |
| 75 | + QgsApplication::init(); |
| 76 | + QgsApplication::initQgis(); |
| 77 | + QgsApplication::showSettings(); |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +void TestQgsMapToPixelGeometrySimplifier::cleanupTestCase() |
| 82 | +{ |
| 83 | + // Runs once after all tests are run |
| 84 | + QgsApplication::exitQgis(); |
| 85 | +} |
| 86 | + |
| 87 | +void TestQgsMapToPixelGeometrySimplifier::init() |
| 88 | +{ |
| 89 | + // will be called before every testfunction. |
| 90 | +} |
| 91 | + |
| 92 | +void TestQgsMapToPixelGeometrySimplifier::cleanup() |
| 93 | +{ |
| 94 | + // will be called after every testfunction. |
| 95 | +} |
| 96 | + |
| 97 | +void TestQgsMapToPixelGeometrySimplifier::testDefaultGeometry() |
| 98 | +{ |
| 99 | + QgsGeometry *g = new QgsGeometry(); |
| 100 | + int fl = QgsMapToPixelSimplifier::SimplifyGeometry; |
| 101 | + bool ret = QgsMapToPixelSimplifier::simplifyGeometry( g, fl, 10.0 ); |
| 102 | + QVERIFY( ! ret ); // not simplifiable |
| 103 | +} |
| 104 | + |
| 105 | +void TestQgsMapToPixelGeometrySimplifier::testLine1() |
| 106 | +{ |
| 107 | + // NOTE: we need more than 4 vertices, or the line will not be |
| 108 | + // reduced at all by the algorithm |
| 109 | + QgsGeometry *g = QgsGeometry::fromWkt( "LINESTRING(0 0,1 1,2 0,3 1,4 0,20 1,20 0,10 0,5 0)" ); |
| 110 | + int fl; |
| 111 | + bool ret; |
| 112 | + QString wkt; |
| 113 | + |
| 114 | + fl = QgsMapToPixelSimplifier::SimplifyGeometry; |
| 115 | + ret = QgsMapToPixelSimplifier::simplifyGeometry( g, fl, 10.0 ); |
| 116 | + QVERIFY( ret ); |
| 117 | + wkt = g->exportToWkt(); |
| 118 | + // NOTE: I don't think vertex 1,1 should be in this result, |
| 119 | + // but that's what we get now |
| 120 | + QCOMPARE( wkt, QString( "LineString (0 0, 1 1, 20 1, 10 0, 5 0)" ) ); |
| 121 | + |
| 122 | + fl = QgsMapToPixelSimplifier::SimplifyEnvelope; |
| 123 | + ret = QgsMapToPixelSimplifier::simplifyGeometry( g, fl, 20.0 ); |
| 124 | + QVERIFY( ! ret ); |
| 125 | + |
| 126 | + ret = QgsMapToPixelSimplifier::simplifyGeometry( g, fl, 30.0 ); |
| 127 | + QVERIFY( ret ); |
| 128 | + wkt = g->exportToWkt(); |
| 129 | + // NOTE: I don't understand this result either |
| 130 | + QCOMPARE( wkt, QString( "LineString (0 0, 20 1)" ) ); |
| 131 | +} |
| 132 | + |
| 133 | +void |
| 134 | +TestQgsMapToPixelGeometrySimplifier::testIsGeneralizableByMapBoundingBox() |
| 135 | +{ |
| 136 | + QgsRectangle r1( 0, 0, 10, 1 ); |
| 137 | + bool ret; |
| 138 | + |
| 139 | + ret = QgsMapToPixelSimplifier::isGeneralizableByMapBoundingBox( r1, 15 ); |
| 140 | + QVERIFY( ret ); |
| 141 | + |
| 142 | + // NOTE: boundary case |
| 143 | + ret = QgsMapToPixelSimplifier::isGeneralizableByMapBoundingBox( r1, 10 ); |
| 144 | + QVERIFY( ! ret ); |
| 145 | + |
| 146 | + ret = QgsMapToPixelSimplifier::isGeneralizableByMapBoundingBox( r1, 5 ); |
| 147 | + QVERIFY( ! ret ); |
| 148 | +} |
| 149 | + |
| 150 | +void TestQgsMapToPixelGeometrySimplifier::testMismatchWKB() |
| 151 | +{ |
| 152 | + // TODO see http://hub.qgis.org/issues/12416 |
| 153 | +} |
| 154 | + |
| 155 | +QTEST_MAIN( TestQgsMapToPixelGeometrySimplifier ) |
| 156 | +#include "testqgsmaptopixelgeometrysimplifier.moc" |
0 commit comments