Skip to content

Commit 079c9fa

Browse files
committed
Expand unit test coverage
1 parent ac193d0 commit 079c9fa

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

src/app/qgsclipboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString &string, const Q
210210
// previous QgsOgrUtils::stringToFeatureList call
211211
// Get the first value of a \t separated list. WKT clipboard pasted
212212
// feature has first element the WKT geom.
213-
// This split is to fix te following issue: https://issues.qgis.org/issues/16870
213+
// This split is to fix the following issue: https://issues.qgis.org/issues/16870
214214
// Value separators are set in generateClipboardText
215215
QStringList fieldValues = row.split( '\t' );
216216
if ( fieldValues.isEmpty() )

tests/src/app/testqgisappclipboard.cpp

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,77 @@ void TestQgisAppClipboard::pasteWkt()
241241
QCOMPARE( point->x(), 125.0 );
242242
QCOMPARE( point->y(), 10.0 );
243243

244-
//clipboard now supports features without geometry
245-
mQgisApp->clipboard()->setText( QStringLiteral( "MNL 11 282 km \nMNL 11 347.80000000000001 km " ) );
244+
//clipboard should support features without geometry
245+
mQgisApp->clipboard()->setText( QStringLiteral( "\tMNL\t11\t282\tkm\t\t\t\n\tMNL\t11\t347.80000000000001\tkm\t\t\t" ) );
246246
features = mQgisApp->clipboard()->copyOf();
247247
QCOMPARE( features.length(), 2 );
248+
QVERIFY( !features.at( 0 ).hasGeometry() );
249+
QCOMPARE( features.at( 0 ).attributes().count(), 7 );
250+
QCOMPARE( features.at( 0 ).attributes().at( 0 ).toString(), QStringLiteral( "MNL" ) );
251+
QCOMPARE( features.at( 0 ).attributes().at( 1 ).toString(), QStringLiteral( "11" ) );
252+
QCOMPARE( features.at( 0 ).attributes().at( 2 ).toString(), QStringLiteral( "282" ) );
253+
QCOMPARE( features.at( 0 ).attributes().at( 3 ).toString(), QStringLiteral( "km" ) );
254+
QVERIFY( features.at( 0 ).attributes().at( 4 ).toString().isEmpty() );
255+
QVERIFY( features.at( 0 ).attributes().at( 5 ).toString().isEmpty() );
256+
QVERIFY( features.at( 0 ).attributes().at( 6 ).toString().isEmpty() );
257+
QVERIFY( !features.at( 1 ).hasGeometry() );
258+
QCOMPARE( features.at( 1 ).attributes().count(), 7 );
259+
QCOMPARE( features.at( 1 ).attributes().at( 0 ).toString(), QStringLiteral( "MNL" ) );
260+
QCOMPARE( features.at( 1 ).attributes().at( 1 ).toString(), QStringLiteral( "11" ) );
261+
QCOMPARE( features.at( 1 ).attributes().at( 2 ).toString(), QStringLiteral( "347.80000000000001" ) );
262+
QCOMPARE( features.at( 1 ).attributes().at( 3 ).toString(), QStringLiteral( "km" ) );
263+
QVERIFY( features.at( 1 ).attributes().at( 4 ).toString().isEmpty() );
264+
QVERIFY( features.at( 1 ).attributes().at( 5 ).toString().isEmpty() );
265+
QVERIFY( features.at( 1 ).attributes().at( 6 ).toString().isEmpty() );
266+
267+
mQgisApp->clipboard()->setText( QStringLiteral( "wkt_geom\ta\tb\tc\n\tMNL\t11\t282\tkm\t\t\t\n\tMNL\t11\t347.80000000000001\tkm\t\t\t" ) );
268+
features = mQgisApp->clipboard()->copyOf();
269+
QCOMPARE( features.length(), 2 );
270+
QVERIFY( !features.at( 0 ).hasGeometry() );
271+
QCOMPARE( features.at( 0 ).fields().count(), 3 );
272+
QCOMPARE( features.at( 0 ).fields().at( 0 ).name(), QStringLiteral( "a" ) );
273+
QCOMPARE( features.at( 0 ).fields().at( 1 ).name(), QStringLiteral( "b" ) );
274+
QCOMPARE( features.at( 0 ).fields().at( 2 ).name(), QStringLiteral( "c" ) );
275+
QCOMPARE( features.at( 0 ).attributes().count(), 7 );
276+
QCOMPARE( features.at( 0 ).attributes().at( 0 ).toString(), QStringLiteral( "MNL" ) );
277+
QCOMPARE( features.at( 0 ).attributes().at( 1 ).toString(), QStringLiteral( "11" ) );
278+
QCOMPARE( features.at( 0 ).attributes().at( 2 ).toString(), QStringLiteral( "282" ) );
279+
QCOMPARE( features.at( 0 ).attributes().at( 3 ).toString(), QStringLiteral( "km" ) );
280+
QVERIFY( features.at( 0 ).attributes().at( 4 ).toString().isEmpty() );
281+
QVERIFY( features.at( 0 ).attributes().at( 5 ).toString().isEmpty() );
282+
QVERIFY( features.at( 0 ).attributes().at( 6 ).toString().isEmpty() );
283+
QVERIFY( !features.at( 1 ).hasGeometry() );
284+
QCOMPARE( features.at( 1 ).attributes().count(), 7 );
285+
QCOMPARE( features.at( 1 ).attributes().at( 0 ).toString(), QStringLiteral( "MNL" ) );
286+
QCOMPARE( features.at( 1 ).attributes().at( 1 ).toString(), QStringLiteral( "11" ) );
287+
QCOMPARE( features.at( 1 ).attributes().at( 2 ).toString(), QStringLiteral( "347.80000000000001" ) );
288+
QCOMPARE( features.at( 1 ).attributes().at( 3 ).toString(), QStringLiteral( "km" ) );
289+
QVERIFY( features.at( 1 ).attributes().at( 4 ).toString().isEmpty() );
290+
QVERIFY( features.at( 1 ).attributes().at( 5 ).toString().isEmpty() );
291+
QVERIFY( features.at( 1 ).attributes().at( 6 ).toString().isEmpty() );
292+
293+
mQgisApp->clipboard()->setText( QStringLiteral( "wkt_geom\ta\tb\tc\nNULL\t1\tb\t2\nNULL\t3\tc3\t4\nPoint (5 4)\t2\tb2\t3" ) );
294+
features = mQgisApp->clipboard()->copyOf();
295+
QCOMPARE( features.length(), 3 );
296+
QCOMPARE( features.at( 0 ).fields().count(), 3 );
297+
QCOMPARE( features.at( 0 ).fields().at( 0 ).name(), QStringLiteral( "a" ) );
298+
QCOMPARE( features.at( 0 ).fields().at( 1 ).name(), QStringLiteral( "b" ) );
299+
QCOMPARE( features.at( 0 ).fields().at( 2 ).name(), QStringLiteral( "c" ) );
300+
QVERIFY( !features.at( 0 ).hasGeometry() );
301+
QCOMPARE( features.at( 0 ).attributes().count(), 3 );
302+
QCOMPARE( features.at( 0 ).attributes().at( 0 ).toString(), QStringLiteral( "1" ) );
303+
QCOMPARE( features.at( 0 ).attributes().at( 1 ).toString(), QStringLiteral( "b" ) );
304+
QCOMPARE( features.at( 0 ).attributes().at( 2 ).toString(), QStringLiteral( "2" ) );
305+
QVERIFY( !features.at( 1 ).hasGeometry() );
306+
QCOMPARE( features.at( 1 ).attributes().count(), 3 );
307+
QCOMPARE( features.at( 1 ).attributes().at( 0 ).toString(), QStringLiteral( "3" ) );
308+
QCOMPARE( features.at( 1 ).attributes().at( 1 ).toString(), QStringLiteral( "c3" ) );
309+
QCOMPARE( features.at( 1 ).attributes().at( 2 ).toString(), QStringLiteral( "4" ) );
310+
QCOMPARE( features.at( 2 ).geometry().asWkt(), QStringLiteral( "Point (5 4)" ) );
311+
QCOMPARE( features.at( 2 ).attributes().count(), 3 );
312+
QCOMPARE( features.at( 2 ).attributes().at( 0 ).toString(), QStringLiteral( "2" ) );
313+
QCOMPARE( features.at( 2 ).attributes().at( 1 ).toString(), QStringLiteral( "b2" ) );
314+
QCOMPARE( features.at( 2 ).attributes().at( 2 ).toString(), QStringLiteral( "3" ) );
248315
}
249316

250317
void TestQgisAppClipboard::pasteGeoJson()

0 commit comments

Comments
 (0)