Skip to content
Permalink
Browse files

Fix super ridiculously noisy qgsgeometry test output

  • Loading branch information
nyalldawson committed Aug 19, 2020
1 parent 5a7cb16 commit 65cf6b0c0b7fbd9039df4cc6d33101b16e5fa10d
Showing with 68 additions and 57 deletions.
  1. +68 −57 tests/src/core/testqgsgeometry.cpp
@@ -76,7 +76,6 @@ class TestQgsGeometry : public QObject
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void copy();
void assignment();
@@ -166,12 +165,17 @@ class TestQgsGeometry : public QObject
void testRandomPointsInPolygon();

private:
//! Must be called before each render test
void initPainterTest();

//! A helper method to do a render check to see if the geometry op is as expected
bool renderCheck( const QString &testName, const QString &comment = QString(), int mismatchCount = 0 );
//! A helper method to dump to qdebug the geometry of a multipolygon
void dumpMultiPolygon( QgsMultiPolygonXY &multiPolygon );
void paintMultiPolygon( QgsMultiPolygonXY &multiPolygon );
//! A helper method to dump to qdebug the geometry of a polygon
void dumpPolygon( QgsPolygonXY &polygon );
void paintPolygon( QgsPolygonXY &polygon );
//! A helper method to dump to qdebug the geometry of a polyline
void dumpPolyline( QgsPolylineXY &polyline );

@@ -252,6 +256,9 @@ void TestQgsGeometry::initTestCase()

void TestQgsGeometry::cleanupTestCase()
{
delete mpPainter;
mpPainter = nullptr;

// Runs once after all tests are run
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
@@ -266,8 +273,10 @@ void TestQgsGeometry::cleanupTestCase()
QgsApplication::exitQgis();
}

