Skip to content
Permalink
Browse files
rewrite test to avoid some noise
  • Loading branch information
lbartoletti committed May 17, 2021
1 parent 40b635f commit ed93757bd5931c5f6d5a6efcdd7e9feb7c523b38
Showing with 34 additions and 35 deletions.
  1. +34 −35 tests/src/app/testqgsvertextool.cpp
@@ -161,7 +161,6 @@ class TestQgsVertexTool : public QObject
QgsFeatureId mFidMultiLineF1 = 0;
QgsFeatureId mFidLineF13857 = 0;
QgsFeatureId mFidPolygonF1 = 0;
QgsFeatureId mFidPolygonF2 = 0;
QgsFeatureId mFidMultiPolygonF1 = 0;
QgsFeatureId mFidPointF1 = 0;
QgsFeatureId mFidCompoundCurveF1 = 0;
@@ -231,13 +230,6 @@ void TestQgsVertexTool::initTestCase()
QgsFeature polygonF1;
polygonF1.setGeometry( QgsGeometry::fromPolygonXY( polygon1 ) );

QgsPolygonXY polygon2;
QgsPolylineXY polygon2exterior;
polygon2exterior << QgsPointXY( 8, 1 ) << QgsPointXY( 9, 1 ) << QgsPointXY( 9, 4 ) << QgsPointXY( 8, 4 ) << QgsPointXY( 8, 1 );
polygon2 << polygon2exterior;
QgsFeature polygonF2;
polygonF2.setGeometry( QgsGeometry::fromPolygonXY( polygon2 ) );

QgsFeature multiPolygonF1;
multiPolygonF1.setGeometry( QgsGeometry::fromWkt( "MultiPolygon (((1 5, 2 5, 2 6.5, 2 8, 1 8, 1 6.5, 1 5),(1.25 5.5, 1.25 6, 1.75 6, 1.75 5.5, 1.25 5.5),(1.25 7, 1.75 7, 1.75 7.5, 1.25 7.5, 1.25 7)),((3 5, 3 6.5, 3 8, 4 8, 4 6.5, 4 5, 3 5),(3.25 5.5, 3.75 5.5, 3.75 6, 3.25 6, 3.25 5.5),(3.25 7, 3.75 7, 3.75 7.5, 3.25 7.5, 3.25 7)))" ) );

@@ -286,10 +278,6 @@ void TestQgsVertexTool::initTestCase()
mFidPolygonF1 = polygonF1.id();
QCOMPARE( mLayerPolygon->featureCount(), ( long )1 );

mLayerPolygon->addFeature( polygonF2 );
mFidPolygonF2 = polygonF2.id();
QCOMPARE( mLayerPolygon->featureCount(), ( long )2 );

mLayerMultiPolygon->startEditing();
mLayerMultiPolygon->addFeature( multiPolygonF1 );
mFidMultiPolygonF1 = multiPolygonF1.id();
@@ -317,7 +305,7 @@ void TestQgsVertexTool::initTestCase()
// just one added feature in each undo stack
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerMultiLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerMultiPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );
// except for layerLineZ
@@ -452,7 +440,7 @@ void TestQgsVertexTool::testMoveVertex()
mouseClick( 4, 1, Qt::LeftButton );
mouseClick( 5, 2, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((5 2, 7 1, 7 4, 4 4, 5 2))" ) );

mLayerPolygon->undoStack()->undo();
@@ -462,7 +450,7 @@ void TestQgsVertexTool::testMoveVertex()
mouseClick( 4, 4, Qt::LeftButton );
mouseClick( 5, 5, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 5 5, 4 1))" ) );

mLayerPolygon->undoStack()->undo();
@@ -482,7 +470,7 @@ void TestQgsVertexTool::testMoveVertex()

// no other unexpected changes happened
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );
}

@@ -506,7 +494,7 @@ void TestQgsVertexTool::testMoveEdge()
mouseClick( 5, 1, Qt::LeftButton );
mouseClick( 6, 1, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((5 1, 8 1, 7 4, 4 4, 5 1))" ) );

mLayerPolygon->undoStack()->undo();
@@ -515,7 +503,7 @@ void TestQgsVertexTool::testMoveEdge()

// no other unexpected changes happened
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );
}

@@ -539,7 +527,7 @@ void TestQgsVertexTool::testAddVertex()
mouseClick( 4, 2.5, Qt::LeftButton );
mouseClick( 3, 2.5, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 3 2.5, 4 1))" ) );

mLayerPolygon->undoStack()->undo();
@@ -548,7 +536,7 @@ void TestQgsVertexTool::testAddVertex()

// no other unexpected changes happened
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );
}

@@ -627,7 +615,7 @@ void TestQgsVertexTool::testAddVertexDoubleClick()
mouseDoubleClick( 4, 2, Qt::LeftButton );
mouseClick( 3, 2.5, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 3 2.5, 4 1))" ) );

mLayerPolygon->undoStack()->undo();
@@ -636,7 +624,7 @@ void TestQgsVertexTool::testAddVertexDoubleClick()

// no other unexpected changes happened
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );

}
@@ -658,7 +646,7 @@ void TestQgsVertexTool::testAddVertexDoubleClickWithShift()
// add vertex in polygon
mouseDoubleClick( 4, 2, Qt::LeftButton, Qt::ShiftModifier );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 2, 4 1))" ) );

