Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 29, 2017
1 parent 55d0ad7 commit ae5651e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/src/app/testqgsnodetool.cpp
Expand Up @@ -54,6 +54,7 @@ class TestQgsNodeTool : public QObject
void testMoveVertex();
void testMoveEdge();
void testAddVertex();
void testAddVertexAtEndpoint();
void testDeleteVertex();

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

void mouseMove( double mapX, double mapY )
{
QgsMapMouseEvent e( mCanvas, QEvent::MouseMove, mapToScreen( mapX, mapY ) );
mNodeTool->cadCanvasMoveEvent( &e );
}

void mouseClick( double mapX, double mapY, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
{
QgsMapMouseEvent e1( mCanvas, QEvent::MouseButtonPress, mapToScreen( mapX, mapY ), button, button, stateKey );
Expand Down Expand Up @@ -170,6 +177,8 @@ void TestQgsNodeTool::initTestCase()

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

qApp->processEvents(); // will this fix travis?

// TODO: set up snapping

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

qApp->processEvents(); // will this fix travis?

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 1 1, 1 3)" ) );

Expand Down Expand Up @@ -330,6 +341,41 @@ void TestQgsNodeTool::testAddVertex()
}


void TestQgsNodeTool::testAddVertexAtEndpoint()
{
// offset of the endpoint marker - currently set as 15px away from the last node in direction of the line
double offsetInMapUnits = 15 * mCanvas->mapSettings().mapUnitsPerPixel();

// add vertex at the end

mouseMove( 1, 3 ); // first we need to move to the vertex
mouseClick( 1, 3 + offsetInMapUnits, Qt::LeftButton );
mouseClick( 2, 3, Qt::LeftButton );

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3, 2 3)" ) );

mLayerLine->undoStack()->undo();
QCOMPARE( mLayerLine->undoStack()->index(), 1 );

QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );

// add vertex at the start

mouseMove( 2, 1 ); // first we need to move to the vertex
mouseClick( 2 + offsetInMapUnits, 1, Qt::LeftButton );
mouseClick( 2, 2, Qt::LeftButton );

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 2 1, 1 1, 1 3)" ) );

mLayerLine->undoStack()->undo();
QCOMPARE( mLayerLine->undoStack()->index(), 1 );

QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
}


void TestQgsNodeTool::testDeleteVertex()
{
// delete vertex in linestring
Expand Down

0 comments on commit ae5651e

Please sign in to comment.