void TestQgsGeometry::init()
void TestQgsGeometry::initPainterTest()
{
delete mpPainter;
mpPainter = nullptr;
//
// Reset / reinitialize the geometries before each test is run
//
@@ -318,13 +327,13 @@ void TestQgsGeometry::init()
mPen1.setWidth( 5 );
mPen1.setBrush( Qt::green );
mpPainter->setPen( mPen1 );
dumpPolygon( mPolygonA );
paintPolygon( mPolygonA );
mPen1.setBrush( Qt::red );
mpPainter->setPen( mPen1 );
dumpPolygon( mPolygonB );
paintPolygon( mPolygonB );
mPen1.setBrush( Qt::blue );
mpPainter->setPen( mPen1 );
dumpPolygon( mPolygonC );
paintPolygon( mPolygonC );

mPen2 = QPen();
mPen2.setWidth( 1 );
@@ -341,7 +350,6 @@ void TestQgsGeometry::init()
void TestQgsGeometry::cleanup()
{
// will be called after every testfunction.
delete mpPainter;
}

void TestQgsGeometry::copy()

void TestQgsGeometry::comparePolylines()
{
QgsPointXY point1 = QgsPointXY( 20.0, 20.0 );
QgsPointXY point2 = QgsPointXY( 80.0, 20.0 );
QgsPointXY point3 = QgsPointXY( 80.0, 80.0 );
QgsPointXY point4 = QgsPointXY( 20.0, 80.0 );
QgsPointXY pointA = QgsPointXY( 40.0, 40.0 );

QgsPolylineXY line1;
line1 << mPoint1 << mPoint2 << mPoint3;
line1 << point1 << point2 << point3;
QgsPolylineXY line2;
line2 << mPoint1 << mPoint2 << mPoint3;
line2 << point1 << point2 << point3;
QVERIFY( QgsGeometry::compare( line1, line2 ) );

//different number of nodes
QgsPolylineXY line3;
line3 << mPoint1 << mPoint2 << mPoint3 << mPoint4;
line3 << point1 << point2 << point3 << point4;
QVERIFY( !QgsGeometry::compare( line1, line3 ) );

//different nodes
QgsPolylineXY line4;
line3 << mPoint1 << mPointA << mPoint3 << mPoint4;
line3 << point1 << pointA << point3 << point4;
QVERIFY( !QgsGeometry::compare( line3, line4 ) );
}

void TestQgsGeometry::comparePolygons()
{
QgsPointXY point1 = QgsPointXY( 20.0, 20.0 );
QgsPointXY point2 = QgsPointXY( 80.0, 20.0 );
QgsPointXY point3 = QgsPointXY( 80.0, 80.0 );
QgsPointXY point4 = QgsPointXY( 20.0, 80.0 );
QgsPointXY pointA = QgsPointXY( 40.0, 40.0 );
QgsPointXY pointB = QgsPointXY( 100.0, 40.0 );

QgsPolylineXY ring1;
ring1 << mPoint1 << mPoint2 << mPoint3 << mPoint1;
ring1 << point1 << point2 << point3 << point1;
QgsPolylineXY ring2;
ring2 << mPoint4 << mPointA << mPointB << mPoint4;
ring2 << point4 << pointA << pointB << point4;
QgsPolygonXY poly1;
poly1 << ring1 << ring2;
QgsPolygonXY poly2;
for ( int j = 0; j < emptyStringList.count() ; ++j )
{
QString generatedWkt = spacesBefore + wkt + spacesMiddle + emptyStringList.at( j ) + spacesAfter;
qDebug() << "Generated WKT:" << generatedWkt << " expected: " << result;

QgsGeometry gWkt = QgsGeometry().fromWkt( generatedWkt );
QVERIFY( gWkt.asWkt().compare( result, Qt::CaseInsensitive ) == 0 );

void TestQgsGeometry::createEmptyWithSameType()
{
qDebug( "createEmptyWithSameType(): QgsCircularString" );
testCreateEmptyWithSameType<QgsCircularString>();

qDebug( "createEmptyWithSameType(): QgsCompoundCurve" );
testCreateEmptyWithSameType<QgsCompoundCurve>();

qDebug( "createEmptyWithSameType(): QgsLineString" );
testCreateEmptyWithSameType<QgsLineString>();


qDebug( "createEmptyWithSameType(): QgsGeometryCollection" );
testCreateEmptyWithSameType<QgsGeometryCollection>();

qDebug( "createEmptyWithSameType(): QgsMultiCurve" );
testCreateEmptyWithSameType<QgsMultiCurve>();

qDebug( "createEmptyWithSameType(): QgsMultiLineString" );
testCreateEmptyWithSameType<QgsMultiLineString>();

qDebug( "createEmptyWithSameType(): QgsMultiPointV2" );
testCreateEmptyWithSameType<QgsMultiPoint>();

qDebug( "createEmptyWithSameType(): QgsMultiSurface" );
testCreateEmptyWithSameType<QgsMultiSurface>();


qDebug( "createEmptyWithSameType(): QgsPoint" );
testCreateEmptyWithSameType<QgsPoint>();


qDebug( "createEmptyWithSameType(): QgsCurvePolygon" );
testCreateEmptyWithSameType<QgsCurvePolygon>();

qDebug( "createEmptyWithSameType(): QgsPolygon" );
testCreateEmptyWithSameType<QgsPolygon>();

qDebug( "createEmptyWithSameType(): QgsTriangle" );
testCreateEmptyWithSameType<QgsTriangle>();

}


#if 0
void TestQgsGeometry::simplifyCheck1()
{
initPainterTest();
QVERIFY( mpPolylineGeometryD->simplify( 0.5 ) );
// should be a single polygon as A intersect B
QgsGeometry *mypSimplifyGeometry = mpPolylineGeometryD->simplify( 0.5 );

void TestQgsGeometry::intersectionCheck1()
{
initPainterTest();
QVERIFY( mpPolygonGeometryA.intersects( mpPolygonGeometryB ) );

std::unique_ptr< QgsGeometryEngine > engine( QgsGeometry::createGeometryEngine( mpPolygonGeometryA.constGet() ) );

// should be a single polygon as A intersect B
QgsGeometry mypIntersectionGeometry = mpPolygonGeometryA.intersection( mpPolygonGeometryB );
qDebug() << "Geometry Type: " << QgsWkbTypes::displayString( mypIntersectionGeometry.wkbType() );
QVERIFY( mypIntersectionGeometry.wkbType() == QgsWkbTypes::Polygon );
QgsPolygonXY myPolygon = mypIntersectionGeometry.asPolygon();
QVERIFY( myPolygon.size() > 0 ); //check that the union created a feature
dumpPolygon( myPolygon );
paintPolygon( myPolygon );
QVERIFY( renderCheck( "geometry_intersectionCheck1", "Checking if A intersects B" ) );
}
void TestQgsGeometry::intersectionCheck2()

void TestQgsGeometry::unionCheck1()
{
initPainterTest();
// should be a multipolygon with 2 parts as A does not intersect C
QgsGeometry mypUnionGeometry = mpPolygonGeometryA.combine( mpPolygonGeometryC );
qDebug() << "Geometry Type: " << QgsWkbTypes::displayString( mypUnionGeometry.wkbType() );
QVERIFY( mypUnionGeometry.wkbType() == QgsWkbTypes::MultiPolygon );
QgsMultiPolygonXY myMultiPolygon = mypUnionGeometry.asMultiPolygon();
QVERIFY( myMultiPolygon.size() > 0 ); //check that the union did not fail
dumpMultiPolygon( myMultiPolygon );
paintMultiPolygon( myMultiPolygon );
QVERIFY( renderCheck( "geometry_unionCheck1", "Checking A union C produces 2 polys" ) );
}

void TestQgsGeometry::unionCheck2()
{
initPainterTest();
// should be a single polygon as A intersect B
QgsGeometry mypUnionGeometry = mpPolygonGeometryA.combine( mpPolygonGeometryB );
qDebug() << "Geometry Type: " << QgsWkbTypes::displayString( mypUnionGeometry.wkbType() );
QVERIFY( mypUnionGeometry.wkbType() == QgsWkbTypes::Polygon );
QgsPolygonXY myPolygon = mypUnionGeometry.asPolygon();
QVERIFY( myPolygon.size() > 0 ); //check that the union created a feature
dumpPolygon( myPolygon );
paintPolygon( myPolygon );
QVERIFY( renderCheck( "geometry_unionCheck2", "Checking A union B produces single union poly" ) );
}

void TestQgsGeometry::differenceCheck1()
{
initPainterTest();
// should be same as A since A does not intersect C so diff is 100% of A
QgsGeometry mypDifferenceGeometry( mpPolygonGeometryA.difference( mpPolygonGeometryC ) );
qDebug() << "Geometry Type: " << QgsWkbTypes::displayString( mypDifferenceGeometry.wkbType() );
QVERIFY( mypDifferenceGeometry.wkbType() == QgsWkbTypes::Polygon );
QgsPolygonXY myPolygon = mypDifferenceGeometry.asPolygon();
QVERIFY( myPolygon.size() > 0 ); //check that the union did not fail
dumpPolygon( myPolygon );
paintPolygon( myPolygon );
QVERIFY( renderCheck( "geometry_differenceCheck1", "Checking (A - C) = A" ) );
}

void TestQgsGeometry::differenceCheck2()
{
initPainterTest();
// should be a single polygon as (A - B) = subset of A
QgsGeometry mypDifferenceGeometry( mpPolygonGeometryA.difference( mpPolygonGeometryB ) );
qDebug() << "Geometry Type: " << QgsWkbTypes::displayString( mypDifferenceGeometry.wkbType() );
QVERIFY( mypDifferenceGeometry.wkbType() == QgsWkbTypes::Polygon );
QgsPolygonXY myPolygon = mypDifferenceGeometry.asPolygon();
QVERIFY( myPolygon.size() > 0 ); //check that the union created a feature
dumpPolygon( myPolygon );
paintPolygon( myPolygon );
QVERIFY( renderCheck( "geometry_differenceCheck2", "Checking (A - B) = subset of A" ) );
}
void TestQgsGeometry::bufferCheck()
{
initPainterTest();
// should be a single polygon
QgsGeometry mypBufferGeometry( mpPolygonGeometryB.buffer( 10, 10 ) );
qDebug() << "Geometry Type: " << QgsWkbTypes::displayString( mypBufferGeometry.wkbType() );
QVERIFY( mypBufferGeometry.wkbType() == QgsWkbTypes::Polygon );
QgsPolygonXY myPolygon = mypBufferGeometry.asPolygon();
QVERIFY( myPolygon.size() > 0 ); //check that the buffer created a feature
dumpPolygon( myPolygon );
paintPolygon( myPolygon );
QVERIFY( renderCheck( "geometry_bufferCheck", "Checking buffer(10,10) of B", 10 ) );
}

}
}

void TestQgsGeometry::paintMultiPolygon( QgsMultiPolygonXY &multiPolygon )
{
for ( int i = 0; i < multiPolygon.size(); i++ )
{
QgsPolygonXY myPolygon = multiPolygon.at( i );
paintPolygon( myPolygon );
}
}

void TestQgsGeometry::dumpPolygon( QgsPolygonXY &polygon )
{
QVector<QPointF> myPoints;
for ( int j = 0; j < polygon.size(); j++ )
{
QgsPolylineXY myPolyline = polygon.at( j ); //rings of polygon
{
QgsPointXY myPoint = myPolyline.at( k );
qDebug( "\t\t\tPoint in ring %d : %s", k, myPoint.toString().toLocal8Bit().constData() );
}
}
}

void TestQgsGeometry::paintPolygon( QgsPolygonXY &polygon )
{
QVector<QPointF> myPoints;
for ( int j = 0; j < polygon.size(); j++ )
{
QgsPolylineXY myPolyline = polygon.at( j ); //rings of polygon
for ( int k = 0; k < myPolyline.size(); k++ )
{
QgsPointXY myPoint = myPolyline.at( k );
myPoints << QPointF( myPoint.x(), myPoint.y() );
}
}

void TestQgsGeometry::snappedToGrid()
{
qDebug( "SnappedToGrid" );
// points
{
qDebug( "\tPoints:" );
auto check = []( QgsPoint * _a, QgsPoint const & b )
{
std::unique_ptr<QgsPoint> a {_a};
// because it is to check after snapping, there shouldn't be small precision errors

qDebug( "\t\tGridified point: %f, %f, %f, %f", a->x(), a->y(), a->z(), a->m() );
qDebug( "\t\tExpected point: %f, %f, %f, %f", b.x(), b.y(), b.z(), b.m() );
if ( !std::isnan( b.x() ) )
QVERIFY( ( float )a->x() == ( float )b.x() );

0 comments on commit 65cf6b0

Please sign in to comment.
You can’t perform that action at this time.