Skip to content

Commit 87887e4

Browse files
author
Sandro Santilli
committedFeb 1, 2016
Add test for unexpected WKB input in simplification
Closes #12416
1 parent 639d1b3 commit 87887e4

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed
 

‎tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ class TestQgsMapToPixelGeometrySimplifier : public QObject
5151
public:
5252
TestQgsMapToPixelGeometrySimplifier();
5353

54+
private:
55+
// Release return with delete []
56+
unsigned char *
57+
hex2bytes( const char *hex, int *size )
58+
{
59+
QByteArray ba = QByteArray::fromHex( hex );
60+
unsigned char *out = new unsigned char[ba.size()];
61+
memcpy( out, ba.data(), ba.size() );
62+
*size = ba.size();
63+
return out;
64+
}
65+
5466
private slots:
5567
void initTestCase();// will be called before the first testfunction is executed.
5668
void cleanupTestCase();// will be called after the last testfunction was executed.
@@ -60,7 +72,7 @@ class TestQgsMapToPixelGeometrySimplifier : public QObject
6072
void testDefaultGeometry();
6173
void testLine1();
6274
void testIsGeneralizableByMapBoundingBox();
63-
void testMismatchWKB();
75+
void testWkbDimensionMismatch();
6476

6577
};
6678

@@ -147,9 +159,26 @@ TestQgsMapToPixelGeometrySimplifier::testIsGeneralizableByMapBoundingBox()
147159
QVERIFY( ! ret );
148160
}
149161

150-
void TestQgsMapToPixelGeometrySimplifier::testMismatchWKB()
162+
void TestQgsMapToPixelGeometrySimplifier::testWkbDimensionMismatch()
151163
{
152-
// TODO see http://hub.qgis.org/issues/12416
164+
// 2D multilinestring containing 2 3DZ linestrings
165+
// See http://hub.qgis.org/issues/12416
166+
// NOTE: the first line needs to be 5 vertices or more, or
167+
// simplification won't even be attempted
168+
const char *hexwkb = "010500000002000000010200008005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000040000000000000000000000000000000000000000000000840000000000000F03F0000000000000000000000000000244000000000000000008DEDB5A0F7C6B0BE010200008002000000000000000000000000000000000000000000000000000000000000000000000000000000000000008DEDB5A0F7C6B03E";
169+
int size;
170+
unsigned char *wkb = hex2bytes( hexwkb, &size );
171+
QgsGeometry g12416;
172+
// NOTE: wkb onwership transferred to QgsGeometry
173+
g12416.fromWkb( wkb, size );
174+
QString wkt = g12416.exportToWkt();
175+
QCOMPARE( wkt, QString( "MultiLineString ((0 0 0, 1 1 0, 2 0 0, 3 1 0, 10 0 -0.000001),(0 0 0, 0 0 0.000001))" ) );
176+
177+
int fl = QgsMapToPixelSimplifier::SimplifyGeometry;
178+
int ret = QgsMapToPixelSimplifier::simplifyGeometry( &g12416, fl, 20.0 );
179+
// NOTE: currently false due to thrown exception, but fixing the
180+
// simplification code might actually give a success
181+
QVERIFY( ! ret );
153182
}
154183

155184
QTEST_MAIN( TestQgsMapToPixelGeometrySimplifier )

0 commit comments

Comments
 (0)
Please sign in to comment.