QString: adapt chop() auto test as data-driven test

Thiago Macieira asked to do that.

Change-Id: I9a07dad7ff2bfebc2f863e0e9f151aab66450bcf
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Anton Kudryavtsev 2016-07-08 11:27:50 +03:00
parent a0bb2fc406
commit e27c07389b

View File

@ -482,6 +482,7 @@ private slots:
void sprintf(); void sprintf();
void fill(); void fill();
void truncate(); void truncate();
void chop_data();
void chop(); void chop();
void constructor(); void constructor();
void constructorQByteArray_data(); void constructorQByteArray_data();
@ -1222,29 +1223,29 @@ void tst_QString::truncate()
} }
void tst_QString::chop() void tst_QString::chop_data()
{ {
QTest::addColumn<QString>("input");
QTest::addColumn<int>("count" );
QTest::addColumn<QString>("result");
const QString original("abcd"); const QString original("abcd");
QString str = original; QTest::newRow("data0") << original << 1 << QString("abc");
str.chop(1); QTest::newRow("data1") << original << 0 << original;
QCOMPARE(str, QLatin1String("abc")); QTest::newRow("data2") << original << -1 << original;
QTest::newRow("data3") << original << original.size() << QString();
QTest::newRow("data4") << original << 1000 << QString();
}
str = original; void tst_QString::chop()
str.chop(0); {
QCOMPARE(str, original); QFETCH(QString, input);
QFETCH(int, count);
QFETCH(QString, result);
str = original; input.chop(count);
str.chop(-1); QCOMPARE(input, result);
QCOMPARE(str, original);
str = original;
str.chop(original.size());
QVERIFY(str.isEmpty());
str = original;
str.chop(1000);
QVERIFY(str.isEmpty());
} }
void tst_QString::fill() void tst_QString::fill()