summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp29
-rw-r--r--tests/auto/corelib/tools/qdatetime/qdatetime.pro5
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp12
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm82
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp20
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp280
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp66
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp12
8 files changed, 394 insertions, 112 deletions
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index 18739cb4e1..d010ff807d 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -2000,6 +2000,9 @@ void tst_QByteArray::toUpperLower_data()
QTest::addColumn<QByteArray>("lower");
QTest::newRow("empty") << QByteArray() << QByteArray() << QByteArray();
+ QTest::newRow("literal") << QByteArrayLiteral("Hello World")
+ << QByteArrayLiteral("HELLO WORLD")
+ << QByteArrayLiteral("hello world");
QTest::newRow("ascii") << QByteArray("Hello World, this is a STRING")
<< QByteArray("HELLO WORLD, THIS IS A STRING")
<< QByteArray("hello world, this is a string");
@@ -2014,8 +2017,34 @@ void tst_QByteArray::toUpperLower()
QFETCH(QByteArray, input);
QFETCH(QByteArray, upper);
QFETCH(QByteArray, lower);
+ QCOMPARE(lower.toLower(), lower);
+ QCOMPARE(upper.toUpper(), upper);
QCOMPARE(input.toUpper(), upper);
QCOMPARE(input.toLower(), lower);
+
+ QByteArray copy = input;
+ QCOMPARE(qMove(copy).toUpper(), upper);
+ copy = input;
+ copy.detach();
+ QCOMPARE(qMove(copy).toUpper(), upper);
+
+ copy = input;
+ QCOMPARE(qMove(copy).toLower(), lower);
+ copy = input;
+ copy.detach();
+ QCOMPARE(qMove(copy).toLower(), lower);
+
+ copy = lower;
+ QCOMPARE(qMove(copy).toLower(), lower);
+ copy = lower;
+ copy.detach();
+ QCOMPARE(qMove(copy).toLower(), lower);
+
+ copy = upper;
+ QCOMPARE(qMove(copy).toUpper(), upper);
+ copy = upper;
+ copy.detach();
+ QCOMPARE(qMove(copy).toUpper(), upper);
}
void tst_QByteArray::macTypes()
diff --git a/tests/auto/corelib/tools/qdatetime/qdatetime.pro b/tests/auto/corelib/tools/qdatetime/qdatetime.pro
index 0a89fe7645..25d11443e4 100644
--- a/tests/auto/corelib/tools/qdatetime/qdatetime.pro
+++ b/tests/auto/corelib/tools/qdatetime/qdatetime.pro
@@ -11,3 +11,8 @@ win32-msvc|win32-msvc9x {
QMAKE_CXXFLAGS_RELEASE -= -O1
}
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
+mac {
+ OBJECTIVE_SOURCES += tst_qdatetime_mac.mm
+ LIBS += -framework Foundation
+}
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 51c3a19d63..8876bb3d34 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -145,6 +145,8 @@ private slots:
void invalid() const;
+ void macTypes();
+
private:
enum { LocalTimeIsUtc = 0, LocalTimeAheadOfUtc = 1, LocalTimeBehindUtc = -1} localTimeType;
bool europeanTimeZone;
@@ -2981,5 +2983,15 @@ void tst_QDateTime::invalid() const
QCOMPARE(tzDate.timeSpec(), Qt::TimeZone);
}
+void tst_QDateTime::macTypes()
+{
+#ifndef Q_OS_MAC
+ QSKIP("This is a Apple-only test");
+#else
+ extern void tst_QDateTime_macTypes(); // in qdatetime_mac.mm
+ tst_QDateTime_macTypes();
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QDateTime)
#include "tst_qdatetime.moc"
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
new file mode 100644
index 0000000000..d03ae3faeb
--- /dev/null
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Petroules Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QDateTime>
+#include <QtTest/QtTest>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <Foundation/Foundation.h>
+
+void tst_QDateTime_macTypes()
+{
+ // QDateTime <-> CFDate
+ {
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const CFDateRef cfDate = qtDateTime.toCFDate();
+ QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTime);
+ CFRelease(cfDate);
+ }
+ {
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const CFDateRef cfDate = qtDateTime.toCFDate();
+ QDateTime qtDateTimeCopy(qtDateTime);
+ qtDateTime.setTime_t(10000); // modify
+ QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTimeCopy);
+ }
+ // QDateTime <-> NSDate
+ {
+ NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const NSDate *nsDate = qtDateTime.toNSDate();
+ QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTime);
+ [autoreleasepool release];
+ }
+ {
+ NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ const NSDate *nsDate = qtDateTime.toNSDate();
+ QDateTime qtDateTimeCopy(qtDateTime);
+ qtDateTime.setTime_t(10000); // modify
+ QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTimeCopy);
+ [autoreleasepool release];
+ }
+}
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index d1152419c0..c1d6184072 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -51,6 +51,7 @@ private slots:
void operators();
void properties();
void metaTypes();
+ void propertyOrderIsNotImportant();
void bezierSpline_data();
void bezierSpline();
void tcbSpline_data();
@@ -552,6 +553,25 @@ void tst_QEasingCurve::metaTypes()
QVERIFY(qMetaTypeId<QEasingCurve>() == QMetaType::QEasingCurve);
}
+/*
+ Test to ensure that regardless of what order properties are set, they should produce the same
+ behavior.
+ */
+void tst_QEasingCurve::propertyOrderIsNotImportant()
+{
+
+ QEasingCurve c1;
+ c1.setPeriod(1);
+ c1.setType(QEasingCurve::OutSine);
+ QVERIFY(c1.valueForProgress(0.75) > 0.9);
+
+ QEasingCurve c2;
+ c2.setType(QEasingCurve::OutSine);
+ c2.setPeriod(1);
+
+ QCOMPARE(c1.valueForProgress(0.75), c2.valueForProgress(0.75));
+}
+
void tst_QEasingCurve::bezierSpline_data()
{
QTest::addColumn<QString>("definition");
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index db22f99cb8..1b6fe2aefe 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -237,6 +237,95 @@ void consistencyCheck(const QRegularExpressionMatchIterator &iterator)
}
+template<typename Result>
+static void prepareResultForNoMatchType(Result *r, const Result &orig)
+{
+ Q_UNUSED(r);
+ Q_UNUSED(orig);
+}
+
+static void prepareResultForNoMatchType(Match *m, const Match &orig)
+{
+ m->isValid = orig.isValid;
+}
+
+template<typename QREMatch, typename QREMatchFunc, typename Subject, typename Result>
+static void testMatchImpl(const QRegularExpression &regexp,
+ QREMatchFunc matchingMethod,
+ const Subject &subject,
+ int offset,
+ QRegularExpression::MatchType matchType,
+ QRegularExpression::MatchOptions matchOptions,
+ const Result &result)
+{
+ {
+ const QREMatch m = (regexp.*matchingMethod)(subject, offset, matchType, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == result);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), matchType);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Result realMatch;
+ prepareResultForNoMatchType(&realMatch, result);
+
+ const QREMatch m = (regexp.*matchingMethod)(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+}
+
+template<typename QREMatch, typename QREMatchFuncForString, typename QREMatchFuncForStringRef, typename Result>
+static void testMatch(const QRegularExpression &regexp,
+ QREMatchFuncForString matchingMethodForString,
+ QREMatchFuncForStringRef matchingMethodForStringRef,
+ const QString &subject,
+ int offset,
+ QRegularExpression::MatchType matchType,
+ 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);
+
+ // test with QStringRef as subject type
+ testMatchImpl<QREMatch>(regexp,
+ matchingMethodForStringRef,
+ QStringRef(&subject, 0, subject.length()),
+ offset,
+ matchType,
+ matchOptions,
+ result);
+
+ // offset <= 0 tested above; now also test stringrefs not spanning over
+ // the entire subject. Note that the offset can be negative, hence the above
+ // tests can't be merged into this one
+ for (int i = 1; i <= offset; ++i) {
+ testMatchImpl<QREMatch>(regexp,
+ matchingMethodForStringRef,
+ QStringRef(&subject, i, subject.length() - i),
+ offset - i,
+ matchType,
+ matchOptions,
+ result);
+ }
+}
+
+typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringRefPMF)(const QStringRef &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringRefPMF)(const QStringRef &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+
void tst_QRegularExpression::provideRegularExpressions()
{
QTest::addColumn<QString>("pattern");
@@ -526,6 +615,7 @@ void tst_QRegularExpression::normalMatch_data()
QTest::addColumn<Match>("match");
Match m;
+ int offset = 0;
m.clear();
m.isValid = true; m.hasMatch = true;
@@ -577,20 +667,28 @@ void tst_QRegularExpression::normalMatch_data()
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;
+ offset = 2;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("match06-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("(\\w*)(\\d+)(\\w*)")
+ << QStringLiteral("abc123def").mid(offset - i)
+ << i
+ << 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;
+ offset = 9;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("match07-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("\\w*")
+ << QStringLiteral("abc123def").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true; m.hasMatch = true;
@@ -648,19 +746,27 @@ void tst_QRegularExpression::normalMatch_data()
m.clear();
m.isValid = true;
- QTest::newRow("nomatch02") << QRegularExpression("(\\w+) (\\w+)")
- << "a string"
- << 1
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 1;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("nomatch02-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("(\\w+) (\\w+)")
+ << QStringLiteral("a string").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true;
- QTest::newRow("nomatch03") << QRegularExpression("\\w+")
- << "abc123def"
- << 9
- << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
- << m;
+ offset = 9;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("nomatch03-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("\\w+")
+ << QStringLiteral("abc123def").mid(offset - i)
+ << i
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
// ***
@@ -728,32 +834,14 @@ void tst_QRegularExpression::normalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- if (forceOptimize)
- regexp.optimize();
-
- {
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
- {
- // ignore the expected results provided by the match object --
- // we'll never get any result when testing the NoMatch type.
- // Just check the validity of the match here.
- Match realMatch;
- realMatch.clear();
- realMatch.isValid = match.isValid;
-
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == realMatch);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
+ testMatch<QRegularExpressionMatch>(regexp,
+ static_cast<QREMatchStringPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringRefPMF>(&QRegularExpression::match),
+ subject,
+ offset,
+ QRegularExpression::NormalMatch,
+ matchOptions,
+ match);
}
void tst_QRegularExpression::partialMatch_data()
@@ -766,6 +854,7 @@ void tst_QRegularExpression::partialMatch_data()
QTest::addColumn<Match>("match");
Match m;
+ int offset = 0;
m.clear();
m.isValid = true; m.hasPartialMatch = true;
@@ -840,12 +929,16 @@ void tst_QRegularExpression::partialMatch_data()
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;
+ offset = 1;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("softmatch08-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("abc\\w+X|defY")
+ << QStringLiteral("abcdef").mid(offset - i)
+ << i
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
// ***
@@ -922,12 +1015,16 @@ void tst_QRegularExpression::partialMatch_data()
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;
+ offset = 1;
+ for (int i = 0; i <= offset; ++i) {
+ QTest::newRow(QStringLiteral("hardmatch08-offset%1").arg(i).toUtf8().constData())
+ << QRegularExpression("abc\\w+X|defY")
+ << QStringLiteral("abcdef").mid(offset - i)
+ << i
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+ }
m.clear();
m.isValid = true; m.hasPartialMatch = true;
@@ -1009,32 +1106,14 @@ void tst_QRegularExpression::partialMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- if (forceOptimize)
- regexp.optimize();
-
- {
- QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), matchType);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
- {
- // ignore the expected results provided by the match object --
- // we'll never get any result when testing the NoMatch type.
- // Just check the validity of the match here.
- Match realMatch;
- realMatch.clear();
- realMatch.isValid = match.isValid;
-
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == realMatch);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
- }
+ testMatch<QRegularExpressionMatch>(regexp,
+ static_cast<QREMatchStringPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringRefPMF>(&QRegularExpression::match),
+ subject,
+ offset,
+ matchType,
+ matchOptions,
+ match);
}
void tst_QRegularExpression::globalMatch_data()
@@ -1304,31 +1383,14 @@ void tst_QRegularExpression::globalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(QList<Match>, matchList);
- if (forceOptimize)
- regexp.optimize();
-
- {
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == matchList);
- QCOMPARE(iterator.regularExpression(), regexp);
- QCOMPARE(iterator.matchType(), matchType);
- QCOMPARE(iterator.matchOptions(), matchOptions);
- }
- {
- // ignore the expected results provided by the match object --
- // we'll never get any result when testing the NoMatch type.
- // Just check the validity of the match here.
- QList<Match> realMatchList;
-
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == realMatchList);
- QCOMPARE(iterator.regularExpression(), regexp);
- QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
- QCOMPARE(iterator.matchOptions(), matchOptions);
- }
-
+ testMatch<QRegularExpressionMatchIterator>(regexp,
+ static_cast<QREGlobalMatchStringPMF>(&QRegularExpression::globalMatch),
+ static_cast<QREGlobalMatchStringRefPMF>(&QRegularExpression::globalMatch),
+ subject,
+ offset,
+ matchType,
+ matchOptions,
+ matchList);
}
void tst_QRegularExpression::serialize_data()
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index ea40c64c89..e001440045 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -155,6 +155,7 @@ private slots:
void lastIndexOfInvalidRegex();
void indexOf_data();
void indexOf();
+ void indexOfInvalidRegex();
void indexOf2_data();
void indexOf2();
void indexOf3_data();
@@ -1182,6 +1183,18 @@ void tst_QString::indexOf()
QRegularExpression re(QRegularExpression::escape(needle), options);
QCOMPARE( haystack.indexOf(re, startpos), resultpos );
+ QCOMPARE(haystack.indexOf(re, startpos, Q_NULLPTR), resultpos);
+
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QCOMPARE(haystack.indexOf(re, startpos, &match), resultpos);
+ QCOMPARE(match.hasMatch(), resultpos != -1);
+ if (resultpos > -1 && needleIsLatin) {
+ if (bcs)
+ QVERIFY(match.captured() == needle);
+ else
+ QVERIFY(match.captured().toLower() == needle.toLower());
+ }
}
if (cs == Qt::CaseSensitive) {
@@ -1290,6 +1303,20 @@ void tst_QString::indexOf2()
}
}
+void tst_QString::indexOfInvalidRegex()
+{
+ QTest::ignoreMessage(QtWarningMsg, "QString::indexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").indexOf(QRegularExpression("invalid regex\\")), -1);
+ QTest::ignoreMessage(QtWarningMsg, "QString::indexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").indexOf(QRegularExpression("invalid regex\\"), -1, Q_NULLPTR), -1);
+
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QTest::ignoreMessage(QtWarningMsg, "QString::indexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").indexOf(QRegularExpression("invalid regex\\"), -1, &match), -1);
+ QVERIFY(!match.hasMatch());
+}
+
void tst_QString::lastIndexOf_data()
{
QTest::addColumn<QString>("haystack" );
@@ -1379,6 +1406,17 @@ void tst_QString::lastIndexOf()
QRegularExpression re(QRegularExpression::escape(needle), options);
QCOMPARE(haystack.lastIndexOf(re, from), expected);
+ QCOMPARE(haystack.lastIndexOf(re, from, Q_NULLPTR), expected);
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QCOMPARE(haystack.lastIndexOf(re, from, &match), expected);
+ QCOMPARE(match.hasMatch(), expected > -1);
+ if (expected > -1) {
+ if (caseSensitive)
+ QCOMPARE(match.captured(), needle);
+ else
+ QCOMPARE(match.captured().toLower(), needle.toLower());
+ }
}
}
@@ -1403,7 +1441,15 @@ void tst_QString::lastIndexOf()
void tst_QString::lastIndexOfInvalidRegex()
{
QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object");
- QCOMPARE(QString("").lastIndexOf(QRegularExpression("invalid regex\\"), 0), -1);
+ QCOMPARE(QString("invalid regex\\").lastIndexOf(QRegularExpression("invalid regex\\"), 0), -1);
+ QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").lastIndexOf(QRegularExpression("invalid regex\\"), -1, Q_NULLPTR), -1);
+
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+ QTest::ignoreMessage(QtWarningMsg, "QString::lastIndexOf: invalid QRegularExpression object");
+ QCOMPARE(QString("invalid regex\\").lastIndexOf(QRegularExpression("invalid regex\\"), -1, &match), -1);
+ QVERIFY(!match.hasMatch());
}
void tst_QString::count()
@@ -1838,6 +1884,7 @@ void tst_QString::toUpper()
{
QCOMPARE( QString().toUpper(), QString() );
QCOMPARE( QString("").toUpper(), QString("") );
+ QCOMPARE( QStringLiteral("text").toUpper(), QString("TEXT") );
QCOMPARE( QString("text").toUpper(), QString("TEXT") );
QCOMPARE( QString("Text").toUpper(), QString("TEXT") );
QCOMPARE( QString("tExt").toUpper(), QString("TEXT") );
@@ -1898,6 +1945,7 @@ void tst_QString::toLower()
QCOMPARE( QString().toLower(), QString() );
QCOMPARE( QString("").toLower(), QString("") );
QCOMPARE( QString("text").toLower(), QString("text") );
+ QCOMPARE( QStringLiteral("Text").toLower(), QString("text") );
QCOMPARE( QString("Text").toLower(), QString("text") );
QCOMPARE( QString("tExt").toLower(), QString("text") );
QCOMPARE( QString("teXt").toLower(), QString("text") );
@@ -2019,6 +2067,13 @@ void tst_QString::trimmed()
QCOMPARE(a,(QString)" ");
a=" a ";
QCOMPARE(a.trimmed(),(QString)"a");
+
+ a="Text";
+ QCOMPARE(qMove(a).trimmed(),(QString)"Text");
+ a=" ";
+ QCOMPARE(qMove(a).trimmed(),(QString)"");
+ a=" a ";
+ QCOMPARE(qMove(a).trimmed(),(QString)"a");
}
void tst_QString::simplified_data()
@@ -2063,9 +2118,12 @@ void tst_QString::simplified()
QVERIFY2(result.isEmpty() && !result.isNull(), qPrintable("'" + full + "' did not yield empty: " + result));
} else {
QCOMPARE(result, simple);
- if (full == simple)
- QVERIFY(result.isSharedWith(full));
}
+
+ // force a detach
+ if (!full.isEmpty())
+ full[0] = full[0];
+ QCOMPARE(qMove(full).simplified(), simple);
}
void tst_QString::insert()
@@ -4454,6 +4512,8 @@ void tst_QString::section()
QCOMPARE( wholeString.section( QRegExp(sep), start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegularExpression(sep), start, end, QString::SectionFlag(flags) ), sectionString );
} else {
+ if (sep.size() == 1)
+ QCOMPARE( wholeString.section( sep[0], start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( sep, start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegExp(QRegExp::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString );
QCOMPARE( wholeString.section( QRegularExpression(QRegularExpression::escape(sep)), start, end, QString::SectionFlag(flags) ), sectionString );
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index 9a79d48472..c9e8a5f657 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -575,6 +575,18 @@ void tst_QVector::append() const
QCOMPARE(v.last(), SimpleValue<T>::at(0));
}
#endif
+ {
+ QVector<int> v;
+ v << 1 << 2 << 3;
+ QVector<int> x;
+ x << 4 << 5 << 6;
+ v.append(x);
+
+ QVector<int> combined;
+ combined << 1 << 2 << 3 << 4 << 5 << 6;
+
+ QCOMPARE(v, combined);
+ }
}
void tst_QVector::appendInt() const