Skip to content
Permalink
Browse files
More unit tests
  • Loading branch information
wonder-sk committed Mar 29, 2017
1 parent 55d0ad7 commit ae5651e41fd97168ad6ca5ab069c78f4ece93383
Showing with 46 additions and 0 deletions.
  1. +46 −0 tests/src/app/testqgsnodetool.cpp
@@ -54,6 +54,7 @@ class TestQgsNodeTool : public QObject
void testMoveVertex();
void testMoveEdge();
void testAddVertex();
void testAddVertexAtEndpoint();
void testDeleteVertex();

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

@@ -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

0 comments on commit ae5651e

Please sign in to comment.