diff options
Diffstat (limited to 'tests/auto')
37 files changed, 2018 insertions, 169 deletions
diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp index 534dec8160..05d1569988 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp @@ -123,6 +123,7 @@ private slots: void deletedInUpdateCurrentTime(); void totalDuration(); void zeroLoopCount(); + void recursiveAnimations(); }; void tst_QPropertyAnimation::initTestCase() @@ -1237,5 +1238,49 @@ void tst_QPropertyAnimation::zeroLoopCount() QCOMPARE(finishedSpy.count(), 0); } + +class RecursiveObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) +public: + RecursiveObject() : m_x(0), m_y(0) { + animation.setTargetObject(this); + animation.setPropertyName("y"); + animation.setDuration(30); + } + qreal x() const { return m_x; } + void setX(qreal x) { + m_x = x; + animation.setEndValue(x); + animation.start(); + } + qreal y() const { return m_y; } + void setY(qreal y) { m_y = y; } + + qreal m_x; + qreal m_y; + QPropertyAnimation animation; +}; + + +void tst_QPropertyAnimation::recursiveAnimations() +{ + RecursiveObject o; + QPropertyAnimation anim; + anim.setTargetObject(&o); + anim.setPropertyName("x"); + anim.setDuration(30); + + anim.setEndValue(4000); + anim.start(); + QTest::qWait(anim.duration() + o.animation.duration()); + QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); + QTRY_COMPARE(o.animation.state(), QAbstractAnimation::Stopped); + QCOMPARE(o.y(), qreal(4000)); +} + + QTEST_MAIN(tst_QPropertyAnimation) #include "tst_qpropertyanimation.moc" diff --git a/tests/auto/corelib/io/qsettings/qsettings.pro b/tests/auto/corelib/io/qsettings/qsettings.pro index 9de476fe13..1772f4b65f 100644 --- a/tests/auto/corelib/io/qsettings/qsettings.pro +++ b/tests/auto/corelib/io/qsettings/qsettings.pro @@ -5,5 +5,3 @@ SOURCES = tst_qsettings.cpp RESOURCES += qsettings.qrc win32-msvc*:LIBS += advapi32.lib - -win32: CONFIG += insignificant_test # QTBUG-24145 diff --git a/tests/auto/corelib/json/test.bjson b/tests/auto/corelib/json/test.bjson Binary files differindex aa412eec67..9a0515f3ef 100644 --- a/tests/auto/corelib/json/test.bjson +++ b/tests/auto/corelib/json/test.bjson diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index f5b4f17732..f35831c900 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -115,6 +115,8 @@ private Q_SLOTS: void testCompaction(); void testDebugStream(); void testCompactionError(); + + void parseUnicodeEscapes(); private: QString testDataDir; }; @@ -1758,5 +1760,19 @@ void TestQtJson::testCompactionError() } } +void TestQtJson::parseUnicodeEscapes() +{ + const QByteArray json = "[ \"A\\u00e4\\u00C4\" ]"; + + QJsonDocument doc = QJsonDocument::fromJson(json); + QJsonArray array = doc.array(); + + QString result = QLatin1String("A"); + result += QChar(0xe4); + result += QChar(0xc4); + + QCOMPARE(array.first().toString(), result); +} + QTEST_MAIN(TestQtJson) #include "tst_qtjson.moc" diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 63adcadb86..9076f37c7c 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -207,6 +207,7 @@ void tst_QMimeDatabase::mimeTypeForFileName_data() QTest::newRow("directory") << "/" << "inode/directory"; QTest::newRow("doesn't exist, no extension") << "IDontExist" << "application/octet-stream"; QTest::newRow("doesn't exist but has known extension") << "IDontExist.txt" << "text/plain"; + QTest::newRow("empty") << "" << "application/octet-stream"; } static inline QByteArray msgMimeTypeForFileNameFailed(const QList<QMimeType> &actual, 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/tools.pro b/tests/auto/corelib/tools/tools.pro index 89bb3bc416..d8961559e5 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -25,6 +25,7 @@ SUBDIRS=\ qqueue \ qrect \ qregexp \ + qregularexpression \ qringbuffer \ qscopedpointer \ qscopedvaluerollback \ diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp index 97c749e5ba..61efb6e3f3 100644 --- a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp @@ -151,14 +151,9 @@ protected: Result ambigResult; }; -QT_BEGIN_NAMESPACE -template<> struct QMetaTypeId<tst_QShortcut::Widget> : public QMetaTypeId<int> -{ static inline int qt_metatype_id() { return QMetaType::Int; } }; -template<> struct QMetaTypeId<tst_QShortcut::Result> : public QMetaTypeId<int> -{ static inline int qt_metatype_id() { return QMetaType::Int; } }; -template<> struct QMetaTypeId<tst_QShortcut::Action> : public QMetaTypeId<int> -{ static inline int qt_metatype_id() { return QMetaType::Int; } }; -QT_END_NAMESPACE +Q_DECLARE_METATYPE(tst_QShortcut::Widget); +Q_DECLARE_METATYPE(tst_QShortcut::Result); +Q_DECLARE_METATYPE(tst_QShortcut::Action); class TestEdit : public QTextEdit { @@ -221,9 +216,7 @@ void tst_QShortcut::initTestCase() mainW->setFixedSize( 100, 100 ); mainW->setCentralWidget( edit ); mainW->show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(mainW); -#endif + QTest::qWaitForWindowShown(mainW); mainW->activateWindow(); QTest::qWait(100); connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)), @@ -251,8 +244,8 @@ Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) void tst_QShortcut::defElements() { - QTest::addColumn<int>("action"); - QTest::addColumn<int>("testWidget"); + QTest::addColumn<tst_QShortcut::Action>("action"); + QTest::addColumn<tst_QShortcut::Widget>("testWidget"); QTest::addColumn<QString>("txt"); QTest::addColumn<int>("k1"); QTest::addColumn<int>("c1"); @@ -262,7 +255,7 @@ void tst_QShortcut::defElements() QTest::addColumn<int>("c3"); QTest::addColumn<int>("k4"); QTest::addColumn<int>("c4"); - QTest::addColumn<int>("result"); + QTest::addColumn<tst_QShortcut::Result>("result"); } void tst_QShortcut::number() @@ -287,7 +280,7 @@ void tst_QShortcut::number_data() defElements(); // Clear all - QTest::newRow("N00 - clear") << ClearAll <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0; + QTest::newRow("N00 - clear") << ClearAll << NoWidget <<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<NoResult; //=========================================== // [Shift + key] on non-shift shortcuts testing @@ -307,7 +300,7 @@ void tst_QShortcut::number_data() //commented out because the behaviour changed, those tests should be updated //QTest::newRow("N001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("N001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N001 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N001 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_M on Shift + Qt::Key_M @@ -321,7 +314,7 @@ void tst_QShortcut::number_data() QTest::newRow("N002 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("N002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N002 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Qt::Key_F1 @@ -331,7 +324,7 @@ void tst_QShortcut::number_data() //commented out because the behaviour changed, those tests should be updated //QTest::newRow("N003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N003 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N003 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Shift + Qt::Key_F1 Qt::Key_F1 on Shift + Qt::Key_F1 @@ -340,7 +333,7 @@ void tst_QShortcut::number_data() QTest::newRow("N004 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N004:Shift+F1 - [Shift+F1]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N004 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N004 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Qt::Key_Tab @@ -355,7 +348,7 @@ void tst_QShortcut::number_data() // (Shift+)BackTab != Tab, but Shift+BackTab == Shift+Tab QTest::newRow("N005a:Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N005a:Shift+Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N005a - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Shift + Qt::Key_Tab @@ -368,7 +361,7 @@ void tst_QShortcut::number_data() QTest::newRow("N005b:Shift+Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N005b:BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N005b - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N005b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Qt::Key_Backtab @@ -384,7 +377,7 @@ void tst_QShortcut::number_data() QTest::newRow("N006a:BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //commented out because the behaviour changed, those tests should be updated //QTest::newRow("N006a:Shift+BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N006a - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N006a - clear") << ClearAll << NoWidget<< QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Shift + Qt::Key_Backtab @@ -397,7 +390,7 @@ void tst_QShortcut::number_data() QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N006b:BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL - QTest::newRow("N006b - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N006b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all //=========================================== // [Shift + key] and [key] on shortcuts with @@ -412,7 +405,7 @@ void tst_QShortcut::number_data() QTest::newRow("N007 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N007 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N007 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_M @@ -434,7 +427,7 @@ void tst_QShortcut::number_data() */ QTest::newRow("N05 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("N:Qt::Key_M on slot") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; - QTest::newRow("N05 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N05 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Specialkeys Qt::Key_aring @@ -450,7 +443,7 @@ void tst_QShortcut::number_data() QTest::newRow("N:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K") << TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N09 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N09 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Multiple Sequences Qt::Key_M @@ -464,7 +457,7 @@ void tst_QShortcut::number_data() QTest::newRow("N:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("N:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N13 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("N13 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all } // ------------------------------------------------------------------ @@ -474,7 +467,7 @@ void tst_QShortcut::text_data() { defElements(); // Clear all - QTest::newRow("T00 - clear") << ClearAll <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0; + QTest::newRow("T00 - clear") << ClearAll << NoWidget <<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<< NoResult; //=========================================== // [Shift + key] on non-shift shortcuts testing @@ -494,7 +487,7 @@ void tst_QShortcut::text_data() //commented out because the behaviour changed, those tests should be updated //QTest::newRow("T001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("T001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T001 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T001 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_M on Shift + Qt::Key_M @@ -510,7 +503,7 @@ void tst_QShortcut::text_data() QTest::newRow("T002 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("T002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T002 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Plus @@ -522,7 +515,7 @@ void tst_QShortcut::text_data() //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T002b:Ctrl++ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T002b:+ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002b - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T002b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Qt::Key_F1 @@ -532,7 +525,7 @@ void tst_QShortcut::text_data() //commented out because the behaviour changed, those tests should be updated //QTest::newRow("T003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T003 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T003 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Shift + Qt::Key_F1 @@ -541,7 +534,7 @@ void tst_QShortcut::text_data() QTest::newRow("T004 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T004:Shift+F1 - [Shift+F1]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T004 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T004 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all //=========================================== // [Shift + key] and [key] on shortcuts with @@ -556,7 +549,7 @@ void tst_QShortcut::text_data() QTest::newRow("T007 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T007 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T007 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_M @@ -579,7 +572,7 @@ void tst_QShortcut::text_data() */ QTest::newRow("T05 - slot2") << SetupAccel << TriggerSlot2 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T:Qt::Key_M on TriggerSlot2") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; - QTest::newRow("T06 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T06 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Specialkeys Qt::Key_aring @@ -595,7 +588,7 @@ void tst_QShortcut::text_data() QTest::newRow("T:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K") << TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T09 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T09 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Multiple Sequences Qt::Key_M @@ -608,7 +601,7 @@ void tst_QShortcut::text_data() QTest::newRow("T:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T13 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all + QTest::newRow("T13 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all } // ------------------------------------------------------------------ @@ -1239,8 +1232,8 @@ void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2 void tst_QShortcut::testElement() { currentResult = NoResult; - QFETCH(int, action); - QFETCH(int, testWidget); + QFETCH(tst_QShortcut::Action, action); + QFETCH(tst_QShortcut::Widget, testWidget); QFETCH(QString, txt); QFETCH(int, k1); QFETCH(int, c1); @@ -1250,15 +1243,15 @@ void tst_QShortcut::testElement() QFETCH(int, c3); QFETCH(int, k4); QFETCH(int, c4); - QFETCH(int, result); + QFETCH(tst_QShortcut::Result, result); if (action == ClearAll) { clearAllShortcuts(); } else if (action == SetupAccel) { setupShortcut(testWidget, txt, k1, k2, k3, k4); } else { - sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); - QCOMPARE(int(currentResult), result); + sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); + QCOMPARE(currentResult, result); } } diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index d8f9bf32ad..8685546a5f 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -3385,6 +3385,7 @@ void tst_QNetworkReply::ioGetFromHttpWithCache_data() << QNetworkCacheMetaData::RawHeader("Cache-control", "max-age=0"); // isn't used in cache loading content.first.setRawHeaders(rawHeaders); content.first.setLastModified(past); + content.first.setExpirationDate(past); QTest::newRow("expired,200,prefer-network") << reply200 << "Reloaded" << content << int(QNetworkRequest::PreferNetwork) << QStringList() << false << true; @@ -6334,29 +6335,52 @@ void tst_QNetworkReply::qtbug13431replyThrottling() void tst_QNetworkReply::httpWithNoCredentialUsage() { - QNetworkRequest request(QUrl("http://httptest:httptest@" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi")); - // Do not use credentials - request.setAttribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Manual); QNetworkAccessManager manager; - QNetworkReplyPtr reply = manager.get(request); - qRegisterMetaType<QNetworkReply*>("QNetworkReply*"); - qRegisterMetaType<QAuthenticator*>("QAuthenticator*"); QSignalSpy authSpy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); QSignalSpy finishedSpy(&manager, SIGNAL(finished(QNetworkReply*))); - qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); - QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + // Get with credentials, to preload authentication cache + { + QNetworkRequest request(QUrl("http://httptest:httptest@" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi")); + QNetworkReplyPtr reply = manager.get(request); + QVERIFY(waitForFinish(reply) == Success); + // credentials in URL, so don't expect authentication signal + QCOMPARE(authSpy.count(), 0); + QCOMPARE(finishedSpy.count(), 1); + finishedSpy.clear(); + } - // We check if authenticationRequired was emitted, however we do not anything in it so it should be 401 - QCOMPARE(authSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); - QCOMPARE(errorSpy.count(), 1); + // Get with cached credentials (normal usage) + { + QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi")); + QNetworkReplyPtr reply = manager.get(request); + QVERIFY(waitForFinish(reply) == Success); + // credentials in cache, so don't expect authentication signal + QCOMPARE(authSpy.count(), 0); + QCOMPARE(finishedSpy.count(), 1); + finishedSpy.clear(); + } - QCOMPARE(reply->error(), QNetworkReply::AuthenticationRequiredError); + // Do not use cached credentials (webkit cross origin usage) + { + QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi")); + request.setAttribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Manual); + QNetworkReplyPtr reply = manager.get(request); + + QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // We check if authenticationRequired was emitted, however we do not anything in it so it should be 401 + QCOMPARE(authSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(errorSpy.count(), 1); + + QCOMPARE(reply->error(), QNetworkReply::AuthenticationRequiredError); + } } void tst_QNetworkReply::qtbug15311doubleContentLength() diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp index 5da9ff0476..93299c26c6 100644 --- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp @@ -109,6 +109,7 @@ private slots: void subjectAndIssuerAttributes(); void verify(); void extensions(); + void threadSafeConstMethods(); // helper for verbose test failure messages QString toString(const QList<QSslError>&); @@ -1059,6 +1060,77 @@ void tst_QSslCertificate::extensions() } +class TestThread : public QThread +{ +public: + void run() + { + effectiveDate = cert.effectiveDate(); + expiryDate = cert.expiryDate(); + extensions = cert.extensions(); + isBlacklisted = cert.isBlacklisted(); + issuerInfo = cert.issuerInfo(QSslCertificate::CommonName); + issuerInfoAttributes = cert.issuerInfoAttributes(); + publicKey = cert.publicKey(); + serialNumber = cert.serialNumber(); + subjectInfo = cert.subjectInfo(QSslCertificate::CommonName); + subjectInfoAttributes = cert.subjectInfoAttributes(); + toDer = cert.toDer(); + toPem = cert.toPem(); + toText = cert.toText(); + version = cert.version(); + } + QSslCertificate cert; + QDateTime effectiveDate; + QDateTime expiryDate; + QList<QSslCertificateExtension> extensions; + bool isBlacklisted; + QStringList issuerInfo; + QList<QByteArray> issuerInfoAttributes; + QSslKey publicKey; + QByteArray serialNumber; + QStringList subjectInfo; + QList<QByteArray> subjectInfoAttributes; + QByteArray toDer; + QByteArray toPem; + QByteArray toText; + QByteArray version; +}; + +void tst_QSslCertificate::threadSafeConstMethods() +{ + if (!QSslSocket::supportsSsl()) + return; + + QByteArray encoded = readFile(testDataDir + "/certificates/cert.pem"); + QSslCertificate certificate(encoded); + QVERIFY(!certificate.isNull()); + + TestThread t1; + t1.cert = certificate; //shallow copy + TestThread t2; + t2.cert = certificate; //shallow copy + t1.start(); + t2.start(); + QVERIFY(t1.wait(5000)); + QVERIFY(t2.wait(5000)); + QVERIFY(t1.cert == t2.cert); + QVERIFY(t1.effectiveDate == t2.effectiveDate); + QVERIFY(t1.expiryDate == t2.expiryDate); + //QVERIFY(t1.extensions == t2.extensions); // no equality operator, so not tested + QVERIFY(t1.isBlacklisted == t2.isBlacklisted); + QVERIFY(t1.issuerInfo == t2.issuerInfo); + QVERIFY(t1.issuerInfoAttributes == t2.issuerInfoAttributes); + QVERIFY(t1.publicKey == t2.publicKey); + QVERIFY(t1.serialNumber == t2.serialNumber); + QVERIFY(t1.subjectInfo == t2.subjectInfo); + QVERIFY(t1.subjectInfoAttributes == t2.subjectInfoAttributes); + QVERIFY(t1.toDer == t2.toDer); + QVERIFY(t1.toPem == t2.toPem); + QVERIFY(t1.toText == t2.toText); + QVERIFY(t1.version == t2.version); + +} #endif // QT_NO_SSL diff --git a/tests/auto/other/headersclean/headersclean.pri b/tests/auto/other/headersclean/headersclean.pri new file mode 100644 index 0000000000..163ef6d409 --- /dev/null +++ b/tests/auto/other/headersclean/headersclean.pri @@ -0,0 +1,38 @@ +# The headersclean test attempts to ensure all public Qt headers +# abide by various rules. +# +# To reuse this test outside of the qtbase module, +# include this .pri and create a qt_headersclean_headers.h which includes +# the headers you'd like to test. + +*-g++*: QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror + +# The flags here come from http://wiki.qt-project.org/Coding_Conventions#Conventions_for_public_header_files +# -Wold-style-cast cannot be used, /usr/include/bits/byteswap.h defines the macro bswap_16 using C style casts :( +# -Wfloat-equal cannot be used, qrect.h and qvector2d.h do exact comparisons in isNull and operator==. Would need #pragmas. +*-g++*: QMAKE_CXXFLAGS += -Woverloaded-virtual -Wshadow -Wundef + +# Other nice flags +*-g++*: QMAKE_CXXFLAGS += -Wnon-virtual-dtor -ansi -Wcast-align -Wchar-subscripts -Wpointer-arith -Wformat-security + +# Enable pedantic mode, but accept variadic macros and 'long long' usage. +*-g++*: QMAKE_CXXFLAGS += -Wno-long-long -Wno-variadic-macros -pedantic-errors + +# There are outstanding alignment issues on ARM in some container classes. +contains(QT_ARCH,arm):*-g++*:QMAKE_CXXFLAGS -= -Wcast-align + +QMAKE_CXXFLAGS += -DQT_NO_CAST_TO_ASCII \ + -DQT_NO_CAST_FROM_ASCII \ + -DQT_STRICT_ITERATORS \ + -DQT_NO_URL_CAST_FROM_STRING \ + -DQT_NO_CAST_FROM_BYTEARRAY \ + -DQT_NO_KEYWORDS \ + -DQT_USE_FAST_CONCATENATION \ + -DQT_USE_FAST_OPERATOR_PLUS + +TARGET = tst_headersclean +SOURCES += $$PWD/tst_headersclean.cpp +HEADERS += $$PWD/tst_headersclean.h + +# qt_headersclean_headers.h should be alongside the .pro file +INCLUDEPATH += $$_PRO_FILE_PWD_ diff --git a/tests/auto/other/headersclean/headersclean.pro b/tests/auto/other/headersclean/headersclean.pro index 5444bebfb9..9bfadca08c 100644 --- a/tests/auto/other/headersclean/headersclean.pro +++ b/tests/auto/other/headersclean/headersclean.pro @@ -1,28 +1,2 @@ -CONFIG += testcase -TARGET = tst_headersclean -SOURCES += tst_headersclean.cpp - -# No need to link to all modules, only those actually used QT = core testlib gui widgets - -*-g++*: QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror - -# The flags here come from http://wiki.qt-project.org/Coding_Conventions#Conventions_for_public_header_files -# -Wold-style-cast cannot be used, /usr/include/bits/byteswap.h defines the macro bswap_16 using C style casts :( -# -Wfloat-equal cannot be used, qrect.h and qvector2d.h do exact comparisons in isNull and operator==. Would need #pragmas. -*-g++*: QMAKE_CXXFLAGS += -Woverloaded-virtual -Wshadow -Wundef - -# Other nice flags -*-g++*: QMAKE_CXXFLAGS += -Wnon-virtual-dtor -ansi -Wcast-align -Wchar-subscripts -Wpointer-arith -Wformat-security - -# Enable pedantic mode, but accept variadic macros and 'long long' usage. -*-g++*: QMAKE_CXXFLAGS += -Wno-long-long -Wno-variadic-macros -pedantic-errors - -QMAKE_CXXFLAGS += -DQT_NO_CAST_TO_ASCII \ - -DQT_NO_CAST_FROM_ASCII \ - -DQT_STRICT_ITERATORS \ - -DQT_NO_URL_CAST_FROM_STRING \ - -DQT_NO_CAST_FROM_BYTEARRAY \ - -DQT_NO_KEYWORDS \ - -DQT_USE_FAST_CONCATENATION \ - -DQT_USE_FAST_OPERATOR_PLUS +include(headersclean.pri) diff --git a/tests/auto/other/headersclean/qt_headersclean_headers.h b/tests/auto/other/headersclean/qt_headersclean_headers.h new file mode 100644 index 0000000000..c9b4e3f399 --- /dev/null +++ b/tests/auto/other/headersclean/qt_headersclean_headers.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** 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$ +** +****************************************************************************/ + +#ifndef QT_HEADERSCLEAN_HEADERS +#define QT_HEADERSCLEAN_HEADERS + +/* + This file should include all the headers to be tested by the headersclean + test. It may be copied and customized for each module. +*/ + +#include <QtCore/QtCore> +#include <QtConcurrent/QtConcurrent> +#include <QtTest/QtTest> + +#include <QtNetwork/QtNetwork> +#include <QtXml/QtXml> +#include <QtSql/QtSql> +#include <QtGui/QtGui> +#include <QtWidgets/QtWidgets> +#include <QtPrintSupport/QtPrintSupport> +#include <QtPlatformSupport/QtPlatformSupport> + +#ifndef QT_NO_OPENGL +#include <QtOpenGL/QtOpenGL> +#endif + +#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) +#include <QtDBus/QtDBus> +#endif + +#endif diff --git a/tests/auto/other/headersclean/tst_headersclean.cpp b/tests/auto/other/headersclean/tst_headersclean.cpp index 81d0aa3a4a..d442ad39d3 100644 --- a/tests/auto/other/headersclean/tst_headersclean.cpp +++ b/tests/auto/other/headersclean/tst_headersclean.cpp @@ -39,38 +39,12 @@ ** ****************************************************************************/ -#define signals int -#define slots int -#define emit public:; -#define foreach public:; -#define forever public:; +#include "tst_headersclean.h" +#include <QTest> -#include <QtCore/QtCore> -#include <QtConcurrent/QtConcurrent> -#include <QtTest/QtTest> - -#include <QtNetwork/QtNetwork> -#include <QtXml/QtXml> -#include <QtSql/QtSql> -#include <QtGui/QtGui> -#include <QtWidgets/QtWidgets> -#include <QtPrintSupport/QtPrintSupport> -#include <QtPlatformSupport/QtPlatformSupport> - -#ifndef QT_NO_OPENGL -#include <QtOpenGL/QtOpenGL> -#endif - -#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) -#include <QtDBus/QtDBus> -#endif - -class tst_HeadersClean: public QObject +void tst_HeadersClean::initTestCase() { - Q_OBJECT -public: - tst_HeadersClean() {} -}; + QWARN("This is a compile test only"); +} QTEST_MAIN(tst_HeadersClean) -#include "tst_headersclean.moc" diff --git a/tests/auto/other/headersclean/tst_headersclean.h b/tests/auto/other/headersclean/tst_headersclean.h new file mode 100644 index 0000000000..7479e061dc --- /dev/null +++ b/tests/auto/other/headersclean/tst_headersclean.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** 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$ +** +****************************************************************************/ + +#ifndef TST_HEADERSCLEAN_H +#define TST_HEADERSCLEAN_H + +#define signals int +#define slots int +#define emit public:; +#define foreach public:; +#define forever public:; + +#include <qt_headersclean_headers.h> +#include <QObject> + +class tst_HeadersClean: public QObject +{ + Q_OBJECT +private Q_SLOTS: + void initTestCase(); +}; + +#endif diff --git a/tests/auto/other/other.pro b/tests/auto/other/other.pro index 9ec5ea8e34..6c708baa6b 100644 --- a/tests/auto/other/other.pro +++ b/tests/auto/other/other.pro @@ -30,8 +30,7 @@ testcocoon: SUBDIRS -= headersclean cross_compile: SUBDIRS -= \ atwrapper \ - compiler \ - headersclean \ + compiler wince*|!contains(QT_CONFIG, accessibility):SUBDIRS -= qaccessibility diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index b2a4b1cca2..4c370bebc7 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -777,6 +777,7 @@ void tst_QAccessibility::actionTest() { QPushButton *button = new QPushButton; button->show(); + QTest::qWaitForWindowShown(button); button->clearFocus(); QCOMPARE(button->hasFocus(), false); QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(button); diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index b22e876c3c..584fcb045a 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -222,6 +222,8 @@ private slots: void sqlite_real_data() { generic_data("QSQLITE"); } void sqlite_real(); + void aggregateFunctionTypes_data() { generic_data(); } + void aggregateFunctionTypes(); private: // returns all database connections void generic_data(const QString &engine=QString()); @@ -3339,5 +3341,121 @@ void tst_QSqlQuery::sqlite_real() QCOMPARE(q.value(0).toDouble(), 5.6); } +void tst_QSqlQuery::aggregateFunctionTypes() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + { + const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__)); + tst_Databases::safeDropTable( db, tableName ); + + QSqlQuery q(db); + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INTEGER)")); + + // First test without any entries + QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.record().field(0).type(), QVariant::Invalid); + + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1)")); + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2)")); + + QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 3); + QCOMPARE(q.record().field(0).type(), QVariant::Int); + + QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 1.5); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + + QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 2); + QCOMPARE(q.record().field(0).type(), QVariant::Int); + + QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 1); + QCOMPARE(q.record().field(0).type(), QVariant::Int); + + QVERIFY_SQL(q, exec("SELECT MAX(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 2); + QCOMPARE(q.record().field(0).type(), QVariant::Int); + } + { + const QString tableName(qTableName("numericFunctionsWithDoubleValues", __FILE__)); + tst_Databases::safeDropTable( db, tableName ); + + QSqlQuery q(db); + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id DOUBLE)")); + + // First test without any entries + QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.record().field(0).type(), QVariant::Invalid); + + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1.5)")); + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2.5)")); + + QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 4.0); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + + QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 2.0); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + + QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 2); + QCOMPARE(q.record().field(0).type(), QVariant::Int); + + QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 1.5); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + + QVERIFY_SQL(q, exec("SELECT MAX(id) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 2.5); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + + QVERIFY_SQL(q, exec("SELECT ROUND(id, 1) FROM " + tableName + " WHERE id=1.5")); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 1.5); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + + QVERIFY_SQL(q, exec("SELECT ROUND(id, 0) FROM " + tableName + " WHERE id=2.5")); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 3.0); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + } + { + const QString tableName(qTableName("stringFunctions", __FILE__)); + tst_Databases::safeDropTable( db, tableName ); + + QSqlQuery q(db); + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INTEGER, txt VARCHAR(50))")); + + QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.record().field(0).type(), QVariant::Invalid); + + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (1, 'lower')")); + QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (2, 'upper')")); + + QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName)); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toString(), QLatin1String("upper")); + QCOMPARE(q.record().field(0).type(), QVariant::String); + } +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" diff --git a/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index ddafeea427..ce0d8db1fd 100644 --- a/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -542,6 +542,13 @@ void tst_QSqlRelationalTableModel::setRecord() model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, submit()); + if (model.editStrategy() != QSqlTableModel::OnManualSubmit) { + QCOMPARE(model.data(model.index(1, 0)).toInt(), 7); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("tester")); + QCOMPARE(model.data(model.index(1, 2)).toString(), QString("herr")); + QVERIFY_SQL(model, select()); + } + QCOMPARE(model.data(model.index(3, 0)).toInt(), 7); QCOMPARE(model.data(model.index(3, 1)).toString(), QString("tester")); QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); @@ -599,6 +606,8 @@ void tst_QSqlRelationalTableModel::insertWithStrategies() QVERIFY_SQL(model, submitAll()); model.setEditStrategy(QSqlTableModel::OnManualSubmit); + // The changes were submitted, but there was no automatic select to resort + QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0,0)).toInt(), 1); QCOMPARE(model.data(model.index(0,1)).toString(), QString("harry")); @@ -1401,6 +1410,8 @@ void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() QVERIFY_SQL(model, insertRecord(-1, rec)); model.submitAll(); + if (model.editStrategy() != QSqlTableModel::OnManualSubmit) + QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0, 0)).toInt(), 3); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Washington")); diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index 270de8292b..448111cd9f 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -411,8 +411,11 @@ void tst_QSqlTableModel::setRecord() } else if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnRowChange && i == model.rowCount() -1) model.submit(); else { - // dataChanged() is not emitted when submitAll() is called - QCOMPARE(spy.count(), 1); + // dataChanged() emitted by selectRow() as well as setRecord() + if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnFieldChange) + QCOMPARE(spy.count(), 2); + else + QCOMPARE(spy.count(), 1); QCOMPARE(spy.at(0).count(), 2); QCOMPARE(qvariant_cast<QModelIndex>(spy.at(0).at(0)), model.index(i, 0)); QCOMPARE(qvariant_cast<QModelIndex>(spy.at(0).at(1)), model.index(i, rec.count() - 1)); @@ -471,8 +474,7 @@ void tst_QSqlTableModel::insertRow() rec.setValue(0, 42); rec.setValue(1, QString("francis")); - // FieldChange updates immediately and resorts - // Row/Manual submit does not resort + // Setting record does not cause resort QVERIFY(model.setRecord(2, rec)); QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); @@ -482,8 +484,23 @@ void tst_QSqlTableModel::insertRow() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond")); QCOMPARE(model.data(model.index(1, 2)).toInt(), 2); - // See comment above setRecord - if (submitpolicy == QSqlTableModel::OnFieldChange) { + QCOMPARE(model.data(model.index(2, 0)).toInt(), 42); + QCOMPARE(model.data(model.index(2, 1)).toString(), QString("francis")); + QCOMPARE(model.data(model.index(2, 2)).toInt(), 2); + QCOMPARE(model.data(model.index(3, 0)).toInt(), 3); + QCOMPARE(model.data(model.index(3, 1)).toString(), QString("vohi")); + QCOMPARE(model.data(model.index(3, 2)).toInt(), 3); + + QVERIFY(model.submitAll()); + + if (submitpolicy == QSqlTableModel::OnManualSubmit) { + // After the submit we should have the resorted view + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toInt(), 1); + QCOMPARE(model.data(model.index(1, 0)).toInt(), 2); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond")); + QCOMPARE(model.data(model.index(1, 2)).toInt(), 2); QCOMPARE(model.data(model.index(2, 0)).toInt(), 3); QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi")); QCOMPARE(model.data(model.index(2, 2)).toInt(), 3); @@ -491,6 +508,13 @@ void tst_QSqlTableModel::insertRow() QCOMPARE(model.data(model.index(3, 1)).toString(), QString("francis")); QCOMPARE(model.data(model.index(3, 2)).toInt(), 2); } else { + // Submit does not select, therefore not resorted + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toInt(), 1); + QCOMPARE(model.data(model.index(1, 0)).toInt(), 2); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond")); + QCOMPARE(model.data(model.index(1, 2)).toInt(), 2); QCOMPARE(model.data(model.index(2, 0)).toInt(), 42); QCOMPARE(model.data(model.index(2, 1)).toString(), QString("francis")); QCOMPARE(model.data(model.index(2, 2)).toInt(), 2); @@ -499,9 +523,8 @@ void tst_QSqlTableModel::insertRow() QCOMPARE(model.data(model.index(3, 2)).toInt(), 3); } - QVERIFY(model.submitAll()); - - // After the submit we should have the resorted view + QVERIFY(model.select()); + // After the select we should have the resorted view in all strategies QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(0, 2)).toInt(), 1); @@ -514,7 +537,6 @@ void tst_QSqlTableModel::insertRow() QCOMPARE(model.data(model.index(3, 0)).toInt(), 42); QCOMPARE(model.data(model.index(3, 1)).toString(), QString("francis")); QCOMPARE(model.data(model.index(3, 2)).toInt(), 2); - } void tst_QSqlTableModel::insertRecord() @@ -647,8 +669,7 @@ void tst_QSqlTableModel::removeRow() QVERIFY_SQL(model, select()); QCOMPARE(model.rowCount(), 3); - // headerDataChanged must be emitted by the model when the edit strategy is OnManualSubmit, - // when OnFieldChange or OnRowChange it's not needed because the model will re-select. + // headerDataChanged must be emitted by the model since the row won't vanish until select qRegisterMetaType<Qt::Orientation>("Qt::Orientation"); QSignalSpy headerDataChangedSpy(&model, SIGNAL(headerDataChanged(Qt::Orientation, int, int))); @@ -673,7 +694,10 @@ void tst_QSqlTableModel::removeRow() headerDataChangedSpy.clear(); QVERIFY(model.removeRow(1)); - QCOMPARE(headerDataChangedSpy.count(), 0); + QCOMPARE(headerDataChangedSpy.count(), 1); + QCOMPARE(model.rowCount(), 3); + + QVERIFY_SQL(model, select()); QCOMPARE(model.rowCount(), 2); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); @@ -706,6 +730,11 @@ void tst_QSqlTableModel::removeRows() QCOMPARE(beforeDeleteSpy.count(), 2); QVERIFY(beforeDeleteSpy.at(0).at(0).toInt() == 0); QVERIFY(beforeDeleteSpy.at(1).at(0).toInt() == 1); + // deleted rows shown as empty until select + QCOMPARE(model.rowCount(), 3); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("")); + QVERIFY(model.select()); + // deleted rows are gone QCOMPARE(model.rowCount(), 1); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("vohi")); model.clear(); @@ -730,10 +759,10 @@ void tst_QSqlTableModel::removeRows() QSignalSpy headerDataChangedSpy(&model, SIGNAL(headerDataChanged(Qt::Orientation, int, int))); QVERIFY(model.removeRows(0, 2, QModelIndex())); QCOMPARE(headerDataChangedSpy.count(), 2); - QCOMPARE(headerDataChangedSpy.at(0).at(1).toInt(), 0); - QCOMPARE(headerDataChangedSpy.at(0).at(2).toInt(), 0); - QCOMPARE(headerDataChangedSpy.at(1).at(1).toInt(), 1); - QCOMPARE(headerDataChangedSpy.at(1).at(2).toInt(), 1); + QCOMPARE(headerDataChangedSpy.at(0).at(1).toInt(), 1); + QCOMPARE(headerDataChangedSpy.at(0).at(2).toInt(), 1); + QCOMPARE(headerDataChangedSpy.at(1).at(1).toInt(), 0); + QCOMPARE(headerDataChangedSpy.at(1).at(2).toInt(), 0); QCOMPARE(model.rowCount(), 3); QVERIFY(beforeDeleteSpy.count() == 0); QVERIFY(model.submitAll()); @@ -778,6 +807,14 @@ void tst_QSqlTableModel::removeInsertedRow() model.submitAll(); + if (model.editStrategy() != QSqlTableModel::OnManualSubmit) { + QCOMPARE(model.rowCount(), 4); + QCOMPARE(model.data(model.index(1, 0)).toInt(), 55); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("null columns")); + QCOMPARE(model.data(model.index(1, 2)).isNull(), true); + QVERIFY(model.select()); + } + QCOMPARE(model.rowCount(), 4); QCOMPARE(model.data(model.index(3, 0)).toInt(), 55); QCOMPARE(model.data(model.index(3, 1)).toString(), QString("null columns")); @@ -785,8 +822,17 @@ void tst_QSqlTableModel::removeInsertedRow() QVERIFY(model.removeRow(3)); model.submitAll(); - QCOMPARE(model.rowCount(), 3); + if (model.editStrategy() != QSqlTableModel::OnManualSubmit) { + QCOMPARE(model.rowCount(), 4); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond")); + QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi")); + QCOMPARE(model.data(model.index(3, 1)).toString(), QString("")); + QVERIFY(model.select()); + } + + QCOMPARE(model.rowCount(), 3); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond")); QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi")); @@ -1129,6 +1175,11 @@ void tst_QSqlTableModel::insertRecordBeforeSelect() buffer.setValue("title", 0); QVERIFY_SQL(model, insertRecord(1, buffer)); + if (model.editStrategy() != QSqlTableModel::OnManualSubmit) { + QCOMPARE(model.rowCount(), 2); + QVERIFY_SQL(model, select()); + } + int rowCount = model.rowCount(); model.clear(); QCOMPARE(model.rowCount(), 0); diff --git a/tests/auto/tools/qmake/testdata/export_across_file_boundaries/oink.pri b/tests/auto/tools/qmake/testdata/export_across_file_boundaries/oink.pri index cbd2d0f7d0..ea58ef076e 100644 --- a/tests/auto/tools/qmake/testdata/export_across_file_boundaries/oink.pri +++ b/tests/auto/tools/qmake/testdata/export_across_file_boundaries/oink.pri @@ -1 +1,2 @@ +load(default_pre) setVar(BAR) diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index af76b1c3c1..ee7ec7ba57 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -4338,9 +4338,16 @@ void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins() QPointF newMouseScenePos = view.mapToScene(mouseViewPos); qreal slack = 1; - QEXPECT_FAIL("", "QTBUG-22455", Abort); - QVERIFY(qAbs(newMouseScenePos.x() - mouseScenePos.x()) < slack); - QVERIFY(qAbs(newMouseScenePos.y() - mouseScenePos.y()) < slack); + + const qreal dx = qAbs(newMouseScenePos.x() - mouseScenePos.x()); + const qreal dy = qAbs(newMouseScenePos.y() - mouseScenePos.y()); + const QByteArray message = QString::fromLatin1("QTBUG-22455, distance: dx=%1, dy=%2 slack=%3 (%4)."). + arg(dx).arg(dy).arg(slack).arg(qApp->style()->metaObject()->className()).toLocal8Bit(); + // This is highly unstable (observed to pass on Windows and some Linux configurations). +#ifdef Q_OS_MAC + QEXPECT_FAIL("", message.constData(), Abort); +#endif + QVERIFY2(dx < slack && dy < slack, message.constData()); #endif } diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index 0a2d0cd2f8..c6b2b49d98 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -1158,9 +1158,6 @@ void tst_QGraphicsWidget::initStyleOption() QCOMPARE(hasFocus, focus); bool isUnderMouse = option.state & QStyle::State_MouseOver; #ifndef Q_OS_WINCE -# if !defined(Q_OS_MAC) && !defined(Q_OS_WIN) - QEXPECT_FAIL("all", "QTBUG-22457", Abort); -# endif QCOMPARE(isUnderMouse, underMouse); #endif // if (layoutDirection != Qt::LeftToRight) diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index f139eac275..9bb08edcce 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -1830,10 +1830,11 @@ void tst_QListView::taskQTBUG_2233_scrollHiddenItems() QStringListModel model(&view); QStringList list; for (int i = 0; i < rowCount; ++i) - list << QString::fromAscii("Item %1").arg(i); + list << QString::number(i); model.setStringList(list); view.setModel(&model); + view.setUniformItemSizes(true); view.setViewMode(QListView::ListMode); for (int i = 0; i < rowCount / 2; ++i) view.setRowHidden(2 * i, true); diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index caf0f1f80d..dab9dd7690 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -5693,7 +5693,6 @@ private: void tst_QWidget::childEvents() { EventRecorder::EventList expected; - bool accessibilityEnabled = false; // Move away the cursor; otherwise it might result in an enter event if it's // inside the widget when the widget is shown. @@ -5735,8 +5734,6 @@ void tst_QWidget::childEvents() << qMakePair(&widget, QEvent::Resize) << qMakePair(&widget, QEvent::Show); - if (accessibilityEnabled) - expected << qMakePair(&widget, QEvent::AccessibilityPrepare); expected << qMakePair(&widget, QEvent::ShowToParent); QCOMPARE(spy.eventList(), expected); spy.clear(); @@ -5820,8 +5817,6 @@ void tst_QWidget::childEvents() << qMakePair(&widget, QEvent::Resize) << qMakePair(&widget, QEvent::Show); - if (accessibilityEnabled) - expected << qMakePair(&widget, QEvent::AccessibilityPrepare); expected << qMakePair(&widget, QEvent::ShowToParent); QCOMPARE(spy.eventList(), expected); spy.clear(); @@ -5908,8 +5903,6 @@ void tst_QWidget::childEvents() << qMakePair(&widget, QEvent::Resize) << qMakePair(&widget, QEvent::Show); - if (accessibilityEnabled) - expected << qMakePair(&widget, QEvent::AccessibilityPrepare); expected << qMakePair(&widget, QEvent::ShowToParent); QCOMPARE(spy.eventList(), expected); spy.clear(); diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 1201b0f1da..544923a1c3 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -555,11 +555,11 @@ void tst_QStyleSheetStyle::layoutSpacing() void tst_QStyleSheetStyle::qproperty() { QPushButton pb; - pb.setStyleSheet("QPushButton { qproperty-text: hello; qproperty-checkable: true; qproperty-checked: 1}"); + pb.setStyleSheet("QPushButton { qproperty-text: hello; qproperty-checkable: 1; qproperty-checked: false}"); pb.ensurePolished(); QCOMPARE(pb.text(), QString("hello")); QCOMPARE(pb.isCheckable(), true); - QCOMPARE(pb.isChecked(), true); + QCOMPARE(pb.isChecked(), false); } namespace ns { @@ -781,10 +781,6 @@ void tst_QStyleSheetStyle::focusColors() + " did not contain background color #e8ff66, using style " + QString::fromLatin1(qApp->style()->metaObject()->className())) .toLocal8Bit().constData()); -#ifdef Q_OS_MAC - if (widget == widgets.first()) - QEXPECT_FAIL("", "Failure only for first widget, the QPushButton, see QTBUG-23686", Continue); -#endif QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), (QString::fromLatin1(widget->metaObject()->className()) + " did not contain text color #ff0084, using style " @@ -882,8 +878,7 @@ void tst_QStyleSheetStyle::hoverColors() (QString::fromLatin1(widget->metaObject()->className()) + " did not contain background color #e8ff66").toLocal8Bit().constData()); #ifdef Q_OS_MAC - if (qobject_cast<QPushButton *>(widget) - || qobject_cast<QComboBox *>(widget)) + if (qobject_cast<QComboBox *>(widget)) QEXPECT_FAIL("", "Failure only for QPushButton and QComboBox, see QTBUG-23686", Continue); #endif QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), diff --git a/tests/auto/widgets/widgets/qcalendarwidget/qcalendarwidget.pro b/tests/auto/widgets/widgets/qcalendarwidget/qcalendarwidget.pro index 127d78596a..f16110cbd1 100644 --- a/tests/auto/widgets/widgets/qcalendarwidget/qcalendarwidget.pro +++ b/tests/auto/widgets/widgets/qcalendarwidget/qcalendarwidget.pro @@ -2,6 +2,3 @@ CONFIG += testcase TARGET = tst_qcalendarwidget QT += widgets testlib SOURCES += tst_qcalendarwidget.cpp - -# QTBUG-23615 - unstable test -linux-*:system(". /etc/lsb-release && [ $DISTRIB_CODENAME = oneiric ]"):CONFIG += insignificant_test diff --git a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp index 4f95f80525..4857900dc8 100644 --- a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp +++ b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp @@ -175,6 +175,8 @@ void tst_QCalendarWidget::buttonClickCheck() QSize size = object.sizeHint(); object.setGeometry(0,0,size.width(), size.height()); object.show(); + QTest::qWaitForWindowShown(&object); + object.activateWindow(); QDate selectedDate(2005, 1, 1); //click on the month buttons diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index 0f07546559..c6a039cb37 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -1435,6 +1435,11 @@ void MoveSeparator::apply(QMainWindow *mw) const } QVERIFY(!path.isEmpty()); + // For QTBUG-15689: + // Following commands is used to simulate user move action. A better way should + // use QMainWindowLayout::startSeparatorMove/separatorMove/endSeparatorMove, + // but then we will need real start/end position coordinates. + l->layoutState.dockAreaLayout.fallbackToSizeHints = false; l->layoutState.dockAreaLayout.separatorMove(path, QPoint(0, 0), QPoint(delta, delta)); } #endif diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 4fffd74491..473c5e05ec 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -562,9 +562,6 @@ void tst_QMenu::tearOff() QTest::mouseClick(menu, Qt::LeftButton, 0, QPoint(3, 3), 10); QTest::qWait(100); -#ifndef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-22565", Abort); -#endif QVERIFY(menu->isTearOffMenuVisible()); QPointer<QMenu> torn = 0; foreach (QWidget *w, QApplication::allWidgets()) { @@ -783,9 +780,6 @@ void tst_QMenu::task258920_mouseBorder() #ifdef Q_OS_WINCE_WM QSKIP("Mouse move related signals for Windows Mobile unavailable"); #endif - // ### fixme: Check platforms - QSKIP("QTBUG-20753 QCursor::setPos() / QTest::mouseMove() doesn't work on qpa"); - Menu258920 menu; // For styles which inherit from QWindowsStyle, styleHint(QStyle::SH_Menu_MouseTracking) is true. menu.setMouseTracking(true); |