Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for premature WKB end in QgsGeometry::asWkt
See #14182
  • Loading branch information
Sandro Santilli authored and jef-n committed Feb 9, 2016
1 parent 2ea3d77 commit e8be21a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -91,6 +91,8 @@ class TestQgsGeometry : public QObject

void exportToGeoJSON();

void wkbInOut();

private:
/** A helper method to do a render check to see if the geometry op is as expected */
bool renderCheck( const QString& theTestName, const QString& theComment = "", int mismatchCount = 0 );
Expand All @@ -101,6 +103,24 @@ class TestQgsGeometry : public QObject
/** A helper method to dump to qdebug the geometry of a polyline */
void dumpPolyline( QgsPolyline &thePolyline );

// Release return with delete []
unsigned char * hex2bytes( const char *hex, int *size )
{
QByteArray ba = QByteArray::fromHex( hex );
unsigned char *out = new unsigned char[ba.size()];
memcpy( out, ba.data(), ba.size() );
*size = ba.size();
return out;
}

QString bytes2hex( const unsigned char *bytes, int size )
{
QByteArray ba(( const char * )bytes, size );
QString out = ba.toHex();
return out;
}


QString elemToString( const QDomElement& elem ) const;

QgsPoint mPoint1;
Expand Down Expand Up @@ -3365,5 +3385,23 @@ QString TestQgsGeometry::elemToString( const QDomElement& elem ) const
return s;
}

void TestQgsGeometry::wkbInOut()
{
// Premature end of WKB
// See http://hub.qgis.org/issues/14182
const char *hexwkb = "0102000000EF0000000000000000000000000000000000000000000000000000000000000000000000";
int size;
unsigned char *wkb = hex2bytes( hexwkb, &size );
QgsGeometry g14182;
// NOTE: wkb onwership transferred to QgsGeometry
g14182.fromWkb( wkb, size );
//QList<QgsGeometry::Error> errors;
//g14182.validateGeometry(errors);
// Check with valgrind !
QString wkt = g14182.exportToWkt();
QCOMPARE( wkt, QString() );

}

QTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"

0 comments on commit e8be21a

Please sign in to comment.