mLayerPolygon->undoStack()->undo();
@@ -667,7 +655,7 @@ void TestQgsVertexTool::testAddVertexDoubleClickWithShift()

// no other unexpected changes happened
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );

}
@@ -692,7 +680,7 @@ void TestQgsVertexTool::testDeleteVertex()
mouseClick( 7, 4, Qt::LeftButton );
keyClick( Qt::Key_Delete );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 4 4, 4 1))" ) );

mLayerPolygon->undoStack()->undo();
@@ -806,7 +794,7 @@ void TestQgsVertexTool::testDeleteVertex()

// no other unexpected changes happened
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
QCOMPARE( mLayerPoint->undoStack()->index(), 1 );
}

@@ -874,7 +862,7 @@ void TestQgsVertexTool::testMoveVertexTopo()
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((3 3, 7 1, 7 4, 4 4, 3 3))" ) );

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 4 ); // one more move of vertex from earlier
QCOMPARE( mLayerPolygon->undoStack()->index(), 3 ); // one more move of vertex from earlier
mLayerLine->undoStack()->undo();
mLayerPolygon->undoStack()->undo();
mLayerPolygon->undoStack()->undo();
@@ -903,7 +891,7 @@ void TestQgsVertexTool::testDeleteVertexTopo()
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((7 1, 7 4, 4 4, 7 1))" ) );

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 4 ); // one more move of vertex from earlier
QCOMPARE( mLayerPolygon->undoStack()->index(), 3 ); // one more move of vertex from earlier
mLayerLine->undoStack()->undo();
mLayerPolygon->undoStack()->undo();
mLayerPolygon->undoStack()->undo();
@@ -925,14 +913,14 @@ void TestQgsVertexTool::testAddVertexTopo()
QVERIFY( resAdd );
QgsFeatureId fTmpId = fTmp.id();

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );

QgsProject::instance()->setTopologicalEditing( true );

mouseClick( 5.5, 4, Qt::LeftButton );
mouseClick( 5, 5, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 4 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );

QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 5 5, 4 4, 4 1))" ) );
QCOMPARE( mLayerPolygon->getFeature( fTmpId ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 4, 5 5, 7 4, 7 6, 4 6, 4 4))" ) );
@@ -956,15 +944,15 @@ void TestQgsVertexTool::testMoveEdgeTopo()
QVERIFY( resAdd );
QgsFeatureId fTmpId = fTmp.id();

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );

QgsProject::instance()->setTopologicalEditing( true );

// move shared segment
mouseClick( 6, 4, Qt::LeftButton );
mouseClick( 6, 5, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 4 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );

QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 5, 4 5, 4 1))" ) );
QCOMPARE( mLayerPolygon->getFeature( fTmpId ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 5, 7 5, 7 6, 4 6, 4 5))" ) );
@@ -986,7 +974,7 @@ void TestQgsVertexTool::testMoveEdgeTopo()
mouseClick( 4, 4, Qt::LeftButton );
mouseClick( 4, 3, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 4 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );

QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 3, 4 3, 4 1))" ) );
QCOMPARE( mLayerPolygon->getFeature( fTmpId ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 3, 7 3, 7 6, 4 6, 4 3))" ) );
@@ -1012,7 +1000,7 @@ void TestQgsVertexTool::testAddVertexTopoFirstSegment()
mouseClick( 5.5, 1, Qt::LeftButton );
mouseClick( 5, 2, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 2 );

QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 5 2, 7 1, 7 4, 4 4, 4 1))" ) );

@@ -1032,14 +1020,25 @@ void TestQgsVertexTool::testAvoidIntersections()
QgsProject::AvoidIntersectionsMode mode( QgsProject::instance()->avoidIntersectionsMode() );
QgsProject::instance()->setAvoidIntersectionsMode( QgsProject::AvoidIntersectionsMode::AvoidIntersectionsCurrentLayer );

QgsPolygonXY polygon2;
QgsPolylineXY polygon2exterior;
polygon2exterior << QgsPointXY( 8, 1 ) << QgsPointXY( 9, 1 ) << QgsPointXY( 9, 4 ) << QgsPointXY( 8, 4 ) << QgsPointXY( 8, 1 );
polygon2 << polygon2exterior;
QgsFeature polygonF2;
polygonF2.setGeometry( QgsGeometry::fromPolygonXY( polygon2 ) );

mLayerPolygon->addFeature( polygonF2 );
QCOMPARE( mLayerPolygon->featureCount(), ( long )2 );

mouseClick( 6.5, 1, Qt::LeftButton );
mouseClick( 9, 2, Qt::LeftButton );

QCOMPARE( mLayerPolygon->undoStack()->index(), 3 );

QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry().asWkt( 1 ), "MultiPolygon (((4 4, 7 4, 8 3.2, 8 2, 6.5 2, 4 4)),((9 2.4, 9.5 2, 9 2, 9 2.4)))" );
QCOMPARE( QgsGeometry::fromWkt( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry().asWkt( 1 ) ), QgsGeometry::fromWkt( "MultiPolygon (((4 4, 7 4, 8 3.2, 8 2, 6.5 2, 4 4)),((9 2.4, 9.5 2, 9 2, 9 2.4)))" ) ); // avoid rounding errors

mLayerPolygon->undoStack()->undo();
mLayerPolygon->undoStack()->undo(); // delete feature

QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );

0 comments on commit ed93757

Please sign in to comment.