Add test for premature WKB end in QgsGeometry::asWkt

See #14182
This commit is contained in:
Sandro Santilli 2016-02-01 11:14:34 +01:00 committed by Juergen E. Fischer
parent 2ea3d7744d
commit e8be21ad61

View File

@ -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 );
@ -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;
@ -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"