Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
i-s-o authored and nirvn committed Jan 10, 2020
1 parent 662ede5 commit 1b920ca
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/src/app/testqgisappclipboard.cpp
Expand Up @@ -331,6 +331,40 @@ void TestQgisAppClipboard::pasteWkt()
QCOMPARE( features.at( 2 ).attributes().at( 0 ).toString(), QStringLiteral( "2" ) );
QCOMPARE( features.at( 2 ).attributes().at( 1 ).toString(), QStringLiteral( "b2" ) );
QCOMPARE( features.at( 2 ).attributes().at( 2 ).toString(), QStringLiteral( "3" ) );

// when a set of features is built outside of QGIS, last one might be terminated by newline
// https://github.com/qgis/QGIS/issues/33617
mQgisApp->clipboard()->setText( QStringLiteral( "POINT (125 10)\nPOINT (111 30)\n" ) );
features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 2 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
featureGeom = features.at( 0 ).geometry();
point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< const QgsPoint * >( features.at( 1 ).geometry().constGet() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );

// on MS Windows, the <EOL> marker is CRLF
// https://github.com/qgis/QGIS/pull/33618#discussion_r363147854
mQgisApp->clipboard()->setText( QStringLiteral( "POINT (125 10)\r\nPOINT (111 30)\r\n" ) );
features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 2 );
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
featureGeom = features.at( 0 ).geometry();
point = dynamic_cast< const QgsPoint * >( featureGeom.constGet() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );
QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
QCOMPARE( features.at( 1 ).geometry().constGet()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< const QgsPoint * >( features.at( 1 ).geometry().constGet() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );
}

void TestQgisAppClipboard::pasteGeoJson()
Expand Down

0 comments on commit 1b920ca

Please sign in to comment.