diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 12:01:25 +0100 |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 12:02:41 +0100 |
commit | 79f2480c868523a7d8ffc9fb15055e8eab3237ba (patch) | |
tree | 8336143e8c09810dc97324970fed61af27e26a97 /tests/auto/corelib/tools | |
parent | 7e4f32993498db0e06346e32458a1ec7d0c7b3ec (diff) | |
parent | 12f221410fbe41d0b2efda4cd3289dfcf9044aa8 (diff) |
Merge remote-tracking branch 'origin/api_changes' into containters
Conflicts:
src/corelib/kernel/qmetaobject.cpp
src/corelib/kernel/qvariant.cpp
src/tools/moc/moc.h
Change-Id: I2cd3d95b41d2636738c6b98064864941e3b0b4e6
Diffstat (limited to 'tests/auto/corelib/tools')
18 files changed, 1688 insertions, 152 deletions
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 1732f628ea..e72af11fbb 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -580,7 +580,9 @@ void tst_QChar::normalization_data() int linenum = 0; int part = 0; - QFile f(QFINDTESTDATA("NormalizationTest.txt")); + QString testFile = QFINDTESTDATA("NormalizationTest.txt"); + QVERIFY2(!testFile.isEmpty(), "NormalizationTest.txt not found!"); + QFile f(testFile); QVERIFY(f.exists()); f.open(QIODevice::ReadOnly); diff --git a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro index a97350ca3f..b61f51d53a 100644 --- a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro +++ b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro @@ -6,6 +6,3 @@ CONFIG -= app_bundle QT = core -# This app is testdata for tst_qlocale -target.path = $$[QT_INSTALL_TESTS]/tst_qlocale/$$TARGET -INSTALLS += target diff --git a/tests/auto/corelib/tools/qlocale/test/test.pro b/tests/auto/corelib/tools/qlocale/test/test.pro index eafd8c1699..24dcc0638a 100644 --- a/tests/auto/corelib/tools/qlocale/test/test.pro +++ b/tests/auto/corelib/tools/qlocale/test/test.pro @@ -12,6 +12,8 @@ win32 { TARGET = ../../release/tst_qlocale } } -TESTDATA += syslocaleapp + +load(testcase) # for target.path and installTestHelperApp() +installTestHelperApp("../syslocaleapp/syslocaleapp",syslocaleapp,syslocaleapp) mac: CONFIG += insignificant_test # QTBUG-22769 diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 02acb00548..b3b573c64b 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -809,11 +809,7 @@ void tst_QLocale::negativeZero() { double negativeZero( 0.0 ); // Initialise to zero. uchar *ptr = (uchar *)&negativeZero; -#ifdef QT_ARMFPA - ptr[3] = 0x80; -#else ptr[QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 7] = 0x80; -#endif QString s = QString::number(negativeZero); QCOMPARE(s, QString("0")); } diff --git a/tests/auto/corelib/tools/qpair/qpair.pro b/tests/auto/corelib/tools/qpair/qpair.pro new file mode 100644 index 0000000000..9c7752327e --- /dev/null +++ b/tests/auto/corelib/tools/qpair/qpair.pro @@ -0,0 +1,4 @@ +CONFIG += testcase parallel_test +TARGET = tst_qpair +QT = core testlib +SOURCES = tst_qpair.cpp diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp new file mode 100644 index 0000000000..5de1e8f8bb --- /dev/null +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QPair> + +class tst_QPair : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void dummy() {} +}; + +class C { char _[4]; }; +class M { char _[4]; }; +class P { char _[4]; }; + +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(M, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(P, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE + +// avoid the comma: +typedef QPair<C,C> QPairCC; +typedef QPair<C,M> QPairCM; +typedef QPair<C,P> QPairCP; +typedef QPair<M,C> QPairMC; +typedef QPair<M,M> QPairMM; +typedef QPair<M,P> QPairMP; +typedef QPair<P,C> QPairPC; +typedef QPair<P,M> QPairPM; +typedef QPair<P,P> QPairPP; + +Q_STATIC_ASSERT( QTypeInfo<QPairCC>::isComplex); +Q_STATIC_ASSERT( QTypeInfo<QPairCC>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairCM>::isComplex); +Q_STATIC_ASSERT( QTypeInfo<QPairCM>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairCP>::isComplex); +Q_STATIC_ASSERT( QTypeInfo<QPairCP>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairMC>::isComplex); +Q_STATIC_ASSERT( QTypeInfo<QPairMC>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairMM>::isComplex); +Q_STATIC_ASSERT(!QTypeInfo<QPairMM>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairMP>::isComplex); +Q_STATIC_ASSERT(!QTypeInfo<QPairMP>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairPC>::isComplex); +Q_STATIC_ASSERT( QTypeInfo<QPairPC>::isStatic ); + +Q_STATIC_ASSERT( QTypeInfo<QPairPM>::isComplex); +Q_STATIC_ASSERT(!QTypeInfo<QPairPM>::isStatic ); + +Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isComplex); +Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isStatic ); + +Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isDummy ); +Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isPointer); + + +QTEST_APPLESS_MAIN(tst_QPair) +#include "tst_qpair.moc" diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp index a697e23270..5470de76ee 100644 --- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp +++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp @@ -81,6 +81,7 @@ private slots: void interval(); void validityCheck_data(); void validityCheck(); + void escapeSequences(); }; // Testing get/set functions @@ -118,43 +119,43 @@ void tst_QRegExp::indexIn_data() stri.setNum(i); // anchors - QTest::newRow( stri + "anc00" ) << QString("a(?=)z") << QString("az") << 0 << 2 << QStringList(); - QTest::newRow( stri + "anc01" ) << QString("a(?!)z") << QString("az") << -1 << -1 << QStringList(); - QTest::newRow( stri + "anc02" ) << QString("a(?:(?=)|(?=))z") << QString("az") << 0 << 2 + QTest::newRow(qPrintable(stri + "anc00")) << QString("a(?=)z") << QString("az") << 0 << 2 << QStringList(); + QTest::newRow(qPrintable(stri + "anc01")) << QString("a(?!)z") << QString("az") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "anc02")) << QString("a(?:(?=)|(?=))z") << QString("az") << 0 << 2 << QStringList(); - QTest::newRow( stri + "anc03" ) << QString("a(?:(?=)|(?!))z") << QString("az") << 0 << 2 + QTest::newRow(qPrintable(stri + "anc03")) << QString("a(?:(?=)|(?!))z") << QString("az") << 0 << 2 << QStringList(); - QTest::newRow( stri + "anc04" ) << QString("a(?:(?!)|(?=))z") << QString("az") << 0 << 2 + QTest::newRow(qPrintable(stri + "anc04")) << QString("a(?:(?!)|(?=))z") << QString("az") << 0 << 2 << QStringList(); - QTest::newRow( stri + "anc05" ) << QString("a(?:(?!)|(?!))z") << QString("az") << -1 << -1 + QTest::newRow(qPrintable(stri + "anc05")) << QString("a(?:(?!)|(?!))z") << QString("az") << -1 << -1 << QStringList(); - QTest::newRow( stri + "anc06" ) << QString("a(?:(?=)|b)z") << QString("az") << 0 << 2 + QTest::newRow(qPrintable(stri + "anc06")) << QString("a(?:(?=)|b)z") << QString("az") << 0 << 2 << QStringList(); - QTest::newRow( stri + "anc07" ) << QString("a(?:(?=)|b)z") << QString("abz") << 0 << 3 + QTest::newRow(qPrintable(stri + "anc07")) << QString("a(?:(?=)|b)z") << QString("abz") << 0 << 3 << QStringList(); - QTest::newRow( stri + "anc08" ) << QString("a(?:(?!)|b)z") << QString("az") << -1 << -1 + QTest::newRow(qPrintable(stri + "anc08")) << QString("a(?:(?!)|b)z") << QString("az") << -1 << -1 << QStringList(); - QTest::newRow( stri + "anc09" ) << QString("a(?:(?!)|b)z") << QString("abz") << 0 << 3 + QTest::newRow(qPrintable(stri + "anc09")) << QString("a(?:(?!)|b)z") << QString("abz") << 0 << 3 << QStringList(); #if 0 - QTest::newRow( stri + "anc10" ) << QString("a?(?=^b$)") << QString("ab") << 0 << 1 + QTest::newRow(qPrintable(stri + "anc10")) << QString("a?(?=^b$)") << QString("ab") << 0 << 1 << QStringList(); - QTest::newRow( stri + "anc11" ) << QString("a?(?=^b$)") << QString("b") << 0 << 0 + QTest::newRow(qPrintable(stri + "anc11")) << QString("a?(?=^b$)") << QString("b") << 0 << 0 << QStringList(); #endif // back-references - QTest::newRow( stri + "bref00" ) << QString("(a*)(\\1)") << QString("aaaaa") << 0 << 4 + QTest::newRow(qPrintable(stri + "bref00")) << QString("(a*)(\\1)") << QString("aaaaa") << 0 << 4 << QStringList( QStringList() << "aa" << "aa" ); - QTest::newRow( stri + "bref01" ) << QString("<(\\w*)>.+</\\1>") << QString("<b>blabla</b>bla</>") + QTest::newRow(qPrintable(stri + "bref01")) << QString("<(\\w*)>.+</\\1>") << QString("<b>blabla</b>bla</>") << 0 << 13 << QStringList( QStringList() << "b" ); - QTest::newRow( stri + "bref02" ) << QString("<(\\w*)>.+</\\1>") << QString("<>blabla</b>bla</>") + QTest::newRow(qPrintable(stri + "bref02")) << QString("<(\\w*)>.+</\\1>") << QString("<>blabla</b>bla</>") << 0 << 18 << QStringList( QStringList() << "" ); - QTest::newRow( stri + "bref03" ) << QString("((a*\\2)\\2)") << QString("aaaa") << 0 << 4 + QTest::newRow(qPrintable(stri + "bref03")) << QString("((a*\\2)\\2)") << QString("aaaa") << 0 << 4 << QStringList( QStringList() << QString("aaaa") << "aa" ); - QTest::newRow( stri + "bref04" ) << QString("^(aa+)\\1+$") << QString("aaaaaa") << 0 << 6 + QTest::newRow(qPrintable(stri + "bref04")) << QString("^(aa+)\\1+$") << QString("aaaaaa") << 0 << 6 << QStringList( QStringList() << QString("aa") ); - QTest::newRow( stri + "bref05" ) << QString("^(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)(12)(13)(14)" + QTest::newRow(qPrintable(stri + "bref05")) << QString("^(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)(12)(13)(14)" "\\14\\13\\12\\11\\10\\9\\8\\7\\6\\5\\4\\3\\2\\1") << QString("12345678910111213141413121110987654321") << 0 << 38 << QStringList( QStringList() << "1" << "2" << "3" << "4" << "5" << "6" @@ -162,49 +163,49 @@ void tst_QRegExp::indexIn_data() << "12" << "13" << "14"); // captures - QTest::newRow( stri + "cap00" ) << QString("(a*)") << QString("") << 0 << 0 + QTest::newRow(qPrintable(stri + "cap00")) << QString("(a*)") << QString("") << 0 << 0 << QStringList( QStringList() << QString("") ); - QTest::newRow( stri + "cap01" ) << QString("(a*)") << QString("aaa") << 0 << 3 + QTest::newRow(qPrintable(stri + "cap01")) << QString("(a*)") << QString("aaa") << 0 << 3 << QStringList( QStringList() << "aaa" ); - QTest::newRow( stri + "cap02" ) << QString("(a*)") << QString("baaa") << 0 << 0 + QTest::newRow(qPrintable(stri + "cap02")) << QString("(a*)") << QString("baaa") << 0 << 0 << QStringList( QStringList() << QString("") ); - QTest::newRow( stri + "cap03" ) << QString("(a*)(a*)") << QString("aaa") << 0 << 3 + QTest::newRow(qPrintable(stri + "cap03")) << QString("(a*)(a*)") << QString("aaa") << 0 << 3 << QStringList( QStringList() << QString("aaa") << QString("") ); - QTest::newRow( stri + "cap04" ) << QString("(a*)(b*)") << QString("aaabbb") << 0 << 6 + QTest::newRow(qPrintable(stri + "cap04")) << QString("(a*)(b*)") << QString("aaabbb") << 0 << 6 << QStringList( QStringList() << QString("aaa") << QString("bbb") ); - QTest::newRow( stri + "cap06" ) << QString("(a*)a*") << QString("aaa") << 0 << 3 + QTest::newRow(qPrintable(stri + "cap06")) << QString("(a*)a*") << QString("aaa") << 0 << 3 << QStringList( QStringList() << QString("aaa") ); - QTest::newRow( stri + "cap07" ) << QString("((a*a*)*)") << QString("aaa") << 0 << 3 + QTest::newRow(qPrintable(stri + "cap07")) << QString("((a*a*)*)") << QString("aaa") << 0 << 3 << QStringList( QStringList() << "aaa" << QString("aaa") ); - QTest::newRow( stri + "cap08" ) << QString("(((a)*(b)*)*)") << QString("ababa") << 0 << 5 + QTest::newRow(qPrintable(stri + "cap08")) << QString("(((a)*(b)*)*)") << QString("ababa") << 0 << 5 << QStringList( QStringList() << QString("ababa") << QString("a") << QString("a") << "" ); - QTest::newRow( stri + "cap09" ) << QString("(((a)*(b)*)c)*") << QString("") << 0 << 0 + QTest::newRow(qPrintable(stri + "cap09")) << QString("(((a)*(b)*)c)*") << QString("") << 0 << 0 << QStringList( QStringList() << QString("") << QString("") << QString("") << QString("") ); - QTest::newRow( stri + "cap10" ) << QString("(((a)*(b)*)c)*") << QString("abc") << 0 << 3 + QTest::newRow(qPrintable(stri + "cap10")) << QString("(((a)*(b)*)c)*") << QString("abc") << 0 << 3 << QStringList( QStringList() << "abc" << "ab" << "a" << "b" ); - QTest::newRow( stri + "cap11" ) << QString("(((a)*(b)*)c)*") << QString("abcc") << 0 << 4 + QTest::newRow(qPrintable(stri + "cap11")) << QString("(((a)*(b)*)c)*") << QString("abcc") << 0 << 4 << QStringList( QStringList() << "c" << "" << "" << "" ); - QTest::newRow( stri + "cap12" ) << QString("(((a)*(b)*)c)*") << QString("abcac") << 0 << 5 + QTest::newRow(qPrintable(stri + "cap12")) << QString("(((a)*(b)*)c)*") << QString("abcac") << 0 << 5 << QStringList( QStringList() << "ac" << "a" << "a" << "" ); - QTest::newRow( stri + "cap13" ) << QString("(to|top)?(o|polo)?(gical|o?logical)") + QTest::newRow(qPrintable(stri + "cap13")) << QString("(to|top)?(o|polo)?(gical|o?logical)") << QString("topological") << 0 << 11 << QStringList( QStringList() << "top" << "o" << "logical" ); - QTest::newRow( stri + "cap14" ) << QString("(a)+") << QString("aaaa") << 0 << 4 + QTest::newRow(qPrintable(stri + "cap14")) << QString("(a)+") << QString("aaaa") << 0 << 4 << QStringList( QStringList() << "a" ); // concatenation - QTest::newRow( stri + "cat00" ) << QString("") << QString("") << 0 << 0 << QStringList(); - QTest::newRow( stri + "cat01" ) << QString("") << QString("a") << 0 << 0 << QStringList(); - QTest::newRow( stri + "cat02" ) << QString("a") << QString("") << -1 << -1 << QStringList(); - QTest::newRow( stri + "cat03" ) << QString("a") << QString("a") << 0 << 1 << QStringList(); - QTest::newRow( stri + "cat04" ) << QString("a") << QString("b") << -1 << -1 << QStringList(); - QTest::newRow( stri + "cat05" ) << QString("b") << QString("a") << -1 << -1 << QStringList(); - QTest::newRow( stri + "cat06" ) << QString("ab") << QString("ab") << 0 << 2 << QStringList(); - QTest::newRow( stri + "cat07" ) << QString("ab") << QString("ba") << -1 << -1 << QStringList(); - QTest::newRow( stri + "cat08" ) << QString("abab") << QString("abbaababab") << 4 << 4 << QStringList(); + QTest::newRow(qPrintable(stri + "cat00")) << QString("") << QString("") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "cat01")) << QString("") << QString("a") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "cat02")) << QString("a") << QString("") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "cat03")) << QString("a") << QString("a") << 0 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "cat04")) << QString("a") << QString("b") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "cat05")) << QString("b") << QString("a") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "cat06")) << QString("ab") << QString("ab") << 0 << 2 << QStringList(); + QTest::newRow(qPrintable(stri + "cat07")) << QString("ab") << QString("ba") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "cat08")) << QString("abab") << QString("abbaababab") << 4 << 4 << QStringList(); indexIn_addMoreRows(stri); } @@ -213,96 +214,96 @@ void tst_QRegExp::indexIn_data() void tst_QRegExp::indexIn_addMoreRows(const QByteArray &stri) { // from Perl Cookbook - QTest::newRow( stri + "cook00" ) << QString("^(m*)(d?c{0,3}|c[dm])(1?x{0,3}|x[lc])(v?i{0,3}|i[vx])$") + QTest::newRow(qPrintable(stri + "cook00")) << QString("^(m*)(d?c{0,3}|c[dm])(1?x{0,3}|x[lc])(v?i{0,3}|i[vx])$") << QString("mmxl") << 0 << 4 << QStringList( QStringList() << "mm" << "" << "xl" << "" ); - QTest::newRow( stri + "cook01" ) << QString("(\\S+)(\\s+)(\\S+)") << QString(" a b") << 1 << 5 + QTest::newRow(qPrintable(stri + "cook01")) << QString("(\\S+)(\\s+)(\\S+)") << QString(" a b") << 1 << 5 << QStringList( QStringList() << "a" << " " << "b" ); - QTest::newRow( stri + "cook02" ) << QString("(\\w+)\\s*=\\s*(.*)\\s*$") << QString(" PATH=. ") << 1 + QTest::newRow(qPrintable(stri + "cook02")) << QString("(\\w+)\\s*=\\s*(.*)\\s*$") << QString(" PATH=. ") << 1 << 7 << QStringList( QStringList() << "PATH" << ". " ); - QTest::newRow( stri + "cook03" ) << QString(".{80,}") + QTest::newRow(qPrintable(stri + "cook03")) << QString(".{80,}") << QString("0000000011111111222222223333333344444444555" "5555566666666777777778888888899999999000000" "00aaaaaaaa") << 0 << 96 << QStringList(); - QTest::newRow( stri + "cook04" ) << QString("(\\d+)/(\\d+)/(\\d+) (\\d+):(\\d+):(\\d+)") + QTest::newRow(qPrintable(stri + "cook04")) << QString("(\\d+)/(\\d+)/(\\d+) (\\d+):(\\d+):(\\d+)") << QString("1978/05/24 07:30:00") << 0 << 19 << QStringList( QStringList() << "1978" << "05" << "24" << "07" << "30" << "00" ); - QTest::newRow( stri + "cook05" ) << QString("/usr/bin") << QString("/usr/local/bin:/usr/bin") + QTest::newRow(qPrintable(stri + "cook05")) << QString("/usr/bin") << QString("/usr/local/bin:/usr/bin") << 15 << 8 << QStringList(); - QTest::newRow( stri + "cook06" ) << QString("%([0-9A-Fa-f]{2})") << QString("http://%7f") << 7 << 3 + QTest::newRow(qPrintable(stri + "cook06")) << QString("%([0-9A-Fa-f]{2})") << QString("http://%7f") << 7 << 3 << QStringList( QStringList() << "7f" ); - QTest::newRow( stri + "cook07" ) << QString("/\\*.*\\*/") << QString("i++; /* increment i */") << 5 + QTest::newRow(qPrintable(stri + "cook07")) << QString("/\\*.*\\*/") << QString("i++; /* increment i */") << 5 << 17 << QStringList(); - QTest::newRow( stri + "cook08" ) << QString("^\\s+") << QString(" aaa ") << 0 << 3 + QTest::newRow(qPrintable(stri + "cook08")) << QString("^\\s+") << QString(" aaa ") << 0 << 3 << QStringList(); - QTest::newRow( stri + "cook09" ) << QString("\\s+$") << QString(" aaa ") << 6 << 3 + QTest::newRow(qPrintable(stri + "cook09")) << QString("\\s+$") << QString(" aaa ") << 6 << 3 << QStringList(); - QTest::newRow( stri + "cook10" ) << QString("^.*::") << QString("Box::cat") << 0 << 5 + QTest::newRow(qPrintable(stri + "cook10")) << QString("^.*::") << QString("Box::cat") << 0 << 5 << QStringList(); - QTest::newRow( stri + "cook11" ) << QString("^([01]?\\d\\d|2[0-4]\\d|25[0-5])\\.([01]?\\" + QTest::newRow(qPrintable(stri + "cook11")) << QString("^([01]?\\d\\d|2[0-4]\\d|25[0-5])\\.([01]?\\" "d\\d|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d|2[0-" "4]\\d|25[0-5])\\.([01]?\\d\\d|2[0-4]\\d|25[" "0-5])$") << QString("255.00.40.30") << 0 << 12 << QStringList( QStringList() << "255" << "00" << "40" << "30" ); - QTest::newRow( stri + "cook12" ) << QString("^.*/") << QString(" /usr/local/bin/moc") << 0 << 16 + QTest::newRow(qPrintable(stri + "cook12")) << QString("^.*/") << QString(" /usr/local/bin/moc") << 0 << 16 << QStringList(); - QTest::newRow( stri + "cook13" ) << QString(":co#(\\d+):") << QString("bla:co#55:") << 3 << 7 + QTest::newRow(qPrintable(stri + "cook13")) << QString(":co#(\\d+):") << QString("bla:co#55:") << 3 << 7 << QStringList( QStringList() << "55" ); - QTest::newRow( stri + "cook14" ) << QString("linux") << QString("alphalinuxinunix") << 5 << 5 + QTest::newRow(qPrintable(stri + "cook14")) << QString("linux") << QString("alphalinuxinunix") << 5 << 5 << QStringList(); - QTest::newRow( stri + "cook15" ) << QString("(\\d+\\.?\\d*|\\.\\d+)") << QString("0.0.5") << 0 << 3 + QTest::newRow(qPrintable(stri + "cook15")) << QString("(\\d+\\.?\\d*|\\.\\d+)") << QString("0.0.5") << 0 << 3 << QStringList( QStringList() << "0.0" ); // mathematical trivia - QTest::newRow( stri + "math00" ) << QString("^(a\\1*)$") << QString("a") << 0 << 1 + QTest::newRow(qPrintable(stri + "math00")) << QString("^(a\\1*)$") << QString("a") << 0 << 1 << QStringList( QStringList() << "a" ); - QTest::newRow( stri + "math01" ) << QString("^(a\\1*)$") << QString("aa") << 0 << 2 + QTest::newRow(qPrintable(stri + "math01")) << QString("^(a\\1*)$") << QString("aa") << 0 << 2 << QStringList( QStringList() << "aa" ); - QTest::newRow( stri + "math02" ) << QString("^(a\\1*)$") << QString("aaa") << -1 << -1 + QTest::newRow(qPrintable(stri + "math02")) << QString("^(a\\1*)$") << QString("aaa") << -1 << -1 << QStringList( QStringList() << QString() ); - QTest::newRow( stri + "math03" ) << QString("^(a\\1*)$") << QString("aaaa") << 0 << 4 + QTest::newRow(qPrintable(stri + "math03")) << QString("^(a\\1*)$") << QString("aaaa") << 0 << 4 << QStringList( QStringList() << "aaaa" ); - QTest::newRow( stri + "math04" ) << QString("^(a\\1*)$") << QString("aaaaa") << -1 << -1 + QTest::newRow(qPrintable(stri + "math04")) << QString("^(a\\1*)$") << QString("aaaaa") << -1 << -1 << QStringList( QStringList() << QString() ); - QTest::newRow( stri + "math05" ) << QString("^(a\\1*)$") << QString("aaaaaa") << -1 << -1 + QTest::newRow(qPrintable(stri + "math05")) << QString("^(a\\1*)$") << QString("aaaaaa") << -1 << -1 << QStringList( QStringList() << QString() ); - QTest::newRow( stri + "math06" ) << QString("^(a\\1*)$") << QString("aaaaaaa") << -1 << -1 + QTest::newRow(qPrintable(stri + "math06")) << QString("^(a\\1*)$") << QString("aaaaaaa") << -1 << -1 << QStringList( QStringList() << QString() ); - QTest::newRow( stri + "math07" ) << QString("^(a\\1*)$") << QString("aaaaaaaa") << 0 << 8 + QTest::newRow(qPrintable(stri + "math07")) << QString("^(a\\1*)$") << QString("aaaaaaaa") << 0 << 8 << QStringList( QStringList() << "aaaaaaaa" ); - QTest::newRow( stri + "math08" ) << QString("^(a\\1*)$") << QString("aaaaaaaaa") << -1 << -1 + QTest::newRow(qPrintable(stri + "math08")) << QString("^(a\\1*)$") << QString("aaaaaaaaa") << -1 << -1 << QStringList( QStringList() << QString() ); - QTest::newRow( stri + "math09" ) << QString("^a(?:a(\\1a))*$") << QString("a") << 0 << 1 + QTest::newRow(qPrintable(stri + "math09")) << QString("^a(?:a(\\1a))*$") << QString("a") << 0 << 1 << QStringList( QStringList() << "" ); - QTest::newRow( stri + "math10" ) << QString("^a(?:a(\\1a))*$") << QString("aaa") << 0 << 3 + QTest::newRow(qPrintable(stri + "math10")) << QString("^a(?:a(\\1a))*$") << QString("aaa") << 0 << 3 << QStringList( QStringList() << "a" ); - QTest::newRow( stri + "math13" ) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|(" + QTest::newRow(qPrintable(stri + "math13")) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|(" "?=a$)))*a$") << QString("aaa") << 0 << 3 << QStringList( QStringList() << "a" << "a" << "" ); - QTest::newRow( stri + "math14" ) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|(" + QTest::newRow(qPrintable(stri + "math14")) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|(" "?=a$)))*a$") << QString("aaaaa") << 0 << 5 << QStringList( QStringList() << "a" << "a" << "aa" ); - QTest::newRow( stri + "math17" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" + QTest::newRow(qPrintable(stri + "math17")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" ":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$") << QString("aaa") << 0 << 3 << QStringList( QStringList() << "" << "" << "" << "aaa" << "a" << "aa" ); - QTest::newRow( stri + "math18" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" + QTest::newRow(qPrintable(stri + "math18")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" ":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$") << QString("aaaaa") << 0 << 5 << QStringList( QStringList() << "aaaaa" << "a" << "aaa" << "" << "" << "" ); - QTest::newRow( stri + "math19" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" + QTest::newRow(qPrintable(stri + "math19")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" ":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$") << QString("aaaaaaaa") << 0 << 8 << QStringList( QStringList() << "" << "" << "" << "aaaaaaaa" << "a" << "aa" ); - QTest::newRow( stri + "math20" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" + QTest::newRow(qPrintable(stri + "math20")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?" ":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$") << QString("aaaaaaaaa") << -1 << -1 << QStringList( QStringList() << QString() @@ -311,7 +312,7 @@ void tst_QRegExp::indexIn_addMoreRows(const QByteArray &stri) << QString() << QString() << QString() ); - QTest::newRow( stri + "math21" ) << QString("^(aa+)\\1+$") << QString("aaaaaaaaaaaa") << 0 << 12 + QTest::newRow(qPrintable(stri + "math21")) << QString("^(aa+)\\1+$") << QString("aaaaaaaaaaaa") << 0 << 12 << QStringList( QStringList() << "aa" ); static const char * const squareRegExp[] = { @@ -349,129 +350,129 @@ void tst_QRegExp::indexIn_addMoreRows(const QByteArray &stri) } // miscellaneous - QTest::newRow( stri + "misc00" ) << QString(email) + QTest::newRow(qPrintable(stri + "misc00")) << QString(email) << QString("email123@example.com") << 0 << 20 << QStringList(); - QTest::newRow( stri + "misc01" ) << QString("[0-9]*\\.[0-9]+") << QString("pi = 3.14") << 5 << 4 + QTest::newRow(qPrintable(stri + "misc01")) << QString("[0-9]*\\.[0-9]+") << QString("pi = 3.14") << 5 << 4 << QStringList(); // or operator - QTest::newRow( stri + "or00" ) << QString("(?:|b)") << QString("xxx") << 0 << 0 << QStringList(); - QTest::newRow( stri + "or01" ) << QString("(?:|b)") << QString("b") << 0 << 1 << QStringList(); - QTest::newRow( stri + "or02" ) << QString("(?:b|)") << QString("") << 0 << 0 << QStringList(); - QTest::newRow( stri + "or03" ) << QString("(?:b|)") << QString("b") << 0 << 1 << QStringList(); - QTest::newRow( stri + "or04" ) << QString("(?:||b||)") << QString("") << 0 << 0 << QStringList(); - QTest::newRow( stri + "or05" ) << QString("(?:||b||)") << QString("b") << 0 << 1 << QStringList(); - QTest::newRow( stri + "or06" ) << QString("(?:a|b)") << QString("") << -1 << -1 << QStringList(); - QTest::newRow( stri + "or07" ) << QString("(?:a|b)") << QString("cc") << -1 << -1 << QStringList(); - QTest::newRow( stri + "or08" ) << QString("(?:a|b)") << QString("abc") << 0 << 1 << QStringList(); - QTest::newRow( stri + "or09" ) << QString("(?:a|b)") << QString("cba") << 1 << 1 << QStringList(); - QTest::newRow( stri + "or10" ) << QString("(?:ab|ba)") << QString("aba") << 0 << 2 + QTest::newRow(qPrintable(stri + "or00")) << QString("(?:|b)") << QString("xxx") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "or01")) << QString("(?:|b)") << QString("b") << 0 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "or02")) << QString("(?:b|)") << QString("") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "or03")) << QString("(?:b|)") << QString("b") << 0 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "or04")) << QString("(?:||b||)") << QString("") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "or05")) << QString("(?:||b||)") << QString("b") << 0 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "or06")) << QString("(?:a|b)") << QString("") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "or07")) << QString("(?:a|b)") << QString("cc") << -1 << -1 << QStringList(); + QTest::newRow(qPrintable(stri + "or08")) << QString("(?:a|b)") << QString("abc") << 0 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "or09")) << QString("(?:a|b)") << QString("cba") << 1 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "or10")) << QString("(?:ab|ba)") << QString("aba") << 0 << 2 << QStringList(); - QTest::newRow( stri + "or11" ) << QString("(?:ab|ba)") << QString("bab") << 0 << 2 + QTest::newRow(qPrintable(stri + "or11")) << QString("(?:ab|ba)") << QString("bab") << 0 << 2 << QStringList(); - QTest::newRow( stri + "or12" ) << QString("(?:ab|ba)") << QString("caba") << 1 << 2 + QTest::newRow(qPrintable(stri + "or12")) << QString("(?:ab|ba)") << QString("caba") << 1 << 2 << QStringList(); - QTest::newRow( stri + "or13" ) << QString("(?:ab|ba)") << QString("cbab") << 1 << 2 + QTest::newRow(qPrintable(stri + "or13")) << QString("(?:ab|ba)") << QString("cbab") << 1 << 2 << QStringList(); // quantifiers - QTest::newRow( stri + "qua00" ) << QString("((([a-j])){0,0})") << QString("") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua00")) << QString("((([a-j])){0,0})") << QString("") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua01" ) << QString("((([a-j])){0,0})") << QString("a") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua01")) << QString("((([a-j])){0,0})") << QString("a") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua02" ) << QString("((([a-j])){0,0})") << QString("xyz") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua02")) << QString("((([a-j])){0,0})") << QString("xyz") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua03" ) << QString("((([a-j]))?)") << QString("") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua03")) << QString("((([a-j]))?)") << QString("") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua04" ) << QString("((([a-j]))?)") << QString("a") << 0 << 1 + QTest::newRow(qPrintable(stri + "qua04")) << QString("((([a-j]))?)") << QString("a") << 0 << 1 << QStringList( QStringList() << "a" << "a" << "a" ); - QTest::newRow( stri + "qua05" ) << QString("((([a-j]))?)") << QString("x") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua05")) << QString("((([a-j]))?)") << QString("x") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua06" ) << QString("((([a-j]))?)") << QString("ab") << 0 << 1 + QTest::newRow(qPrintable(stri + "qua06")) << QString("((([a-j]))?)") << QString("ab") << 0 << 1 << QStringList( QStringList() << "a" << "a" << "a" ); - QTest::newRow( stri + "qua07" ) << QString("((([a-j]))?)") << QString("xa") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua07")) << QString("((([a-j]))?)") << QString("xa") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua08" ) << QString("((([a-j])){0,3})") << QString("") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua08")) << QString("((([a-j])){0,3})") << QString("") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua09" ) << QString("((([a-j])){0,3})") << QString("a") << 0 << 1 + QTest::newRow(qPrintable(stri + "qua09")) << QString("((([a-j])){0,3})") << QString("a") << 0 << 1 << QStringList( QStringList() << "a" << "a" << "a" ); - QTest::newRow( stri + "qua10" ) << QString("((([a-j])){0,3})") << QString("abcd") << 0 << 3 + QTest::newRow(qPrintable(stri + "qua10")) << QString("((([a-j])){0,3})") << QString("abcd") << 0 << 3 << QStringList( QStringList() << "abc" << "c" << "c" ); - QTest::newRow( stri + "qua11" ) << QString("((([a-j])){0,3})") << QString("abcde") << 0 << 3 + QTest::newRow(qPrintable(stri + "qua11")) << QString("((([a-j])){0,3})") << QString("abcde") << 0 << 3 << QStringList( QStringList() << "abc" << "c" << "c" ); - QTest::newRow( stri + "qua12" ) << QString("((([a-j])){2,4})") << QString("a") << -1 << -1 + QTest::newRow(qPrintable(stri + "qua12")) << QString("((([a-j])){2,4})") << QString("a") << -1 << -1 << QStringList( QStringList() << QString() << QString() << QString() ); - QTest::newRow( stri + "qua13" ) << QString("((([a-j])){2,4})") << QString("ab") << 0 << 2 + QTest::newRow(qPrintable(stri + "qua13")) << QString("((([a-j])){2,4})") << QString("ab") << 0 << 2 << QStringList( QStringList() << "ab" << "b" << "b" ); - QTest::newRow( stri + "qua14" ) << QString("((([a-j])){2,4})") << QString("abcd") << 0 << 4 + QTest::newRow(qPrintable(stri + "qua14")) << QString("((([a-j])){2,4})") << QString("abcd") << 0 << 4 << QStringList( QStringList() << "abcd" << "d" << "d" ); - QTest::newRow( stri + "qua15" ) << QString("((([a-j])){2,4})") << QString("abcdef") << 0 << 4 + QTest::newRow(qPrintable(stri + "qua15")) << QString("((([a-j])){2,4})") << QString("abcdef") << 0 << 4 << QStringList( QStringList() << "abcd" << "d" << "d" ); - QTest::newRow( stri + "qua16" ) << QString("((([a-j])){2,4})") << QString("xaybcd") << 3 << 3 + QTest::newRow(qPrintable(stri + "qua16")) << QString("((([a-j])){2,4})") << QString("xaybcd") << 3 << 3 << QStringList( QStringList() << "bcd" << "d" << "d" ); - QTest::newRow( stri + "qua17" ) << QString("((([a-j])){0,})") << QString("abcdefgh") << 0 << 8 + QTest::newRow(qPrintable(stri + "qua17")) << QString("((([a-j])){0,})") << QString("abcdefgh") << 0 << 8 << QStringList( QStringList() << "abcdefgh" << "h" << "h" ); - QTest::newRow( stri + "qua18" ) << QString("((([a-j])){,0})") << QString("abcdefgh") << 0 << 0 + QTest::newRow(qPrintable(stri + "qua18")) << QString("((([a-j])){,0})") << QString("abcdefgh") << 0 << 0 << QStringList( QStringList() << "" << "" << "" ); - QTest::newRow( stri + "qua19" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("123332333") << 0 + QTest::newRow(qPrintable(stri + "qua19")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("123332333") << 0 << 9 << QStringList( QStringList() << "123332333" << "2333" << "3" ); - QTest::newRow( stri + "qua20" ) << QString("(1(2(3){3,4}){2,3}){1,2}") + QTest::newRow(qPrintable(stri + "qua20")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333323333233331233332333323333") << 0 << 32 << QStringList( QStringList() << "1233332333323333" << "23333" << "3" ); - QTest::newRow( stri + "qua21" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("") << -1 << -1 + QTest::newRow(qPrintable(stri + "qua21")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("") << -1 << -1 << QStringList( QStringList() << QString() << QString() << QString() ); - QTest::newRow( stri + "qua22" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333") << -1 + QTest::newRow(qPrintable(stri + "qua22")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333") << -1 << -1 << QStringList( QStringList() << QString() << QString() << QString() ); - QTest::newRow( stri + "qua23" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333233") << -1 + QTest::newRow(qPrintable(stri + "qua23")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333233") << -1 << -1 << QStringList( QStringList() << QString() << QString() << QString() ); - QTest::newRow( stri + "qua24" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("122333") << -1 + QTest::newRow(qPrintable(stri + "qua24")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("122333") << -1 << -1 << QStringList( QStringList() << QString() << QString() << QString() ); // star operator - QTest::newRow( stri + "star00" ) << QString("(?:)*") << QString("") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star01" ) << QString("(?:)*") << QString("abc") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star02" ) << QString("(?:a)*") << QString("") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star03" ) << QString("(?:a)*") << QString("a") << 0 << 1 << QStringList(); - QTest::newRow( stri + "star04" ) << QString("(?:a)*") << QString("aaa") << 0 << 3 << QStringList(); - QTest::newRow( stri + "star05" ) << QString("(?:a)*") << QString("bbbbaaa") << 0 << 0 + QTest::newRow(qPrintable(stri + "star00")) << QString("(?:)*") << QString("") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "star01")) << QString("(?:)*") << QString("abc") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "star02")) << QString("(?:a)*") << QString("") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "star03")) << QString("(?:a)*") << QString("a") << 0 << 1 << QStringList(); + QTest::newRow(qPrintable(stri + "star04")) << QString("(?:a)*") << QString("aaa") << 0 << 3 << QStringList(); + QTest::newRow(qPrintable(stri + "star05")) << QString("(?:a)*") << QString("bbbbaaa") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star06" ) << QString("(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 0 + QTest::newRow(qPrintable(stri + "star06")) << QString("(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star07" ) << QString("(?:b)*(?:a)*") << QString("") << 0 << 0 + QTest::newRow(qPrintable(stri + "star07")) << QString("(?:b)*(?:a)*") << QString("") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star08" ) << QString("(?:b)*(?:a)*") << QString("a") << 0 << 1 + QTest::newRow(qPrintable(stri + "star08")) << QString("(?:b)*(?:a)*") << QString("a") << 0 << 1 << QStringList(); - QTest::newRow( stri + "star09" ) << QString("(?:b)*(?:a)*") << QString("aaa") << 0 << 3 + QTest::newRow(qPrintable(stri + "star09")) << QString("(?:b)*(?:a)*") << QString("aaa") << 0 << 3 << QStringList(); - QTest::newRow( stri + "star10" ) << QString("(?:b)*(?:a)*") << QString("bbbbaaa") << 0 << 7 + QTest::newRow(qPrintable(stri + "star10")) << QString("(?:b)*(?:a)*") << QString("bbbbaaa") << 0 << 7 << QStringList(); - QTest::newRow( stri + "star11" ) << QString("(?:b)*(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 7 + QTest::newRow(qPrintable(stri + "star11")) << QString("(?:b)*(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 7 << QStringList(); - QTest::newRow( stri + "star12" ) << QString("(?:a|b)*") << QString("c") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star13" ) << QString("(?:a|b)*") << QString("abac") << 0 << 3 + QTest::newRow(qPrintable(stri + "star12")) << QString("(?:a|b)*") << QString("c") << 0 << 0 << QStringList(); + QTest::newRow(qPrintable(stri + "star13")) << QString("(?:a|b)*") << QString("abac") << 0 << 3 << QStringList(); - QTest::newRow( stri + "star14" ) << QString("(?:a|b|)*") << QString("c") << 0 << 0 + QTest::newRow(qPrintable(stri + "star14")) << QString("(?:a|b|)*") << QString("c") << 0 << 0 << QStringList(); - QTest::newRow( stri + "star15" ) << QString("(?:a|b|)*") << QString("abac") << 0 << 3 + QTest::newRow(qPrintable(stri + "star15")) << QString("(?:a|b|)*") << QString("abac") << 0 << 3 << QStringList(); - QTest::newRow( stri + "star16" ) << QString("(?:ab|ba|b)*") << QString("abbbababbbaaab") << 0 << 11 + QTest::newRow(qPrintable(stri + "star16")) << QString("(?:ab|ba|b)*") << QString("abbbababbbaaab") << 0 << 11 << QStringList(); } @@ -1373,6 +1374,29 @@ void tst_QRegExp::validityCheck() QCOMPARE(rx2.cap(), QString("")); } +void tst_QRegExp::escapeSequences() +{ + QString perlSyntaxSpecialChars("0123456789afnrtvbBdDwWsSx\\|[]{}()^$?+*"); + QString w3cXmlSchema11SyntaxSpecialChars("cCiIpP"); // as well as the perl ones + for (int i = ' '; i <= 127; ++i) { + QLatin1Char c(i); + if (perlSyntaxSpecialChars.indexOf(c) == -1) { + QRegExp rx(QString("\\%1").arg(c), Qt::CaseSensitive, QRegExp::RegExp); + // we'll never have c == 'a' since it's a special character + QString s = QString("aaa%1aaa").arg(c); + QCOMPARE(rx.indexIn(s), 3); + + rx.setPatternSyntax(QRegExp::RegExp2); + QCOMPARE(rx.indexIn(s), 3); + + if (w3cXmlSchema11SyntaxSpecialChars.indexOf(c) == -1) { + rx.setPatternSyntax(QRegExp::W3CXmlSchema11); + QCOMPARE(rx.indexIn(s), 3); + } + } + } +} + QTEST_APPLESS_MAIN(tst_QRegExp) #include "tst_qregexp.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/.gitignore b/tests/auto/corelib/tools/qregularexpression/.gitignore new file mode 100644 index 0000000000..c9249e090e --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/.gitignore @@ -0,0 +1,2 @@ +tst_qregularexpression_alwaysoptimize +tst_qregularexpression_defaultoptimize diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro new file mode 100644 index 0000000000..f48b1ee96a --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro @@ -0,0 +1,7 @@ +CONFIG += testcase parallel_test +TARGET = tst_qregularexpression_alwaysoptimize +QT = core testlib +HEADERS = ../tst_qregularexpression.h +SOURCES = \ + tst_qregularexpression_alwaysoptimize.cpp \ + ../tst_qregularexpression.cpp diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp new file mode 100644 index 0000000000..9190f183a1 --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include "../tst_qregularexpression.h" + +class tst_QRegularExpression_AlwaysOptimize : public tst_QRegularExpression +{ + Q_OBJECT + +private slots: + void initTestCase(); +}; + +QT_BEGIN_NAMESPACE +extern Q_CORE_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count; // from qregularexpression.cpp +QT_END_NAMESPACE + +void tst_QRegularExpression_AlwaysOptimize::initTestCase() +{ + qt_qregularexpression_optimize_after_use_count = 1; +} + +QTEST_APPLESS_MAIN(tst_QRegularExpression_AlwaysOptimize) + +#include "tst_qregularexpression_alwaysoptimize.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro new file mode 100644 index 0000000000..dd1a90cfbc --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro @@ -0,0 +1,7 @@ +CONFIG += testcase parallel_test +TARGET = tst_qregularexpression_defaultoptimize +QT = core testlib +HEADERS = ../tst_qregularexpression.h +SOURCES = \ + tst_qregularexpression_defaultoptimize.cpp \ + ../tst_qregularexpression.cpp diff --git a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp new file mode 100644 index 0000000000..d0b5bee4b7 --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include "../tst_qregularexpression.h" + +class tst_QRegularExpression_DefaultOptimize : public tst_QRegularExpression +{ + Q_OBJECT +}; + +QTEST_APPLESS_MAIN(tst_QRegularExpression_DefaultOptimize) + +#include "tst_qregularexpression_defaultoptimize.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro new file mode 100644 index 0000000000..0cae10112f --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = defaultoptimize +contains(QT_CONFIG,private_tests):SUBDIRS += alwaysoptimize diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp new file mode 100644 index 0000000000..72157c0536 --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -0,0 +1,1198 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <qstring.h> +#include <qlist.h> +#include <qstringlist.h> +#include <qhash.h> + +#include "tst_qregularexpression.h" + +struct Match +{ + Match() + { + clear(); + } + + void clear() + { + isValid = false; + hasMatch = false; + hasPartialMatch = false; + captured.clear(); + namedCaptured.clear(); + } + + bool isValid; + bool hasMatch; + bool hasPartialMatch; + QStringList captured; + QHash<QString, QString> namedCaptured; +}; + +Q_DECLARE_METATYPE(Match) +Q_DECLARE_METATYPE(QList<Match>) + +bool operator==(const QRegularExpressionMatch &rem, const Match &m) +{ + if (rem.isValid() != m.isValid) + return false; + if (!rem.isValid()) + return true; + if ((rem.hasMatch() != m.hasMatch) || (rem.hasPartialMatch() != m.hasPartialMatch)) + return false; + if (rem.hasMatch() || rem.hasPartialMatch()) { + if (rem.lastCapturedIndex() != (m.captured.size() - 1)) + return false; + for (int i = 0; i <= rem.lastCapturedIndex(); ++i) { + QString remCaptured = rem.captured(i); + QString mCaptured = m.captured.at(i); + if (remCaptured != mCaptured + || remCaptured.isNull() != mCaptured.isNull() + || remCaptured.isEmpty() != mCaptured.isEmpty()) { + return false; + } + } + + Q_FOREACH (const QString &name, m.namedCaptured.keys()) { + if (rem.captured(name) != m.namedCaptured.value(name)) + return false; + } + } + + return true; +} + +bool operator==(const Match &m, const QRegularExpressionMatch &rem) +{ + return operator==(rem, m); +} + +bool operator!=(const QRegularExpressionMatch &rem, const Match &m) +{ + return !operator==(rem, m); +} + +bool operator!=(const Match &m, const QRegularExpressionMatch &rem) +{ + return !operator==(m, rem); +} + + +bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList) +{ + QRegularExpressionMatchIterator i = iterator; + if (i.isValid() != (!expectedMatchList.isEmpty())) + return false; + + foreach (const Match &expectedMatch, expectedMatchList) + { + if (!i.hasNext()) + return false; + + QRegularExpressionMatch match = i.next(); + if (match != expectedMatch) + return false; + } + + if (i.hasNext()) + return false; + + return true; +} + +bool operator==(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator) +{ + return operator==(iterator, expectedMatchList); +} + +bool operator!=(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList) +{ + return !operator==(iterator, expectedMatchList); +} + +bool operator!=(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator) +{ + return !operator==(expectedMatchList, iterator); +} + +void consistencyCheck(const QRegularExpressionMatch &match) +{ + if (match.isValid()) { + QVERIFY(match.regularExpression().isValid()); + QVERIFY(!(match.hasMatch() && match.hasPartialMatch())); + + if (match.hasMatch() || match.hasPartialMatch()) { + QVERIFY(match.lastCapturedIndex() >= 0); + if (match.hasPartialMatch()) + QVERIFY(match.lastCapturedIndex() == 0); + + for (int i = 0; i <= match.lastCapturedIndex(); ++i) { + int startPos = match.capturedStart(i); + int endPos = match.capturedEnd(i); + int length = match.capturedLength(i); + QString captured = match.captured(i); + QStringRef capturedRef = match.capturedRef(i); + + if (!captured.isNull()) { + QVERIFY(startPos >= 0); + QVERIFY(endPos >= 0); + QVERIFY(length >= 0); + QVERIFY(endPos >= startPos); + QVERIFY((endPos - startPos) == length); + QVERIFY(captured == capturedRef); + } else { + QVERIFY(startPos == -1); + QVERIFY(endPos == -1); + QVERIFY((endPos - startPos) == length); + QVERIFY(capturedRef.isNull()); + } + } + } + } else { + QVERIFY(!match.hasMatch()); + QVERIFY(!match.hasPartialMatch()); + QVERIFY(match.captured(0).isNull()); + QVERIFY(match.capturedStart(0) == -1); + QVERIFY(match.capturedEnd(0) == -1); + QVERIFY(match.capturedLength(0) == 0); + } +} + +void consistencyCheck(const QRegularExpressionMatchIterator &iterator) +{ + QRegularExpressionMatchIterator i(iterator); // make a copy, we modify it + if (i.isValid()) { + while (i.hasNext()) { + QRegularExpressionMatch peeked = i.peekNext(); + QRegularExpressionMatch match = i.next(); + consistencyCheck(peeked); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch() || match.hasPartialMatch()); + QCOMPARE(i.regularExpression(), match.regularExpression()); + QCOMPARE(i.matchOptions(), match.matchOptions()); + QCOMPARE(i.matchType(), match.matchType()); + + QVERIFY(peeked.isValid() == match.isValid()); + QVERIFY(peeked.hasMatch() == match.hasMatch()); + QVERIFY(peeked.hasPartialMatch() == match.hasPartialMatch()); + QVERIFY(peeked.lastCapturedIndex() == match.lastCapturedIndex()); + for (int i = 0; i <= peeked.lastCapturedIndex(); ++i) { + QVERIFY(peeked.captured(i) == match.captured(i)); + QVERIFY(peeked.capturedStart(i) == match.capturedStart(i)); + QVERIFY(peeked.capturedEnd(i) == match.capturedEnd(i)); + } + } + } else { + QVERIFY(!i.hasNext()); + QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatchIterator::peekNext() called on an iterator already at end"); + QRegularExpressionMatch peeked = i.peekNext(); + QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatchIterator::next() called on an iterator already at end"); + QRegularExpressionMatch match = i.next(); + consistencyCheck(peeked); + consistencyCheck(match); + QVERIFY(!match.isValid()); + QVERIFY(!peeked.isValid()); + } + +} + +void tst_QRegularExpression::provideRegularExpressions() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QRegularExpression::PatternOptions>("patternOptions"); + + QTest::newRow("emptynull01") << QString() + << QRegularExpression::PatternOptions(0); + QTest::newRow("emptynull02") << QString() + << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption + | QRegularExpression::DotMatchesEverythingOption + | QRegularExpression::MultilineOption); + QTest::newRow("emptynull03") << "" + << QRegularExpression::PatternOptions(0); + QTest::newRow("emptynull04") << "" + << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption + | QRegularExpression::DotMatchesEverythingOption + | QRegularExpression::MultilineOption); + + QTest::newRow("regexp01") << "a pattern" + << QRegularExpression::PatternOptions(0); + QTest::newRow("regexp02") << "^a (.*) more complicated(?<P>pattern)$" + << QRegularExpression::PatternOptions(0); + QTest::newRow("regexp03") << "(?:a) pAttErN" + << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption); + QTest::newRow("regexp04") << "a\nmultiline\npattern" + << QRegularExpression::PatternOptions(QRegularExpression::MultilineOption); + QTest::newRow("regexp05") << "an extended # IGNOREME\npattern" + << QRegularExpression::PatternOptions(QRegularExpression::ExtendedPatternSyntaxOption); + QTest::newRow("regexp06") << "a [sS]ingleline .* match" + << QRegularExpression::PatternOptions(QRegularExpression::DotMatchesEverythingOption); + QTest::newRow("regexp07") << "multiple.*options" + << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption + | QRegularExpression::DotMatchesEverythingOption + | QRegularExpression::MultilineOption + | QRegularExpression::DontCaptureOption + | QRegularExpression::InvertedGreedinessOption); + + QTest::newRow("unicode01") << QString::fromUtf8("^s[ome] latin-1 \xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99 chars$") + << QRegularExpression::PatternOptions(0); + QTest::newRow("unicode02") << QString::fromUtf8("^s[ome] latin-1 \xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99 chars$") + << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption + | QRegularExpression::DotMatchesEverythingOption + | QRegularExpression::InvertedGreedinessOption); + QTest::newRow("unicode03") << QString::fromUtf8("Unicode \xf0\x9d\x85\x9d \xf0\x9d\x85\x9e\xf0\x9d\x85\x9f") + << QRegularExpression::PatternOptions(0); + QTest::newRow("unicode04") << QString::fromUtf8("Unicode \xf0\x9d\x85\x9d \xf0\x9d\x85\x9e\xf0\x9d\x85\x9f") + << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption + | QRegularExpression::DotMatchesEverythingOption + | QRegularExpression::InvertedGreedinessOption); +} + +void tst_QRegularExpression::gettersSetters_data() +{ + provideRegularExpressions(); +} + +void tst_QRegularExpression::gettersSetters() +{ + QFETCH(QString, pattern); + QFETCH(QRegularExpression::PatternOptions, patternOptions); + { + QRegularExpression re; + re.setPattern(pattern); + QCOMPARE(re.pattern(), pattern); + QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); + } + { + QRegularExpression re; + re.setPatternOptions(patternOptions); + QCOMPARE(re.pattern(), QString()); + QCOMPARE(re.patternOptions(), patternOptions); + } + { + QRegularExpression re(pattern); + QCOMPARE(re.pattern(), pattern); + QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); + } + { + QRegularExpression re(pattern, patternOptions); + QCOMPARE(re.pattern(), pattern); + QCOMPARE(re.patternOptions(), patternOptions); + } +} + +void tst_QRegularExpression::escape_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<QString>("escaped"); + QTest::newRow("escape01") << "a normal pattern" + << "a\\ normal\\ pattern"; + + QTest::newRow("escape02") << "abcdefghijklmnopqrstuvzABCDEFGHIJKLMNOPQRSTUVZ1234567890_" + << "abcdefghijklmnopqrstuvzABCDEFGHIJKLMNOPQRSTUVZ1234567890_"; + + QTest::newRow("escape03") << "^\\ba\\b.*(?<NAME>reg|exp)$" + << "\\^\\\\ba\\\\b\\.\\*\\(\\?\\<NAME\\>reg\\|exp\\)\\$"; + + QString nulString("abcXabcXXabc"); + nulString[3] = nulString[7] = nulString[8] = QChar(0, 0); + QTest::newRow("NUL") << nulString + << "abc\\0abc\\0\\0abc"; + + QTest::newRow("unicode01") << QString::fromUtf8("^s[ome] latin-1 \xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99 chars$") + << QString::fromUtf8("\\^s\\[ome\\]\\ latin\\-1\\ \\\xc3\x80\\\xc3\x88\\\xc3\x8c\\\xc3\x92\\\xc3\x99\\ chars\\$"); + QTest::newRow("unicode02") << QString::fromUtf8("Unicode \xf0\x9d\x85\x9d \xf0\x9d\x85\x9e\xf0\x9d\x85\x9f") + << QString::fromUtf8("Unicode\\ \\\xf0\x9d\x85\x9d\\ \\\xf0\x9d\x85\x9e\\\xf0\x9d\x85\x9f"); + + QString unicodeAndNulString = QString::fromUtf8("^\xc3\x80\xc3\x88\xc3\x8cN\xc3\x92NN\xc3\x99 chars$"); + unicodeAndNulString[4] = unicodeAndNulString[6] = unicodeAndNulString[7] = QChar(0, 0); + QTest::newRow("unicode03") << unicodeAndNulString + << QString::fromUtf8("\\^\\\xc3\x80\\\xc3\x88\\\xc3\x8c\\0\\\xc3\x92\\0\\0\\\xc3\x99\\ chars\\$"); +} + +void tst_QRegularExpression::escape() +{ + QFETCH(QString, string); + QFETCH(QString, escaped); + QCOMPARE(QRegularExpression::escape(string), escaped); + QRegularExpression re(escaped); + QCOMPARE(re.isValid(), true); +} + +void tst_QRegularExpression::validity_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<bool>("validity"); + + QTest::newRow("valid01") << "a pattern" << true; + QTest::newRow("valid02") << "(a|pattern)" << true; + QTest::newRow("valid03") << "a [pP]attern" << true; + QTest::newRow("valid04") << "^(?<article>a).*(?<noun>pattern)$" << true; + QTest::newRow("valid05") << "a \\P{Ll}attern" << true; + + QTest::newRow("invalid01") << "a pattern\\" << false; + QTest::newRow("invalid02") << "(a|pattern" << false; + QTest::newRow("invalid03") << "a \\P{BLAH}attern" << false; + + QString pattern; + // 0xD800 (high surrogate) not followed by a low surrogate + pattern = "abcdef"; + pattern[3] = QChar(0x00, 0xD8); + QTest::newRow("invalidUnicode01") << pattern << false; +} + +void tst_QRegularExpression::validity() +{ + QFETCH(QString, pattern); + QFETCH(bool, validity); + QRegularExpression re(pattern); + QCOMPARE(re.isValid(), validity); + if (!validity) + QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object"); + QRegularExpressionMatch match = re.match("a pattern"); + QCOMPARE(match.isValid(), validity); + consistencyCheck(match); + + if (!validity) + QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object"); + QRegularExpressionMatchIterator iterator = re.globalMatch("a pattern"); + QCOMPARE(iterator.isValid(), validity); +} + +void tst_QRegularExpression::patternOptions_data() +{ + QTest::addColumn<QRegularExpression>("regexp"); + QTest::addColumn<QString>("subject"); + QTest::addColumn<Match>("match"); + + // none of these would successfully match if the respective + // pattern option is not set + + Match m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << QString::fromUtf8("AbC\xc3\xa0"); + QTest::newRow("/i") << QRegularExpression(QString::fromUtf8("abc\xc3\x80"), QRegularExpression::CaseInsensitiveOption) + << QString::fromUtf8("AbC\xc3\xa0") + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "abc123\n678def"; + QTest::newRow("/s") << QRegularExpression("\\Aabc.*def\\z", QRegularExpression::DotMatchesEverythingOption) + << "abc123\n678def" + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "jumped over"; + QTest::newRow("/m") << QRegularExpression("^\\w+ \\w+$", QRegularExpression::MultilineOption) + << "the quick fox\njumped over\nthe lazy\ndog" + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "abc 123456"; + QTest::newRow("/x") << QRegularExpression("\\w+ # a word\n" + "\\ # a space\n" + "\\w+ # another word", + QRegularExpression::ExtendedPatternSyntaxOption) + << "abc 123456 def" + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "the quick fox" << "the" << "quick fox"; + QTest::newRow("/U") << QRegularExpression("(.+) (.+?)", QRegularExpression::InvertedGreedinessOption) + << "the quick fox" + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "the quick fox" << "quick"; + m.namedCaptured["named"] = "quick"; + QTest::newRow("no cap") << QRegularExpression("(\\w+) (?<named>\\w+) (\\w+)", QRegularExpression::DontCaptureOption) + << "the quick fox" + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << QString::fromUtf8("abc\xc3\x80\xc3\xa0 12\xdb\xb1\xdb\xb2\xf0\x9d\x9f\x98") + << QString::fromUtf8("abc\xc3\x80\xc3\xa0") + << QString::fromUtf8("12\xdb\xb1\xdb\xb2\xf0\x9d\x9f\x98"); + QTest::newRow("unicode properties") << QRegularExpression("(\\w+) (\\d+)", QRegularExpression::UseUnicodePropertiesOption) + << QString::fromUtf8("abc\xc3\x80\xc3\xa0 12\xdb\xb1\xdb\xb2\xf0\x9d\x9f\x98") + << m; +} + +void tst_QRegularExpression::patternOptions() +{ + QFETCH(QRegularExpression, regexp); + QFETCH(QString, subject); + QFETCH(Match, match); + + QRegularExpressionMatch m = regexp.match(subject); + consistencyCheck(m); + QVERIFY(m == match); +} + +void tst_QRegularExpression::normalMatch_data() +{ + QTest::addColumn<QRegularExpression>("regexp"); + QTest::addColumn<QString>("subject"); + QTest::addColumn<int>("offset"); + QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions"); + QTest::addColumn<Match>("match"); + + Match m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "string" << "string"; + QTest::newRow("match01") << QRegularExpression("(\\bstring\\b)") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "a string" << "a" << "string"; + QTest::newRow("match02") << QRegularExpression("(\\w+) (\\w+)") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "a string" << "a" << "string"; + m.namedCaptured["article"] = "a"; + m.namedCaptured["noun"] = "string"; + QTest::newRow("match03") << QRegularExpression("(?<article>\\w+) (?<noun>\\w+)") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << " string" << QString() << "string"; + QTest::newRow("match04") << QRegularExpression("(\\w+)? (\\w+)") + << " string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << " string" << QString("") << "string"; + QTest::newRow("match05") << QRegularExpression("(\\w*) (\\w+)") + << " string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "c123def" << "c12" << "3" << "def"; + QTest::newRow("match06") << QRegularExpression("(\\w*)(\\d+)(\\w*)") + << "abc123def" + << 2 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << QString(""); + QTest::newRow("match07") << QRegularExpression("\\w*") + << "abc123def" + << 9 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << QString("a string") << QString("a string") << QString(""); + QTest::newRow("match08") << QRegularExpression("(.*)(.*)") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << QString("a string") << QString("") << QString("a string"); + QTest::newRow("match09") << QRegularExpression("(.*?)(.*)") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + // *** + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch01") << QRegularExpression("\\d+") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch02") << QRegularExpression("(\\w+) (\\w+)") + << "a string" + << 1 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch03") << QRegularExpression("\\w+") + << "abc123def" + << 9 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + // *** + + m.clear(); + m.isValid = true; + QTest::newRow("anchoredmatch01") << QRegularExpression("\\d+") + << "abc123def" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::AnchoredMatchOption) + << m; +} + + +void tst_QRegularExpression::normalMatch() +{ + QFETCH(QRegularExpression, regexp); + QFETCH(QString, subject); + QFETCH(int, offset); + QFETCH(QRegularExpression::MatchOptions, matchOptions); + QFETCH(Match, match); + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); +} + + +void tst_QRegularExpression::partialMatch_data() +{ + QTest::addColumn<QRegularExpression>("regexp"); + QTest::addColumn<QString>("subject"); + QTest::addColumn<int>("offset"); + QTest::addColumn<QRegularExpression::MatchType>("matchType"); + QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions"); + QTest::addColumn<Match>("match"); + + Match m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "str"; + QTest::newRow("softmatch01") << QRegularExpression("string") + << "a str" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << " str"; + QTest::newRow("softmatch02") << QRegularExpression("\\bstring\\b") + << "a str" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << " str"; + QTest::newRow("softmatch03") << QRegularExpression("(\\bstring\\b)") + << "a str" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "8 Dec 19"; + QTest::newRow("softmatch04") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$") + << "8 Dec 19" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "8 Dec 1985" << "8" << "Dec" << "1985"; + QTest::newRow("softmatch05") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$") + << "8 Dec 1985" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "def"; + QTest::newRow("softmatch06") << QRegularExpression("abc\\w+X|def") + << "abcdef" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "abcdef"; + QTest::newRow("softmatch07") << QRegularExpression("abc\\w+X|defY") + << "abcdef" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "def"; + QTest::newRow("softmatch08") << QRegularExpression("abc\\w+X|defY") + << "abcdef" + << 1 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + // *** + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "str"; + QTest::newRow("hardmatch01") << QRegularExpression("string") + << "a str" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << " str"; + QTest::newRow("hardmatch02") << QRegularExpression("\\bstring\\b") + << "a str" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << " str"; + QTest::newRow("hardmatch03") << QRegularExpression("(\\bstring\\b)") + << "a str" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "8 Dec 19"; + QTest::newRow("hardmatch04") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$") + << "8 Dec 19" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "8 Dec 1985"; + QTest::newRow("hardmatch05") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$") + << "8 Dec 1985" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "abcdef"; + QTest::newRow("hardmatch06") << QRegularExpression("abc\\w+X|def") + << "abcdef" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "abcdef"; + QTest::newRow("hardmatch07") << QRegularExpression("abc\\w+X|defY") + << "abcdef" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "def"; + QTest::newRow("hardmatch08") << QRegularExpression("abc\\w+X|defY") + << "abcdef" + << 1 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "ab"; + QTest::newRow("hardmatch09") << QRegularExpression("abc|ab") + << "ab" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "abc"; + QTest::newRow("hardmatch10") << QRegularExpression("abc(def)?") + << "abc" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasPartialMatch = true; + m.captured << "abc"; + QTest::newRow("hardmatch11") << QRegularExpression("(abc)*") + << "abc" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + + // *** + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch01") << QRegularExpression("abc\\w+X|defY") + << "123456" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch02") << QRegularExpression("abc\\w+X|defY") + << "123456" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch03") << QRegularExpression("abc\\w+X|defY") + << "ab123" + << 0 + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; + QTest::newRow("nomatch04") << QRegularExpression("abc\\w+X|defY") + << "ab123" + << 0 + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + +} + +void tst_QRegularExpression::partialMatch() +{ + QFETCH(QRegularExpression, regexp); + QFETCH(QString, subject); + QFETCH(int, offset); + QFETCH(QRegularExpression::MatchType, matchType); + QFETCH(QRegularExpression::MatchOptions, matchOptions); + QFETCH(Match, match); + + QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); +} + +void tst_QRegularExpression::globalMatch_data() +{ + QTest::addColumn<QRegularExpression>("regexp"); + QTest::addColumn<QString>("subject"); + QTest::addColumn<int>("offset"); + QTest::addColumn<QRegularExpression::MatchType>("matchType"); + QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions"); + QTest::addColumn<QList<Match> >("matchList"); + + QList<Match> matchList; + Match m; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the"; + matchList << m; + m.captured = QStringList() << "quick"; + matchList << m; + m.captured = QStringList() << "fox"; + matchList << m; + QTest::newRow("globalmatch01") << QRegularExpression("\\w+") + << "the quick fox" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the" << "t" << "he"; + matchList << m; + m.captured = QStringList() << "quick" << "q" << "uick"; + matchList << m; + m.captured = QStringList() << "fox" << "f" << "ox"; + matchList << m; + QTest::newRow("globalmatch02") << QRegularExpression("(\\w+?)(\\w+)") + << "the quick fox" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "c"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "c"; + matchList << m; + m.captured = QStringList() << "aabb"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + + QTest::newRow("globalmatch_emptycaptures01") << QRegularExpression("a*b*|c") + << "ccaabbd" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "quick"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "fox"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + + QTest::newRow("globalmatch_emptycaptures02") << QRegularExpression(".*") + << "the\nquick\nfox" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "quick"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "fox"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + + QTest::newRow("globalmatch_emptycaptures03") << QRegularExpression(".*") + << "the\nquick\nfox\n" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "quick"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "fox"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + + QTest::newRow("globalmatch_emptycaptures04") << QRegularExpression("(*CRLF).*") + << "the\r\nquick\r\nfox" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "quick"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "fox"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + + QTest::newRow("globalmatch_emptycaptures05") << QRegularExpression("(*CRLF).*") + << "the\r\nquick\r\nfox\r\n" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; + + matchList.clear(); + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured = QStringList() << "the"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "quick"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "fox"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + m.captured = QStringList() << "jumped"; + matchList << m; + m.captured = QStringList() << ""; + matchList << m; + + QTest::newRow("globalmatch_emptycaptures06") << QRegularExpression("(*ANYCRLF).*") + << "the\r\nquick\nfox\rjumped" + << 0 + << QRegularExpression::NormalMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << matchList; +} + +void tst_QRegularExpression::globalMatch() +{ + QFETCH(QRegularExpression, regexp); + QFETCH(QString, subject); + QFETCH(int, offset); + QFETCH(QRegularExpression::MatchType, matchType); + QFETCH(QRegularExpression::MatchOptions, matchOptions); + QFETCH(QList<Match>, matchList); + + QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions); + consistencyCheck(iterator); + QVERIFY(iterator == matchList); +} + +void tst_QRegularExpression::serialize_data() +{ + provideRegularExpressions(); +} + +void tst_QRegularExpression::serialize() +{ + QFETCH(QString, pattern); + QFETCH(QRegularExpression::PatternOptions, patternOptions); + QRegularExpression outRe(pattern, patternOptions); + QByteArray buffer; + { + QDataStream out(&buffer, QIODevice::WriteOnly); + out << outRe; + } + QRegularExpression inRe; + { + QDataStream in(&buffer, QIODevice::ReadOnly); + in >> inRe; + } + QCOMPARE(inRe, outRe); +} + +static void verifyEquality(const QRegularExpression &re1, const QRegularExpression &re2) +{ + QVERIFY(re1 == re2); + QVERIFY(re2 == re1); + QVERIFY(!(re1 != re2)); + QVERIFY(!(re2 != re1)); + + QRegularExpression re3(re1); + + QVERIFY(re1 == re3); + QVERIFY(re3 == re1); + QVERIFY(!(re1 != re3)); + QVERIFY(!(re3 != re1)); + + QVERIFY(re2 == re3); + QVERIFY(re3 == re2); + QVERIFY(!(re2 != re3)); + QVERIFY(!(re3 != re2)); + + re3 = re2; + QVERIFY(re1 == re3); + QVERIFY(re3 == re1); + QVERIFY(!(re1 != re3)); + QVERIFY(!(re3 != re1)); + + QVERIFY(re2 == re3); + QVERIFY(re3 == re2); + QVERIFY(!(re2 != re3)); + QVERIFY(!(re3 != re2)); +} + +void tst_QRegularExpression::operatoreq_data() +{ + provideRegularExpressions(); +} + +void tst_QRegularExpression::operatoreq() +{ + QFETCH(QString, pattern); + QFETCH(QRegularExpression::PatternOptions, patternOptions); + { + QRegularExpression re1(pattern); + QRegularExpression re2(pattern); + verifyEquality(re1, re2); + } + { + QRegularExpression re1(QString(), patternOptions); + QRegularExpression re2(QString(), patternOptions); + verifyEquality(re1, re2); + } + { + QRegularExpression re1(pattern, patternOptions); + QRegularExpression re2(pattern, patternOptions); + verifyEquality(re1, re2); + } +} + +void tst_QRegularExpression::captureCount_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<int>("captureCount"); + QTest::newRow("captureCount01") << "a pattern" << 0; + QTest::newRow("captureCount02") << "a.*pattern" << 0; + QTest::newRow("captureCount03") << "(a) pattern" << 1; + QTest::newRow("captureCount04") << "(a).*(pattern)" << 2; + QTest::newRow("captureCount05") << "^(?<article>\\w+) (?<noun>\\w+)$" << 2; + QTest::newRow("captureCount06") << "^(\\w+) (?<word>\\w+) (.)$" << 3; + QTest::newRow("captureCount07") << "(?:non capturing) (capturing) (?<n>named) (?:non (capturing))" << 3; + QTest::newRow("captureCount08") << "(?|(a)(b)|(c)(d))" << 2; + QTest::newRow("captureCount09") << "(?|(a)(b)|(c)(d)(?:e))" << 2; + QTest::newRow("captureCount10") << "(?|(a)(b)|(c)(d)(e)) (f)(g)" << 5; + QTest::newRow("captureCount11") << "(?|(a)(b)|(c)(d)(e)) (f)(?:g)" << 4; + QTest::newRow("captureCount_invalid01") << "(.*" << -1; + QTest::newRow("captureCount_invalid02") << "\\" << -1; + QTest::newRow("captureCount_invalid03") << "(?<noun)" << -1; +} + +void tst_QRegularExpression::captureCount() +{ + QFETCH(QString, pattern); + QRegularExpression re(pattern); + QTEST(re.captureCount(), "captureCount"); + if (!re.isValid()) + QCOMPARE(re.captureCount(), -1); +} diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h new file mode 100644 index 0000000000..1a703a8f92 --- /dev/null +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qobject.h> +#include <qregularexpression.h> + +Q_DECLARE_METATYPE(QRegularExpression::PatternOptions) +Q_DECLARE_METATYPE(QRegularExpression::MatchType) +Q_DECLARE_METATYPE(QRegularExpression::MatchOptions) + +class tst_QRegularExpression : public QObject +{ + Q_OBJECT + +private slots: + void gettersSetters_data(); + void gettersSetters(); + void escape_data(); + void escape(); + void validity_data(); + void validity(); + void patternOptions_data(); + void patternOptions(); + void normalMatch_data(); + void normalMatch(); + void partialMatch_data(); + void partialMatch(); + void globalMatch_data(); + void globalMatch(); + void serialize_data(); + void serialize(); + void operatoreq_data(); + void operatoreq(); + void captureCount_data(); + void captureCount(); + +private: + void provideRegularExpressions(); +}; diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 88c5e5b595..a8f706ff80 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -4217,16 +4217,7 @@ void tst_QString::tortureSprintfDouble() # error "Q_BYTE_ORDER not defined" # endif -# ifdef QT_ARMFPA - buff[0] = data->bytes[4]; - buff[1] = data->bytes[5]; - buff[2] = data->bytes[6]; - buff[3] = data->bytes[7]; - buff[4] = data->bytes[0]; - buff[5] = data->bytes[1]; - buff[6] = data->bytes[2]; - buff[7] = data->bytes[3]; -# elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN +# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN for (uint i = 0; i < 8; ++i) buff[i] = data->bytes[i]; # else diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp index afc16078b8..556b9ac16a 100644 --- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -73,6 +73,7 @@ void runScenario() QString string(l1string); QStringRef stringref(&string, 2, 10); QLatin1Char achar('c'); + QChar::SpecialCharacter special(QChar::Nbsp); QString r2(QLatin1String(LITERAL LITERAL)); QString r3 = QString::fromUtf8(UTF8_LITERAL UTF8_LITERAL); QString r; @@ -97,6 +98,8 @@ void runScenario() QCOMPARE(r, QString(string P achar)); r = achar + string; QCOMPARE(r, QString(achar P string)); + r = special + string; + QCOMPARE(r, QString(special P string)); #ifdef Q_COMPILER_UNICODE_STRINGS r = QStringLiteral(UNICODE_LITERAL); diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index e2002a98b6..38225e12f7 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -21,10 +21,12 @@ SUBDIRS=\ qlocale \ qmap \ qmargins \ + qpair \ qpoint \ qqueue \ qrect \ qregexp \ + qregularexpression \ qringbuffer \ qscopedpointer \ qscopedvaluerollback \ |