Skip to content

Commit ae5651e

Browse files
committedMar 29, 2017
More unit tests
1 parent 55d0ad7 commit ae5651e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
 

‎tests/src/app/testqgsnodetool.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class TestQgsNodeTool : public QObject
5454
void testMoveVertex();
5555
void testMoveEdge();
5656
void testAddVertex();
57+
void testAddVertexAtEndpoint();
5758
void testDeleteVertex();
5859

5960
private:
@@ -63,6 +64,12 @@ class TestQgsNodeTool : public QObject
6364
return QPoint( qRound( pt.x() ), qRound( pt.y() ) );
6465
}
6566

67+
void mouseMove( double mapX, double mapY )
68+
{
69+
QgsMapMouseEvent e( mCanvas, QEvent::MouseMove, mapToScreen( mapX, mapY ) );
70+
mNodeTool->cadCanvasMoveEvent( &e );
71+
}
72+
6673
void mouseClick( double mapX, double mapY, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
6774
{
6875
QgsMapMouseEvent e1( mCanvas, QEvent::MouseButtonPress, mapToScreen( mapX, mapY ), button, button, stateKey );
@@ -170,6 +177,8 @@ void TestQgsNodeTool::initTestCase()
170177

171178
mCanvas->setLayers( QList<QgsMapLayer*>() << mLayerLine << mLayerPolygon << mLayerPoint );
172179

180+
qApp->processEvents(); // will this fix travis?
181+
173182
// TODO: set up snapping
174183

175184
// create node tool
@@ -195,6 +204,8 @@ void TestQgsNodeTool::testMoveVertex()
195204
mouseClick( 2, 1, Qt::LeftButton );
196205
mouseClick( 2, 2, Qt::LeftButton );
197206

207+
qApp->processEvents(); // will this fix travis?
208+
198209
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
199210
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 1 1, 1 3)" ) );
200211

@@ -330,6 +341,41 @@ void TestQgsNodeTool::testAddVertex()
330341
}
331342

332343

344+
void TestQgsNodeTool::testAddVertexAtEndpoint()
345+
{
346+
// offset of the endpoint marker - currently set as 15px away from the last node in direction of the line
347+
double offsetInMapUnits = 15 * mCanvas->mapSettings().mapUnitsPerPixel();
348+
349+
// add vertex at the end
350+
351+
mouseMove( 1, 3 ); // first we need to move to the vertex
352+
mouseClick( 1, 3 + offsetInMapUnits, Qt::LeftButton );
353+
mouseClick( 2, 3, Qt::LeftButton );
354+
355+
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
356+
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3, 2 3)" ) );
357+
358+
mLayerLine->undoStack()->undo();
359+
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
360+
361+
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
362+
363+
// add vertex at the start
364+
365+
mouseMove( 2, 1 ); // first we need to move to the vertex
366+
mouseClick( 2 + offsetInMapUnits, 1, Qt::LeftButton );
367+
mouseClick( 2, 2, Qt::LeftButton );
368+
369+
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
370+
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 2 1, 1 1, 1 3)" ) );
371+
372+
mLayerLine->undoStack()->undo();
373+
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
374+
375+
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
376+
}
377+
378+
333379
void TestQgsNodeTool::testDeleteVertex()
334380
{
335381
// delete vertex in linestring

0 commit comments

Comments
 (0)
Please sign in to comment.