diff options
Diffstat (limited to 'tests/auto/corelib/tools')
16 files changed, 393 insertions, 304 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 38366e86ff..b40b1f0624 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -2620,6 +2620,8 @@ void testLinkedListLikeStlIterators() QVERIFY(i2 == c2); QVERIFY(c2 == i2); QVERIFY(c2 == c2); + QVERIFY(1 + i1 == i1 + 1); + QVERIFY(1 + c1 == c1 + 1); QVERIFY(i1 != i2); QVERIFY(i1 != c2); @@ -2731,6 +2733,8 @@ void testMapLikeStlIterators() QVERIFY(i2 == c2); QVERIFY(c2 == i2); QVERIFY(c2 == c2); + QVERIFY(1 + i1 == i1 + 1); + QVERIFY(1 + c1 == c1 + 1); QVERIFY(i1 != i2); QVERIFY(i1 != c2); diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 338adaabf7..ecfa331141 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -141,6 +141,8 @@ private slots: #endif void toUpperLower_data(); void toUpperLower(); + void isUpper(); + void isLower(); void macTypes(); @@ -856,15 +858,38 @@ void tst_QByteArray::qstricmp() if ( actual != 0 ) { actual = (actual < 0 ? -1 : 1); } - QCOMPARE(expected, actual); + QCOMPARE(actual, expected); + + actual = ::qstricmp("012345679abcd" + str1.toLatin1(), "012345679AbCd" + str2.toLatin1()); + if ( actual != 0 ) { + actual = (actual < 0 ? -1 : 1); + } + QCOMPARE(actual, expected); + + actual = str1.toLatin1().compare(str2.toLatin1(), Qt::CaseInsensitive); + if ( actual != 0 ) { + actual = (actual < 0 ? -1 : 1); + } + QCOMPARE(actual, expected); + + actual = str1.toLatin1().compare(str2.toLatin1().constData(), Qt::CaseInsensitive); + if ( actual != 0 ) { + actual = (actual < 0 ? -1 : 1); + } + QCOMPARE(actual, expected); } void tst_QByteArray::qstricmp_singularities() { QCOMPARE(::qstricmp(0, 0), 0); - QVERIFY(::qstricmp(0, "a") != 0); - QVERIFY(::qstricmp("a", 0) != 0); + QVERIFY(::qstricmp(0, "a") < 0); + QVERIFY(::qstricmp("a", 0) > 0); QCOMPARE(::qstricmp("", ""), 0); + QCOMPARE(QByteArray().compare(nullptr, Qt::CaseInsensitive), 0); + QCOMPARE(QByteArray().compare("", Qt::CaseInsensitive), 0); + QVERIFY(QByteArray("a").compare(nullptr, Qt::CaseInsensitive) > 0); + QVERIFY(QByteArray("a").compare("", Qt::CaseInsensitive) > 0); + QVERIFY(QByteArray().compare("a", Qt::CaseInsensitive) < 0); } void tst_QByteArray::qstrnicmp_singularities() @@ -874,6 +899,9 @@ void tst_QByteArray::qstrnicmp_singularities() QVERIFY(::qstrnicmp("a", 0, 123) != 0); QCOMPARE(::qstrnicmp("", "", 123), 0); QCOMPARE(::qstrnicmp("a", "B", 0), 0); + QCOMPARE(QByteArray().compare(QByteArray(), Qt::CaseInsensitive), 0); + QVERIFY(QByteArray().compare(QByteArray("a"), Qt::CaseInsensitive) < 0); + QVERIFY(QByteArray("a").compare(QByteArray(), Qt::CaseInsensitive) > 0); } void tst_QByteArray::chop_data() @@ -1757,6 +1785,12 @@ void tst_QByteArray::compare() const bool isLess = result < 0; const bool isGreater = result > 0; + int cmp = str1.compare(str2); + if (cmp) + cmp = (cmp < 0 ? -1 : 1); + + QCOMPARE(cmp, result); + // basic tests: QCOMPARE(str1 == str2, isEqual); QCOMPARE(str1 < str2, isLess); @@ -2188,6 +2222,51 @@ void tst_QByteArray::toUpperLower() QCOMPARE(qMove(copy).toUpper(), upper); } +void tst_QByteArray::isUpper() +{ + QVERIFY(!QByteArray().isUpper()); + QVERIFY(!QByteArray("").isUpper()); + QVERIFY(QByteArray("TEXT").isUpper()); + QVERIFY(QByteArray("\xD0\xDE").isUpper()); + QVERIFY(!QByteArray("\xD7").isUpper()); // multiplication sign is not upper + QVERIFY(!QByteArray("\xDF").isUpper()); // sz ligature is not upper + QVERIFY(!QByteArray("text").isUpper()); + QVERIFY(!QByteArray("Text").isUpper()); + QVERIFY(!QByteArray("tExt").isUpper()); + QVERIFY(!QByteArray("teXt").isUpper()); + QVERIFY(!QByteArray("texT").isUpper()); + QVERIFY(!QByteArray("TExt").isUpper()); + QVERIFY(!QByteArray("teXT").isUpper()); + QVERIFY(!QByteArray("tEXt").isUpper()); + QVERIFY(!QByteArray("tExT").isUpper()); + QVERIFY(!QByteArray("@ABYZ[").isUpper()); + QVERIFY(!QByteArray("@abyz[").isUpper()); + QVERIFY(!QByteArray("`ABYZ{").isUpper()); + QVERIFY(!QByteArray("`abyz{").isUpper()); +} + +void tst_QByteArray::isLower() +{ + QVERIFY(!QByteArray().isLower()); + QVERIFY(!QByteArray("").isLower()); + QVERIFY(QByteArray("text").isLower()); + QVERIFY(QByteArray("\xE0\xFF").isLower()); + QVERIFY(!QByteArray("\xF7").isLower()); // division sign is not lower + QVERIFY(!QByteArray("Text").isLower()); + QVERIFY(!QByteArray("tExt").isLower()); + QVERIFY(!QByteArray("teXt").isLower()); + QVERIFY(!QByteArray("texT").isLower()); + QVERIFY(!QByteArray("TExt").isLower()); + QVERIFY(!QByteArray("teXT").isLower()); + QVERIFY(!QByteArray("tEXt").isLower()); + QVERIFY(!QByteArray("tExT").isLower()); + QVERIFY(!QByteArray("TEXT").isLower()); + QVERIFY(!QByteArray("@ABYZ[").isLower()); + QVERIFY(!QByteArray("@abyz[").isLower()); + QVERIFY(!QByteArray("`ABYZ{").isLower()); + QVERIFY(!QByteArray("`abyz{").isLower()); +} + void tst_QByteArray::macTypes() { #ifndef Q_OS_MAC diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 17a0f3edd9..3eef7631c8 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -29,6 +29,7 @@ #include <QtCore/QCoreApplication> #include <QtTest/QtTest> +#include <QtCore/QMetaEnum> Q_DECLARE_METATYPE(QCryptographicHash::Algorithm) @@ -45,6 +46,7 @@ private slots: void sha3(); void files_data(); void files(); + void hashLength(); }; void tst_QCryptographicHash::repeated_result_data() @@ -291,6 +293,15 @@ void tst_QCryptographicHash::files() } } +void tst_QCryptographicHash::hashLength() +{ + auto metaEnum = QMetaEnum::fromType<QCryptographicHash::Algorithm>(); + for (int i = 0, value = metaEnum.value(i); value != -1; value = metaEnum.value(++i)) { + auto algorithm = QCryptographicHash::Algorithm(value); + QByteArray output = QCryptographicHash::hash(QByteArrayLiteral("test"), algorithm); + QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length()); + } +} QTEST_MAIN(tst_QCryptographicHash) #include "tst_qcryptographichash.moc" diff --git a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp index f545ead1f1..e89e634841 100644 --- a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp +++ b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp @@ -159,6 +159,8 @@ void tst_QExplicitlySharedDataPointer::data() const { QExplicitlySharedDataPointer<const MyClass> pointer; QCOMPARE(pointer.data(), static_cast<const MyClass *>(0)); + QVERIFY(pointer == nullptr); + QVERIFY(nullptr == pointer); } /* On const pointer. Must not mutate the pointer. */ @@ -168,6 +170,9 @@ void tst_QExplicitlySharedDataPointer::data() const /* Check that this cast is possible. */ static_cast<const MyClass *>(pointer.data()); + + QVERIFY(! (pointer == nullptr)); + QVERIFY(! (nullptr == pointer)); } /* On mutatable pointer. Must not mutate the pointer. */ diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro deleted file mode 100644 index a27286ff20..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -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 deleted file mode 100644 index 6d2ae48235..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $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 deleted file mode 100644 index 0b36c79c1b..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -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 deleted file mode 100644 index a815c6cab9..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $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/forceoptimize/forceoptimize.pro b/tests/auto/corelib/tools/qregularexpression/forceoptimize/forceoptimize.pro deleted file mode 100644 index 1db77781dd..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/forceoptimize/forceoptimize.pro +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG += testcase -TARGET = tst_qregularexpression_forceoptimize -QT = core testlib -HEADERS = ../tst_qregularexpression.h -SOURCES = \ - tst_qregularexpression_forceoptimize.cpp \ - ../tst_qregularexpression.cpp -DEFINES += forceOptimize=true diff --git a/tests/auto/corelib/tools/qregularexpression/forceoptimize/tst_qregularexpression_forceoptimize.cpp b/tests/auto/corelib/tools/qregularexpression/forceoptimize/tst_qregularexpression_forceoptimize.cpp deleted file mode 100644 index 38a3a64fa3..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/forceoptimize/tst_qregularexpression_forceoptimize.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "../tst_qregularexpression.h" - -class tst_QRegularExpression_ForceOptimize : public tst_QRegularExpression -{ - Q_OBJECT -}; - -QTEST_APPLESS_MAIN(tst_QRegularExpression_ForceOptimize) - -#include "tst_qregularexpression_forceoptimize.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro index e1840808ff..ec8189717e 100644 --- a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro +++ b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro @@ -1,3 +1,4 @@ -TEMPLATE = subdirs -SUBDIRS = defaultoptimize forceoptimize -qtConfig(private_tests): SUBDIRS += alwaysoptimize +CONFIG += testcase +TARGET = tst_qregularexpression +QT = core testlib +SOURCES = tst_qregularexpression.cpp diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index c828551e44..5130b7cfcd 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -33,11 +33,60 @@ #include <qstringlist.h> #include <qhash.h> -#include "tst_qregularexpression.h" +#include <qobject.h> +#include <qregularexpression.h> +#include <qthread.h> -#ifndef forceOptimize -#define forceOptimize false -#endif +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 defaultConstructors(); + 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(); + void captureNames_data(); + void captureNames(); + void pcreJitStackUsage_data(); + void pcreJitStackUsage(); + void regularExpressionMatch_data(); + void regularExpressionMatch(); + void JOptionUsage_data(); + void JOptionUsage(); + void QStringAndQStringRefEquivalence(); + void threadSafety_data(); + void threadSafety(); + + void wildcard_data(); + void wildcard(); + void testInvalidWildcard_data(); + void testInvalidWildcard(); + +private: + void provideRegularExpressions(); +}; struct Match { @@ -292,9 +341,6 @@ static void testMatch(const QRegularExpression ®exp, QRegularExpression::MatchOptions matchOptions, const Result &result) { - if (forceOptimize) - regexp.optimize(); - // test with QString as subject type testMatchImpl<QREMatch>(regexp, matchingMethodForString, subject, offset, matchType, matchOptions, result); @@ -401,30 +447,22 @@ void tst_QRegularExpression::gettersSetters() { QRegularExpression re; re.setPattern(pattern); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), pattern); QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); } { QRegularExpression re; re.setPatternOptions(patternOptions); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), QString()); QCOMPARE(re.patternOptions(), patternOptions); } { QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), pattern); QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); } { QRegularExpression re(pattern, patternOptions); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), pattern); QCOMPARE(re.patternOptions(), patternOptions); } @@ -465,8 +503,6 @@ void tst_QRegularExpression::escape() QFETCH(QString, escaped); QCOMPARE(QRegularExpression::escape(string), escaped); QRegularExpression re(escaped); - if (forceOptimize) - re.optimize(); QCOMPARE(re.isValid(), true); } @@ -497,8 +533,6 @@ void tst_QRegularExpression::validity() QFETCH(QString, pattern); QFETCH(bool, validity); QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); QCOMPARE(re.isValid(), validity); if (!validity) QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object"); @@ -585,9 +619,6 @@ void tst_QRegularExpression::patternOptions() QFETCH(QString, subject); QFETCH(Match, match); - if (forceOptimize) - regexp.optimize(); - QRegularExpressionMatch m = regexp.match(subject); consistencyCheck(m); QVERIFY(m == match); @@ -1403,9 +1434,6 @@ void tst_QRegularExpression::serialize() QFETCH(QRegularExpression::PatternOptions, patternOptions); QRegularExpression outRe(pattern, patternOptions); - if (forceOptimize) - outRe.optimize(); - QByteArray buffer; { QDataStream out(&buffer, QIODevice::WriteOnly); @@ -1468,33 +1496,18 @@ void tst_QRegularExpression::operatoreq() QRegularExpression re1(pattern); QRegularExpression re2(pattern); - if (forceOptimize) - re1.optimize(); - if (forceOptimize) - re2.optimize(); - verifyEquality(re1, re2); } { QRegularExpression re1(QString(), patternOptions); QRegularExpression re2(QString(), patternOptions); - if (forceOptimize) - re1.optimize(); - if (forceOptimize) - re2.optimize(); - verifyEquality(re1, re2); } { QRegularExpression re1(pattern, patternOptions); QRegularExpression re2(pattern, patternOptions); - if (forceOptimize) - re1.optimize(); - if (forceOptimize) - re2.optimize(); - verifyEquality(re1, re2); } } @@ -1524,9 +1537,6 @@ void tst_QRegularExpression::captureCount() QFETCH(QString, pattern); QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QTEST(re.captureCount(), "captureCount"); if (!re.isValid()) QCOMPARE(re.captureCount(), -1); @@ -1595,9 +1605,6 @@ void tst_QRegularExpression::captureNames() QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QStringList namedCaptureGroups = re.namedCaptureGroups(); int namedCaptureGroupsCount = namedCaptureGroups.size(); @@ -1633,9 +1640,6 @@ void tst_QRegularExpression::pcreJitStackUsage() QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QVERIFY(re.isValid()); QRegularExpressionMatch match = re.match(subject); consistencyCheck(match); @@ -1663,9 +1667,6 @@ void tst_QRegularExpression::regularExpressionMatch() QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QVERIFY(re.isValid()); QRegularExpressionMatch match = re.match(subject); consistencyCheck(match); @@ -1705,8 +1706,6 @@ void tst_QRegularExpression::JOptionUsage() QRegularExpression re(pattern); if (isValid && JOptionUsed) QTest::ignoreMessage(QtWarningMsg, qPrintable(warningMessage.arg(pattern))); - if (forceOptimize) - re.optimize(); QCOMPARE(re.isValid(), isValid); } @@ -2066,3 +2065,166 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() } } } + +class MatcherThread : public QThread +{ +public: + explicit MatcherThread(const QRegularExpression &re, const QString &subject, QObject *parent = nullptr) + : QThread(parent), + m_re(re), + m_subject(subject) + { + } + +private: + static const int MATCH_ITERATIONS = 50; + + void run() override + { + yieldCurrentThread(); + for (int i = 0; i < MATCH_ITERATIONS; ++i) + m_re.match(m_subject); + } + + const QRegularExpression &m_re; + const QString &m_subject; +}; + +void tst_QRegularExpression::threadSafety_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("subject"); + + int i = 0; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abcd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abbbbcccd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abababcd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abcabcd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abccccccababd"; + + { + QString subject(512*1024, QLatin1Char('x')); + QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; + } + + { + QString subject = "ab"; + subject.append(QString(512*1024, QLatin1Char('x'))); + subject.append("c"); + QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; + } + + { + QString subject = "ab"; + subject.append(QString(512*1024, QLatin1Char('x'))); + subject.append("cd"); + QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; + } + + QTest::addRow("pattern%d", ++i) << "(?(R)a*(?1)|((?R))b)" << "aaaabcde"; + QTest::addRow("pattern%d", ++i) << "(?(R)a*(?1)|((?R))b)" << "aaaaaaabcde"; +} + +void tst_QRegularExpression::threadSafety() +{ + QFETCH(QString, pattern); + QFETCH(QString, subject); + + static const int THREAD_SAFETY_ITERATIONS = 50; + + const int threadCount = qMax(QThread::idealThreadCount(), 4); + + for (int threadSafetyIteration = 0; threadSafetyIteration < THREAD_SAFETY_ITERATIONS; ++threadSafetyIteration) { + QRegularExpression re(pattern); + + QVector<MatcherThread *> threads; + for (int i = 0; i < threadCount; ++i) { + MatcherThread *thread = new MatcherThread(re, subject); + thread->start(); + threads.push_back(thread); + } + + for (int i = 0; i < threadCount; ++i) + threads[i]->wait(); + + qDeleteAll(threads); + } +} + +void tst_QRegularExpression::wildcard_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("string"); + QTest::addColumn<int>("foundIndex"); + + auto addRow = [](const char *pattern, const char *string, int foundIndex) { + QTest::newRow(pattern) << pattern << string << foundIndex; + }; + + addRow("*.html", "test.html", 0); + addRow("*.html", "test.htm", -1); + addRow("bar*", "foobarbaz", 3); + addRow("*", "Qt Rocks!", 0); + addRow(".html", "test.html", 4); + addRow(".h", "test.cpp", -1); + addRow(".???l", "test.html", 4); + addRow("?", "test.html", 0); + addRow("?m", "test.html", 6); + addRow(".h[a-z]ml", "test.html", 4); + addRow(".h[A-Z]ml", "test.html", -1); + addRow(".h[A-Z]ml", "test.hTml", 4); + addRow(".h[!A-Z]ml", "test.hTml", -1); + addRow(".h[!A-Z]ml", "test.html", 4); + addRow(".h[!T]ml", "test.hTml", -1); + addRow(".h[!T]ml", "test.html", 4); + addRow(".h[!T]m[!L]", "test.htmL", -1); + addRow(".h[!T]m[!L]", "test.html", 4); + addRow(".h[][!]", "test.h]ml", 4); + addRow(".h[][!]", "test.h[ml", 4); + addRow(".h[][!]", "test.h!ml", 4); +} + +void tst_QRegularExpression::wildcard() +{ + QFETCH(QString, pattern); + QFETCH(QString, string); + QFETCH(int, foundIndex); + + QRegularExpression re; + re.setWildcardPattern(pattern); + + QRegularExpressionMatch match = re.match(string); + + QCOMPARE(match.capturedStart(), foundIndex); +} + +void tst_QRegularExpression::testInvalidWildcard_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<bool>("isValid"); + + QTest::newRow("valid []") << "[abc]" << true; + QTest::newRow("valid ending ]") << "abc]" << true; + QTest::newRow("invalid [") << "[abc" << false; + QTest::newRow("ending [") << "abc[" << false; + QTest::newRow("ending [^") << "abc[^" << false; + QTest::newRow("ending [\\") << "abc[\\" << false; + QTest::newRow("ending []") << "abc[]" << false; + QTest::newRow("ending [[") << "abc[[" << false; +} + +void tst_QRegularExpression::testInvalidWildcard() +{ + QFETCH(QString, pattern); + + QRegularExpression re; + re.setWildcardPattern(pattern); + + QFETCH(bool, isValid); + QCOMPARE(re.isValid(), isValid); +} + +QTEST_APPLESS_MAIN(tst_QRegularExpression) + +#include "tst_qregularexpression.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h deleted file mode 100644 index 8bb4aa0cce..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $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 defaultConstructors(); - 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(); - void captureNames_data(); - void captureNames(); - void pcreJitStackUsage_data(); - void pcreJitStackUsage(); - void regularExpressionMatch_data(); - void regularExpressionMatch(); - void JOptionUsage_data(); - void JOptionUsage(); - void QStringAndQStringRefEquivalence(); - -private: - void provideRegularExpressions(); -}; diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 2074c9789a..cdabd51d43 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -450,6 +450,8 @@ private slots: void trimmed(); void toUpper(); void toLower(); + void isUpper(); + void isLower(); void toCaseFolded(); void rightJustified(); void leftJustified(); @@ -529,10 +531,8 @@ private slots: void integer_conversion(); void tortureSprintfDouble(); void toNum(); -#if !defined(Q_OS_WIN) void localeAwareCompare_data(); void localeAwareCompare(); -#endif void reverseIterators(); void split_data(); void split(); @@ -2315,6 +2315,46 @@ void tst_QString::toLower() #endif } +void tst_QString::isUpper() +{ + QVERIFY(!QString().isUpper()); + QVERIFY(!QString("").isUpper()); + QVERIFY(QString("TEXT").isUpper()); + QVERIFY(!QString("text").isUpper()); + QVERIFY(!QString("Text").isUpper()); + QVERIFY(!QString("tExt").isUpper()); + QVERIFY(!QString("teXt").isUpper()); + QVERIFY(!QString("texT").isUpper()); + QVERIFY(!QString("TExt").isUpper()); + QVERIFY(!QString("teXT").isUpper()); + QVERIFY(!QString("tEXt").isUpper()); + QVERIFY(!QString("tExT").isUpper()); + QVERIFY(!QString("@ABYZ[").isUpper()); + QVERIFY(!QString("@abyz[").isUpper()); + QVERIFY(!QString("`ABYZ{").isUpper()); + QVERIFY(!QString("`abyz{").isUpper()); +} + +void tst_QString::isLower() +{ + QVERIFY(!QString().isLower()); + QVERIFY(!QString("").isLower()); + QVERIFY(QString("text").isLower()); + QVERIFY(!QString("Text").isLower()); + QVERIFY(!QString("tExt").isLower()); + QVERIFY(!QString("teXt").isLower()); + QVERIFY(!QString("texT").isLower()); + QVERIFY(!QString("TExt").isLower()); + QVERIFY(!QString("teXT").isLower()); + QVERIFY(!QString("tEXt").isLower()); + QVERIFY(!QString("tExT").isLower()); + QVERIFY(!QString("TEXT").isLower()); + QVERIFY(!QString("@ABYZ[").isLower()); + QVERIFY(!QString("@abyz[").isLower()); + QVERIFY(!QString("`ABYZ{").isLower()); + QVERIFY(!QString("`abyz{").isLower()); +} + void tst_QString::toCaseFolded() { QCOMPARE( QString().toCaseFolded(), QString() ); @@ -5468,8 +5508,6 @@ void tst_QString::tortureSprintfDouble() #include <locale.h> -#if !defined(Q_OS_WIN) -// On Q_OS_WIN, we cannot set the system or user locale void tst_QString::localeAwareCompare_data() { QTest::addColumn<QString>("locale"); @@ -5477,6 +5515,15 @@ void tst_QString::localeAwareCompare_data() QTest::addColumn<QString>("s2"); QTest::addColumn<int>("result"); + // Compare decomposed and composed form + { + // From ES6 test262 test suite (built-ins/String/prototype/localeCompare/15.5.4.9_CE.js), addressing from Unicode 5.0, chapter 3.12. Boils + // down to this one-liner: console.log("\u1111\u1171\u11B6".localeCompare("\ud4db") + QTest::newRow("normalize") << QString() << QString::fromUtf8("\xED\x93\x9B") << QString::fromUtf8("\xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6") << 0; + } + +#if !defined(Q_OS_WIN) +// On Q_OS_WIN, we cannot set the system or user locale /* The C locale performs pure byte comparisons for Latin-1-specific characters (I think). Compare with Swedish @@ -5537,6 +5584,7 @@ void tst_QString::localeAwareCompare_data() QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1; QTest::newRow("german3") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1; #endif +#endif //!defined(Q_OS_WIN) } void tst_QString::localeAwareCompare() @@ -5549,17 +5597,17 @@ void tst_QString::localeAwareCompare() QStringRef r1(&s1, 0, s1.length()); QStringRef r2(&s2, 0, s2.length()); + if (!locale.isEmpty()) { #if defined (Q_OS_DARWIN) || defined(QT_USE_ICU) - QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)"); + QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)"); #else - if (!locale.isEmpty()) { const char *newLocale = setlocale(LC_ALL, locale.toLatin1()); if (!newLocale) { setlocale(LC_ALL, ""); QSKIP("Please install the proper locale on this machine to test properly"); } - } #endif + } #ifdef QT_USE_ICU // ### for c1, ICU disagrees with libc on how to compare @@ -5614,7 +5662,6 @@ void tst_QString::localeAwareCompare() if (!locale.isEmpty()) setlocale(LC_ALL, ""); } -#endif //!defined(Q_OS_WIN) void tst_QString::reverseIterators() { diff --git a/tests/auto/corelib/tools/qtimezone/qtimezone.pro b/tests/auto/corelib/tools/qtimezone/qtimezone.pro index 19ebc13306..5ec8d008e7 100644 --- a/tests/auto/corelib/tools/qtimezone/qtimezone.pro +++ b/tests/auto/corelib/tools/qtimezone/qtimezone.pro @@ -3,7 +3,7 @@ TARGET = tst_qtimezone QT = core-private testlib SOURCES = tst_qtimezone.cpp qtConfig(icu) { - DEFINES += QT_USE_ICU + QMAKE_USE_PRIVATE += icu } darwin { diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index ed80d4528d..d335dae7bc 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -31,6 +31,10 @@ #include <private/qtimezoneprivate_p.h> #include <qlocale.h> +#if defined(Q_OS_WIN) && !QT_CONFIG(icu) +# define USING_WIN_TZ +#endif + class tst_QTimeZone : public QObject { Q_OBJECT @@ -413,7 +417,7 @@ void tst_QTimeZone::specificTransition_data() QTest::addColumn<int>("dstoff"); // Moscow ditched DST on 2010-10-31 but has since changed standard offset twice. -#ifdef Q_OS_WIN +#ifdef USING_WIN_TZ // Win7 is too old to know about this transition: if (QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7) #endif @@ -477,8 +481,9 @@ void tst_QTimeZone::transitionEachZone_data() }; QString name; + const auto zones = QTimeZone::availableTimeZoneIds(); for (int k = sizeof(table) / sizeof(table[0]); k-- > 0; ) { - foreach (QByteArray zone, QTimeZone::availableTimeZoneIds()) { + for (const QByteArray &zone : zones) { name.sprintf("%s@%d", zone.constData(), table[k].year); QTest::newRow(name.toUtf8().constData()) << zone @@ -500,7 +505,7 @@ void tst_QTimeZone::transitionEachZone() QTimeZone named(zone); for (int i = start; i < stop; i++) { -#ifdef Q_OS_WIN +#ifdef USING_WIN_TZ // See QTBUG-64985: MS's TZ APIs' misdescription of Europe/Samara leads // to mis-disambiguation of its fall-back here. if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7 @@ -833,7 +838,7 @@ void tst_QTimeZone::utcTest() void tst_QTimeZone::icuTest() { -#if defined(QT_BUILD_INTERNAL) && defined(QT_USE_ICU) +#if defined(QT_BUILD_INTERNAL) && QT_CONFIG(icu) // Known datetimes qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); @@ -881,7 +886,7 @@ void tst_QTimeZone::icuTest() testCetPrivate(tzp); testEpochTranPrivate(QIcuTimeZonePrivate("America/Toronto")); -#endif // QT_USE_ICU +#endif // icu } void tst_QTimeZone::tzTest() @@ -907,7 +912,7 @@ void tst_QTimeZone::tzTest() QLocale enUS("en_US"); // Only test names in debug mode, names used can vary by ICU version installed if (debug) { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, enUS), QString("Central European Standard Time")); QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::ShortName, enUS), @@ -946,7 +951,7 @@ void tst_QTimeZone::tzTest() QString("CET")); QCOMPARE(tzp.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName, enUS), QString("CET")); -#endif // QT_USE_ICU +#endif // icu // Test Abbreviations QCOMPARE(tzp.abbreviation(std), QString("CET")); @@ -1123,7 +1128,7 @@ void tst_QTimeZone::darwinTypes() void tst_QTimeZone::winTest() { -#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) +#if defined(QT_BUILD_INTERNAL) && defined(USING_WIN_TZ) // Known datetimes qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); @@ -1174,7 +1179,7 @@ void tst_QTimeZone::winTest() testCetPrivate(tzp); testEpochTranPrivate(QWinTimeZonePrivate("America/Toronto")); -#endif // Q_OS_WIN +#endif // QT_BUILD_INTERNAL && USING_WIN_TZ } #ifdef QT_BUILD_INTERNAL @@ -1286,7 +1291,7 @@ void tst_QTimeZone::testEpochTranPrivate(const QTimeZonePrivate &tzp) // 1970-04-26 02:00 EST, -5 -> -4 const QDateTime after = QDateTime(QDate(1970, 4, 26), QTime(2, 0), Qt::OffsetFromUTC, -5 * 3600); const QDateTime found = QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC); -#ifdef Q_OS_WIN // MS gets the date wrong: 5th April instead of 26th. +#ifdef USING_WIN_TZ // MS gets the date wrong: 5th April instead of 26th. QCOMPARE(found.toOffsetFromUtc(-5 * 3600).time(), after.time()); #else QCOMPARE(found, after); |