Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Feb 3, 2020
1 parent 40f7c87 commit 2331b8e
Show file tree
Hide file tree
Showing 4 changed files with 413 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/src/app/testqgsmaptoolcircle.cpp
Expand Up @@ -40,8 +40,11 @@ class TestQgsMapToolCircle : public QObject
void cleanupTestCase();

void testCircleFrom2Points();
void testCircleFrom2PointsWithDeletedVertex();
void testCircleFrom3Points();
void testCircleFrom3PointsWithDeletedVertex();
void testCircleFromCenterPoint();
void testCircleFromCenterPointWithDeletedVertex();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -105,6 +108,33 @@ void TestQgsMapToolCircle::testCircleFrom2Points()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFrom2PointsWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
mLayer->startEditing();

QgsMapToolCircle2Points mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );

utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseMove( 0, 2 );
utils.mouseClick( 0, 2, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ (CircularStringZ (0 2 333, 1 1 333, 0 0 333, -1 1 333, 0 2 333))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFrom3Points()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 111 );
Expand All @@ -130,6 +160,33 @@ void TestQgsMapToolCircle::testCircleFrom3Points()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFrom3PointsWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 111 );
mLayer->startEditing();

QgsMapToolCircle3Points mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 2, Qt::LeftButton );
utils.mouseMove( 1, 1 );
utils.mouseClick( 1, 1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ (CircularStringZ (0 2 111, 1 1 111, 0 0 111, -1 1 111, 0 2 111))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFromCenterPoint()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
Expand All @@ -154,5 +211,32 @@ void TestQgsMapToolCircle::testCircleFromCenterPoint()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircle::testCircleFromCenterPointWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
mLayer->startEditing();

QgsMapToolCircleCenterPoint mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );

utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseMove( 0, 2 );
utils.mouseClick( 0, 2, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ (CircularStringZ (0 2 222, 2 0 222, 0 -2 222, -2 0 222, 0 2 222))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

QGSTEST_MAIN( TestQgsMapToolCircle )
#include "testqgsmaptoolcircle.moc"
130 changes: 130 additions & 0 deletions tests/src/app/testqgsmaptoolellipse.cpp
Expand Up @@ -42,9 +42,13 @@ class TestQgsMapToolEllipse : public QObject
void cleanupTestCase();

void testEllipseFromCenterAndPoint();
void testEllipseFromCenterAndPointWithDeletedVertex();
void testEllipseFromCenterAnd2Points();
void testEllipseFromCenterAnd2PointsWithDeletedVertex();
void testEllipseFromExtent();
void testEllipseFromExtentWithDeletedVertex();
void testEllipseFromFoci();
void testEllipseFromFociWithDeletedVertex();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -112,6 +116,37 @@ void TestQgsMapToolEllipse::testEllipseFromCenterAndPoint()
mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}
void TestQgsMapToolEllipse::testEllipseFromCenterAndPointWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
mLayer->startEditing();

QgsMapToolEllipseCenterPoint mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseMove( 1, -1 );
utils.mouseClick( 1, -1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = f.geometry().asWkt().replace( "LineStringZ (", "" ).replace( ")", "" );
QgsPointSequence pts = QgsGeometryUtils::pointsFromWKT( wkt, true, false );

for ( const QgsPoint &pt : pts )
{
QCOMPARE( pt.z(), ( double )333 );
}

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}


void TestQgsMapToolEllipse::testEllipseFromCenterAnd2Points()
{
Expand Down Expand Up @@ -143,6 +178,38 @@ void TestQgsMapToolEllipse::testEllipseFromCenterAnd2Points()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolEllipse::testEllipseFromCenterAnd2PointsWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 111 );
mLayer->startEditing();

QgsMapToolEllipseCenter2Points mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseClick( 0, 1, Qt::LeftButton );
utils.mouseMove( 0, -1 );
utils.mouseClick( 0, -1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = f.geometry().asWkt().replace( "LineStringZ (", "" ).replace( ")", "" );
QgsPointSequence pts = QgsGeometryUtils::pointsFromWKT( wkt, true, false );

for ( const QgsPoint &pt : pts )
{
QCOMPARE( pt.z(), ( double )111 );
}

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolEllipse::testEllipseFromExtent()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
Expand Down Expand Up @@ -172,6 +239,37 @@ void TestQgsMapToolEllipse::testEllipseFromExtent()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolEllipse::testEllipseFromExtentWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
mLayer->startEditing();

QgsMapToolEllipseExtent mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseMove( 2, 2 );
utils.mouseClick( 2, 2, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = f.geometry().asWkt().replace( "LineStringZ (", "" ).replace( ")", "" );
QgsPointSequence pts = QgsGeometryUtils::pointsFromWKT( wkt, true, false );

for ( const QgsPoint &pt : pts )
{
QCOMPARE( pt.z(), ( double )222 );
}

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolEllipse::testEllipseFromFoci()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 444 );
Expand Down Expand Up @@ -202,5 +300,37 @@ void TestQgsMapToolEllipse::testEllipseFromFoci()
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolEllipse::testEllipseFromFociWithDeletedVertex()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 444 );
mLayer->startEditing();

QgsMapToolEllipseFoci mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.keyClick( Qt::Key_Backspace );
utils.mouseClick( 0, 0, Qt::LeftButton );
utils.mouseClick( 0, 2, Qt::LeftButton );
utils.mouseMove( 0, -1 );
utils.mouseClick( 0, -1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = f.geometry().asWkt().replace( "LineStringZ (", "" ).replace( ")", "" );
QgsPointSequence pts = QgsGeometryUtils::pointsFromWKT( wkt, true, false );

for ( const QgsPoint &pt : pts )
{
QCOMPARE( pt.z(), ( double )444 );
}

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

QGSTEST_MAIN( TestQgsMapToolEllipse )
#include "testqgsmaptoolellipse.moc"

0 comments on commit 2331b8e

Please sign in to comment.