From c1771a78ed0ceab26891b3fdf801dc5557173fac Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 11 Mar 2013 13:58:35 +0100 Subject: Correct QString's warnings involving QRegularExpression. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces "QRegularExpresssion" with "QRegularExpression" and adds some auto tests for the warning itself. Task-number: QTBUG-30054 Change-Id: Iba333a4388795eccca809fb430c295f503794263 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 8e30a66d6f..7b7869d033 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -156,6 +156,7 @@ private slots: void count(); void lastIndexOf_data(); void lastIndexOf(); + void lastIndexOfInvalidRegex(); void indexOf_data(); void indexOf(); void indexOf2_data(); @@ -633,6 +634,7 @@ void tst_QString::replace_regexp_data() << QString("a9a8a7a6a5nmlkjii0hh0gg0ff0ee0dd0cc0bb0a"); QTest::newRow("backref10") << QString("abc") << QString("((((((((((((((abc))))))))))))))") << QString("\\0\\01\\011") << QString("\\0\\01\\011"); + QTest::newRow("invalid") << QString("") << QString("invalid regex\\") << QString("") << QString(""); } void tst_QString::utf8_data() @@ -1379,6 +1381,12 @@ void tst_QString::lastIndexOf() } } +void tst_QString::lastIndexOfInvalidRegex() +{ + QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object"); + QCOMPARE(QString("").lastIndexOf(QRegularExpression("invalid regex\\"), 0), -1); +} + void tst_QString::count() { QString a; @@ -1396,7 +1404,8 @@ void tst_QString::count() QCOMPARE(a.count(QRegExp("[G][HE]")),2); QCOMPARE(a.count(QRegularExpression("[FG][HI]")), 1); QCOMPARE(a.count(QRegularExpression("[G][HE]")), 2); - + QTest::ignoreMessage(QtWarningMsg, "QString::count: invalid QRegularExpression object"); + QCOMPARE(a.count(QRegularExpression("invalid regex\\")), 0); CREATE_REF(QLatin1String("FG")); QCOMPARE(a.count(ref),2); @@ -1432,6 +1441,8 @@ void tst_QString::contains() QStringRef emptyRef(&a, 0, 0); QVERIFY(a.contains(emptyRef, Qt::CaseInsensitive)); + QTest::ignoreMessage(QtWarningMsg, "QString::contains: invalid QRegularExpression object"); + QVERIFY(!a.contains(QRegularExpression("invalid regex\\"))); } @@ -2342,7 +2353,10 @@ void tst_QString::replace_regexp() s2.replace( QRegExp(regexp), after ); QTEST( s2, "result" ); s2 = string; - s2.replace( QRegularExpression(regexp), after ); + QRegularExpression regularExpression(regexp); + if (!regularExpression.isValid()) + QTest::ignoreMessage(QtWarningMsg, "QString::replace: invalid QRegularExpression object"); + s2.replace( regularExpression, after ); QTEST( s2, "result" ); } -- cgit v1.2.3