diff options
Diffstat (limited to 'tests/auto/corelib')
24 files changed, 1013 insertions, 136 deletions
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp index ccc23851b7..51f07993cd 100644 --- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp +++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp @@ -44,7 +44,6 @@ #include <QtCore/qsequentialanimationgroup.h> Q_DECLARE_METATYPE(QAbstractAnimation::State) -Q_DECLARE_METATYPE(QAbstractAnimation*) class tst_QSequentialAnimationGroup : public QObject { @@ -84,7 +83,6 @@ private slots: void tst_QSequentialAnimationGroup::initTestCase() { qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); - qRegisterMetaType<QAbstractAnimation*>("QAbstractAnimation*"); } void tst_QSequentialAnimationGroup::construction() diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index f54af657c0..3696ee264f 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -55,6 +55,8 @@ private slots: void checkptr(); void qstaticassert(); void qConstructorFunction(); + void qCoreAppStartupFunction(); + void qCoreAppStartupFunctionRestart(); void isEnum(); void qAlignOf(); }; @@ -303,6 +305,33 @@ void tst_QGlobal::qConstructorFunction() QCOMPARE(qConstructorFunctionValue, 123); } +static int qStartupFunctionValue; +static void myStartupFunc() +{ + Q_ASSERT(QCoreApplication::instance()); + if (QCoreApplication::instance()) + qStartupFunctionValue += 124; +} + +Q_COREAPP_STARTUP_FUNCTION(myStartupFunc) + +void tst_QGlobal::qCoreAppStartupFunction() +{ + QCOMPARE(qStartupFunctionValue, 0); + int argc = 1; + char *argv[] = { const_cast<char*>("tst_qglobal") }; + QCoreApplication app(argc, argv); + QCOMPARE(qStartupFunctionValue, 124); +} + +void tst_QGlobal::qCoreAppStartupFunctionRestart() +{ + qStartupFunctionValue = 0; + qCoreAppStartupFunction(); + qStartupFunctionValue = 0; + qCoreAppStartupFunction(); +} + struct isEnum_A { int n_; }; @@ -532,5 +561,5 @@ void tst_QGlobal::qAlignOf() #undef TEST_AlignOf_RValueRef #undef TEST_AlignOf_impl -QTEST_MAIN(tst_QGlobal) +QTEST_APPLESS_MAIN(tst_QGlobal) #include "tst_qglobal.moc" diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro index 03b42a2cbb..948e9dec5f 100644 --- a/tests/auto/corelib/io/io.pro +++ b/tests/auto/corelib/io/io.pro @@ -20,6 +20,7 @@ SUBDIRS=\ qprocessenvironment \ qresourceengine \ qsettings \ + qsavefile \ qstandardpaths \ qtemporarydir \ qtemporaryfile \ diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 333ccc8e49..f452efc1b3 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -52,7 +52,8 @@ private slots: void warningWithoutDebug() const; void criticalWithoutDebug() const; void debugWithBool() const; - void debugNoSpaces() const; + void debugSpaceHandling() const; + void stateSaver() const; void veryLongWarningMessage() const; void qDebugQStringRef() const; void qDebugQLatin1String() const; @@ -150,7 +151,36 @@ void tst_QDebug::debugWithBool() const QCOMPARE(QString::fromLatin1(s_function), function); } -void tst_QDebug::debugNoSpaces() const +class MyPoint +{ +public: + MyPoint(int val1, int val2) + : v1(val1), v2(val2) {} + int v1; + int v2; +}; +QDebug operator<< (QDebug s, const MyPoint& point) +{ + const QDebugStateSaver saver(s); + return s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")"; +} + +class MyLine +{ +public: + MyLine(const MyPoint& point1, const MyPoint& point2) + : p1(point1), p2(point2) {} + MyPoint p1; + MyPoint p2; +}; +QDebug operator<< (QDebug s, const MyLine& line) +{ + const QDebugStateSaver saver(s); + s.nospace() << "MyLine(" << line.p1 << ", " << line.p2 << ")"; + return s; +} + +void tst_QDebug::debugSpaceHandling() const { MessageHandlerSetter mhs(myMessageHandler); { @@ -166,8 +196,26 @@ void tst_QDebug::debugNoSpaces() const d << "key=" << "value"; d.space(); d << 1 << 2; + MyLine line(MyPoint(10, 11), MyPoint (12, 13)); + d << line; + // With the old implementation of MyPoint doing dbg.nospace() << ...; dbg.space() we ended up with + // MyLine(MyPoint(10, 11) , MyPoint(12, 13) ) + } + QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13))")); +} + +void tst_QDebug::stateSaver() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + { + QDebugStateSaver saver(d); + d.nospace() << hex << right << qSetFieldWidth(3) << qSetPadChar('0') << 42; + } + d.space() << 42; } - QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 ")); + QCOMPARE(s_msg, QString::fromLatin1("02a 42 ")); } void tst_QDebug::veryLongWarningMessage() const diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index ded77c649f..c2d578d4c0 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -46,6 +46,7 @@ #include <qcoreapplication.h> #include <qlibrary.h> #include <qtemporaryfile.h> +#include <qtemporarydir.h> #include <qdir.h> #include <qfileinfo.h> #ifdef Q_OS_UNIX @@ -80,7 +81,11 @@ class tst_QFileInfo : public QObject { Q_OBJECT +public: + tst_QFileInfo() : m_currentDir(QDir::currentPath()) {} + private slots: + void initTestCase(); void cleanupTestCase(); void getSetCheck(); @@ -190,32 +195,27 @@ private slots: void invalidState(); void nonExistingFileDates(); + +private: + const QString m_currentDir; + QString m_sourceFile; + QString m_resourcesDir; + QTemporaryDir m_dir; }; -void tst_QFileInfo::cleanupTestCase() +void tst_QFileInfo::initTestCase() { - QFile::remove("brokenlink.lnk"); - QFile::remove("link.lnk"); - QFile::remove("file1"); - QFile::remove("dummyfile"); - QFile::remove("simplefile.txt"); - QFile::remove("longFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileName.txt"); - QFile::remove("tempfile.txt"); + m_sourceFile = QFINDTESTDATA("tst_qfileinfo.cpp"); + QVERIFY(!m_sourceFile.isEmpty()); + m_resourcesDir = QFINDTESTDATA("resources"); + QVERIFY(!m_resourcesDir.isEmpty()); + QVERIFY(m_dir.isValid()); + QVERIFY(QDir::setCurrent(m_dir.path())); +} -#if defined(Q_OS_UNIX) - QDir().rmdir("./.hidden-directory"); - QFile::remove("link_to_tst_qfileinfo"); -#endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - QDir().rmdir("./hidden-directory"); - QDir().rmdir("abs_symlink"); - QDir().rmdir("rel_symlink"); - QDir().rmdir("junction_pwd"); - QDir().rmdir("junction_root"); - QDir().rmdir("mountpoint"); - QFile::remove("abs_symlink.cpp"); - QFile::remove("rel_symlink.cpp"); -#endif +void tst_QFileInfo::cleanupTestCase() +{ + QDir::setCurrent(m_currentDir); // Release temporary directory so that it can be deleted on Windows } // Testing get/set functions @@ -237,10 +237,9 @@ static QFileInfoPrivate* getPrivate(QFileInfo &info) void tst_QFileInfo::copy() { - QTemporaryFile *t; - t = new QTemporaryFile; - t->open(); - QFileInfo info(t->fileName()); + QTemporaryFile t; + t.open(); + QFileInfo info(t.fileName()); QVERIFY(info.exists()); //copy constructor @@ -287,7 +286,7 @@ void tst_QFileInfo::isFile_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << false; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true; + QTest::newRow("data1") << m_sourceFile << true; QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << false; QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << true; QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; @@ -320,13 +319,13 @@ void tst_QFileInfo::isDir_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << true; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << false; + QTest::newRow("data1") << m_sourceFile << false; QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << true; QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << false; QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; - QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true; - QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true; + QTest::newRow("simple dir") << m_resourcesDir << true; + QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true; QTest::newRow("broken link") << "brokenlink.lnk" << false; @@ -366,8 +365,8 @@ void tst_QFileInfo::isRoot_data() QTest::newRow("data4") << ":/tst_qfileinfo/resources/" << false; QTest::newRow("data5") << ":/" << true; - QTest::newRow("simple dir") << QFINDTESTDATA("resources") << false; - QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << false; + QTest::newRow("simple dir") << m_resourcesDir << false; + QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << false; #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) QTest::newRow("drive 1") << "c:" << false; QTest::newRow("drive 2") << "c:/" << true; @@ -398,21 +397,21 @@ void tst_QFileInfo::exists_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << true; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true; + QTest::newRow("data1") << m_sourceFile << true; QTest::newRow("data2") << "/I/do_not_expect_this_path_to_exist/" << false; QTest::newRow("data3") << ":/tst_qfileinfo/resources/" << true; QTest::newRow("data4") << ":/tst_qfileinfo/resources/file1" << true; QTest::newRow("data5") << ":/I/do_not_expect_this_path_to_exist/" << false; - QTest::newRow("data6") << (QFINDTESTDATA("resources/") + "*") << false; - QTest::newRow("data7") << (QFINDTESTDATA("resources/") + "*.foo") << false; - QTest::newRow("data8") << (QFINDTESTDATA("resources/") + "*.ext1") << false; - QTest::newRow("data9") << (QFINDTESTDATA("resources/") + "file?.ext1") << false; + QTest::newRow("data6") << (m_resourcesDir + "/*") << false; + QTest::newRow("data7") << (m_resourcesDir + "/*.foo") << false; + QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false; + QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false; QTest::newRow("data10") << "." << true; QTest::newRow("data11") << ". " << false; QTest::newRow("empty") << "" << false; - QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true; - QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true; + QTest::newRow("simple dir") << m_resourcesDir << true; + QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; @@ -561,7 +560,7 @@ void tst_QFileInfo::canonicalFilePath() // test symlinks QFile::remove("link.lnk"); { - QFile file(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFile file(m_sourceFile); if (file.link("link.lnk")) { QFileInfo info1(file); QFileInfo info2("link.lnk"); @@ -587,7 +586,7 @@ void tst_QFileInfo::canonicalFilePath() QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); QFileInfo info3(link + QDir::separator() + "link.lnk"); - QFileInfo info4(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFileInfo info4(m_sourceFile); QVERIFY(!info3.canonicalFilePath().isEmpty()); QCOMPARE(info4.canonicalFilePath(), info3.canonicalFilePath()); @@ -621,20 +620,21 @@ void tst_QFileInfo::canonicalFilePath() // CreateSymbolicLink can return TRUE & still fail to create the link, // the error code in that case is ERROR_PRIVILEGE_NOT_HELD (1314) SetLastError(0); - BOOL ret = ptrCreateSymbolicLink((wchar_t*)QString("res").utf16(), (wchar_t*)QString("resources").utf16(), 1); + const QString linkTarget = QStringLiteral("res"); + BOOL ret = ptrCreateSymbolicLink((wchar_t*)linkTarget.utf16(), (wchar_t*)m_resourcesDir.utf16(), 1); DWORD dwErr = GetLastError(); if (!ret) QSKIP("Symbolic links aren't supported by FS"); QString currentPath = QDir::currentPath(); - bool is_res_Current = QDir::setCurrent("res"); + bool is_res_Current = QDir::setCurrent(linkTarget); if (!is_res_Current && dwErr == 1314) QSKIP("Not enough privilages to create Symbolic links"); QCOMPARE(is_res_Current, true); + const QString actualCanonicalPath = QFileInfo("file1").canonicalFilePath(); + QVERIFY(QDir::setCurrent(currentPath)); + QCOMPARE(actualCanonicalPath, m_resourcesDir + QStringLiteral("/file1")); - QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1"); - - QCOMPARE(QDir::setCurrent(currentPath), true); - QDir::current().rmdir("res"); + QDir::current().rmdir(linkTarget); } #endif } @@ -855,7 +855,7 @@ void tst_QFileInfo::permission_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << int(QFile::ExeUser) << true; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << int(QFile::ReadUser) << true; + QTest::newRow("data1") << m_sourceFile << int(QFile::ReadUser) << true; QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true; QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false; QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ExeUser) << false; @@ -921,13 +921,15 @@ void tst_QFileInfo::compare_data() if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) caseSensitiveOnMac = false; #endif + QString caseChangedSource = m_sourceFile; + caseChangedSource.replace("info", "Info"); QTest::newRow("data0") - << QFINDTESTDATA("tst_qfileinfo.cpp") - << QFINDTESTDATA("tst_qfileinfo.cpp") + << m_sourceFile + << m_sourceFile << true; QTest::newRow("data1") - << QFINDTESTDATA("tst_qfileinfo.cpp") + << m_sourceFile << QString::fromLatin1("/tst_qfileinfo.cpp") << false; QTest::newRow("data2") @@ -935,8 +937,8 @@ void tst_QFileInfo::compare_data() << QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp") << true; QTest::newRow("casesense1") - << QFINDTESTDATA("tst_qfileinfo.cpp").replace("info", "Info") - << QFINDTESTDATA("tst_qfileinfo.cpp") + << caseChangedSource + << m_sourceFile #if defined(Q_OS_WIN) << true; #elif defined(Q_OS_MAC) @@ -1140,7 +1142,7 @@ void tst_QFileInfo::isSymLink_data() QFile::remove("brokenlink.lnk"); QFile::remove("dummyfile"); - QFile file1(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFile file1(m_sourceFile); QVERIFY(file1.link("link.lnk")); QFile file2("dummyfile"); @@ -1152,8 +1154,8 @@ void tst_QFileInfo::isSymLink_data() QTest::addColumn<bool>("isSymLink"); QTest::addColumn<QString>("linkTarget"); - QTest::newRow("existent file") << QFINDTESTDATA("tst_qfileinfo.cpp") << false << ""; - QTest::newRow("link") << "link.lnk" << true << QFileInfo(QFINDTESTDATA("tst_qfileinfo.cpp")).absoluteFilePath(); + QTest::newRow("existent file") << m_sourceFile << false << ""; + QTest::newRow("link") << "link.lnk" << true << QFileInfo(m_sourceFile).absoluteFilePath(); QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); } @@ -1390,7 +1392,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() } { //File symlinks - QFileInfo target(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFileInfo target(m_sourceFile); QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath()); QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp"); QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath())); @@ -1447,10 +1449,22 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks() QFETCH(QString, canonicalFilePath); QFileInfo fi(path); - QCOMPARE(fi.isSymLink(), isSymLink); + const bool actualIsSymLink = fi.isSymLink(); + const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString(); + const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString(); + // Ensure that junctions, mountpoints are removed. If this fails, do not remove + // temporary directory to prevent it from trashing the system. + if (fi.isDir()) { + if (!QDir().rmdir(fi.fileName())) { + qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.", + qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path()))); + m_dir.setAutoRemove(false); + } + } + QCOMPARE(actualIsSymLink, isSymLink); if (isSymLink) { - QCOMPARE(fi.symLinkTarget(), linkTarget); - QCOMPARE(fi.canonicalFilePath(), canonicalFilePath); + QCOMPARE(actualSymLinkTarget, linkTarget); + QCOMPARE(actualCanonicalFilePath, canonicalFilePath); } } diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 7965d1d431..11824f4ab6 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1256,7 +1256,6 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() process->start("testProcessEcho/testProcessEcho"); QVERIFY(process->waitForStarted(5000)); - qRegisterMetaType<qint64>("qint64"); QSignalSpy spy(process, SIGNAL(bytesWritten(qint64))); QVERIFY(spy.isValid()); process->write("f"); diff --git a/tests/auto/corelib/io/qsavefile/qsavefile.pro b/tests/auto/corelib/io/qsavefile/qsavefile.pro new file mode 100644 index 0000000000..36db000fa7 --- /dev/null +++ b/tests/auto/corelib/io/qsavefile/qsavefile.pro @@ -0,0 +1,5 @@ +CONFIG += testcase parallel_test +TARGET = tst_qsavefile +QT = core testlib +SOURCES = tst_qsavefile.cpp +TESTDATA += tst_qsavefile.cpp diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp new file mode 100644 index 0000000000..5ef4b11e8a --- /dev/null +++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** Copyright (C) 2012 David Faure <faure@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <qcoreapplication.h> +#include <qstring.h> +#include <qtemporaryfile.h> +#include <qfile.h> +#include <qdir.h> +#include <qset.h> + +#if defined(Q_OS_UNIX) +# include <unistd.h> // for geteuid +# include <sys/types.h> +#endif + +#if defined(Q_OS_WIN) +# include <windows.h> +#endif + +class tst_QSaveFile : public QObject +{ + Q_OBJECT +public slots: + +private slots: + void transactionalWrite(); + void textStreamManualFlush(); + void textStreamAutoFlush(); + void saveTwice(); + void transactionalWriteNoPermissionsOnDir(); + void transactionalWriteNoPermissionsOnFile(); + void transactionalWriteCanceled(); + void transactionalWriteErrorRenaming(); +}; + +void tst_QSaveFile::transactionalWrite() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QFile::remove(targetFile); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QVERIFY(file.isOpen()); + QCOMPARE(file.fileName(), targetFile); + QVERIFY(!QFile::exists(targetFile)); + + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + QCOMPARE(file.error(), QFile::NoError); + QVERIFY(!QFile::exists(targetFile)); + + QVERIFY(file.commit()); + QVERIFY(QFile::exists(targetFile)); + QCOMPARE(file.fileName(), targetFile); + + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll()), QString::fromLatin1("Hello")); +} + +void tst_QSaveFile::saveTwice() +{ + // Check that we can reuse a QSaveFile object + // (and test the case of an existing target file) + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + QVERIFY2(file.commit(), qPrintable(file.errorString())); + + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("World"), Q_INT64_C(5)); + QVERIFY2(file.commit(), qPrintable(file.errorString())); + + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll()), QString::fromLatin1("World")); +} + +void tst_QSaveFile::textStreamManualFlush() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + + QTextStream ts(&file); + ts << "Manual flush"; + ts.flush(); + QCOMPARE(file.error(), QFile::NoError); + QVERIFY(!QFile::exists(targetFile)); + + QVERIFY(file.commit()); + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Manual flush")); + QFile::remove(targetFile); +} + +void tst_QSaveFile::textStreamAutoFlush() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + + QTextStream ts(&file); + ts << "Auto-flush."; + // no flush + QVERIFY(file.commit()); // QIODevice::close will emit aboutToClose, which will flush the stream + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Auto-flush.")); + QFile::remove(targetFile); +} + +void tst_QSaveFile::transactionalWriteNoPermissionsOnDir() +{ +#ifdef Q_OS_UNIX + if (::geteuid() == 0) + QSKIP("not valid running this test as root"); + + // You can write into /dev/zero, but you can't create a /dev/zero.XXXXXX temp file. + QSaveFile file("/dev/zero"); + if (!QDir("/dev").exists()) + QSKIP("/dev doesn't exist on this system"); + + QVERIFY(!file.open(QIODevice::WriteOnly)); + QCOMPARE((int)file.error(), (int)QFile::OpenError); + QVERIFY(!file.commit()); +#endif +} + +void tst_QSaveFile::transactionalWriteNoPermissionsOnFile() +{ + // Setup an existing but readonly file + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + file.close(); + file.setPermissions(QFile::ReadOwner); + QVERIFY(!file.open(QIODevice::WriteOnly)); + + // Try saving into it + { + QSaveFile saveFile(targetFile); + QVERIFY(!saveFile.open(QIODevice::WriteOnly)); // just like QFile + } + QVERIFY(file.exists()); +} + +void tst_QSaveFile::transactionalWriteCanceled() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QFile::remove(targetFile); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + + QTextStream ts(&file); + ts << "This writing operation will soon be canceled.\n"; + ts.flush(); + QCOMPARE(file.error(), QFile::NoError); + QVERIFY(!QFile::exists(targetFile)); + + // We change our mind, let's abort writing + file.cancelWriting(); + + QVERIFY(!file.commit()); + + QVERIFY(!QFile::exists(targetFile)); // temp file was discarded + QCOMPARE(file.fileName(), targetFile); +} + +void tst_QSaveFile::transactionalWriteErrorRenaming() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Hello"), qint64(5)); + QVERIFY(!QFile::exists(targetFile)); + + // Restore permissions so that the QTemporaryDir cleanup can happen + class PermissionRestorer + { + public: + PermissionRestorer(const QString& path) + : m_path(path) + {} + + ~PermissionRestorer() + { + QFile file(m_path); +#ifdef Q_OS_UNIX + file.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)); +#else + file.setPermissions(QFile::WriteOwner); + file.remove(); +#endif + } + + private: + QString m_path; + }; + +#ifdef Q_OS_UNIX + // Make rename() fail for lack of permissions in the directory + QFile dirAsFile(dir.path()); // yay, I have to use QFile to change a dir's permissions... + QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions + PermissionRestorer permissionRestorer(dir.path()); +#else + // Windows: Make rename() fail for lack of permissions on an existing target file + QFile existingTargetFile(targetFile); + QVERIFY(existingTargetFile.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Target"), qint64(6)); + existingTargetFile.close(); + QVERIFY(existingTargetFile.setPermissions(QFile::ReadOwner)); + PermissionRestorer permissionRestorer(targetFile); +#endif + + // The saving should fail. + QVERIFY(!file.commit()); +#ifdef Q_OS_UNIX + QVERIFY(!QFile::exists(targetFile)); // renaming failed +#endif + QCOMPARE(file.error(), QFile::RenameError); +} + +QTEST_MAIN(tst_QSaveFile) +#include "tst_qsavefile.moc" diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 124ccbb456..e733a8f5f8 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -79,6 +79,8 @@ private slots: void toString(); void toString_constructed_data(); void toString_constructed(); + void toAndFromStringList_data(); + void toAndFromStringList(); void isParentOf_data(); void isParentOf(); void toLocalFile_data(); @@ -941,6 +943,25 @@ void tst_QUrl::toString() QCOMPARE(url.toString(QUrl::FormattingOptions(options)), string); } +void tst_QUrl::toAndFromStringList_data() +{ + QTest::addColumn<QStringList>("strings"); + + QTest::newRow("empty") << QStringList(); + QTest::newRow("local") << (QStringList() << "file:///tmp" << "file:///"); + QTest::newRow("remote") << (QStringList() << "http://qt-project.org"); +} + +void tst_QUrl::toAndFromStringList() +{ + QFETCH(QStringList, strings); + + const QList<QUrl> urls = QUrl::fromStringList(strings); + QCOMPARE(urls.count(), strings.count()); + const QStringList converted = QUrl::toStringList(urls); + QCOMPARE(converted, strings); +} + //### more tests ... what do we expect ... void tst_QUrl::isParentOf_data() { diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 20bd4fa433..d2fb56ce02 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -467,9 +467,6 @@ typedef QPair<int, int> Position; typedef QVector<QPair<int, int> > Selection; typedef QVector<QVector<QString> > StringTable; typedef QVector<QString> StringTableRow; -Q_DECLARE_METATYPE(Position) -Q_DECLARE_METATYPE(Selection) -Q_DECLARE_METATYPE(StringTable) static StringTableRow qStringTableRow(const QString &s1, const QString &s2, const QString &s3) { @@ -1922,8 +1919,6 @@ public: void tst_QAbstractItemModel::testDataChanged() { - qRegisterMetaType<QVector<int> >(); - CustomRoleModel model; QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>))); diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp index c8cbacf76e..c385a02b9c 100644 --- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp @@ -281,8 +281,6 @@ void tst_QAbstractProxyModel::revert() // public void setSourceModel(QAbstractItemModel* sourceModel) void tst_QAbstractProxyModel::setSourceModel() { - qRegisterMetaType<QAbstractItemModel*>(); - SubQAbstractProxyModel model; QCOMPARE(model.property("sourceModel"), QVariant::fromValue<QAbstractItemModel*>(0)); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 02a4824c4b..998e78a0fd 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -54,6 +54,8 @@ typedef QList<int> IntList; typedef QPair<int, int> IntPair; typedef QList<IntPair> IntPairList; +Q_DECLARE_METATYPE(QList<QPersistentModelIndex>) + class tst_QSortFilterProxyModel : public QObject { Q_OBJECT @@ -174,9 +176,7 @@ tst_QSortFilterProxyModel::tst_QSortFilterProxyModel() void tst_QSortFilterProxyModel::initTestCase() { - qRegisterMetaType<IntList>("IntList"); - qRegisterMetaType<IntPair>("IntPair"); - qRegisterMetaType<IntPairList>("IntPairList"); + qRegisterMetaType<QList<QPersistentModelIndex> >(); m_model = new QStandardItemModel(0, 1); m_proxy = new QSortFilterProxyModel(); m_proxy->setSourceModel(m_model); @@ -3242,8 +3242,6 @@ void tst_QSortFilterProxyModel::resetInvalidate() QCOMPARE(ok, works); } -Q_DECLARE_METATYPE(QList<QPersistentModelIndex>) - void tst_QSortFilterProxyModel::testParentLayoutChanged() { QStandardItemModel model; @@ -3276,8 +3274,6 @@ void tst_QSortFilterProxyModel::testParentLayoutChanged() proxy2.setSourceModel(&proxy); proxy2.setObjectName("proxy2"); - qRegisterMetaType<QList<QPersistentModelIndex> >(); - QSignalSpy dataChangedSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); QVERIFY(dataChangedSpy.isValid()); @@ -3411,8 +3407,6 @@ private: void tst_QSortFilterProxyModel::moveSourceRows() { - qRegisterMetaType<QList<QPersistentModelIndex> >(); - DynamicTreeModel model; { diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index a586f81ccc..57a43a2b33 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -64,6 +64,12 @@ QRunnable *createTask(FunctionPointer pointer) class tst_QThreadPool : public QObject { Q_OBJECT +public: + tst_QThreadPool(); + ~tst_QThreadPool(); + + static QMutex *functionTestMutex; + private slots: void runFunction(); void createThreadRunFunction(); @@ -92,8 +98,24 @@ private slots: void waitForDoneTimeout(); void destroyingWaitsForTasksToFinish(); void stressTest(); + +private: + QMutex m_functionTestMutex; }; + +QMutex *tst_QThreadPool::functionTestMutex = 0; + +tst_QThreadPool::tst_QThreadPool() +{ + tst_QThreadPool::functionTestMutex = &m_functionTestMutex; +} + +tst_QThreadPool::~tst_QThreadPool() +{ + tst_QThreadPool::functionTestMutex = 0; +} + int testFunctionCount; void sleepTestFunction() @@ -114,19 +136,19 @@ void noSleepTestFunction() void sleepTestFunctionMutex() { - static QMutex testMutex; + Q_ASSERT(tst_QThreadPool::functionTestMutex); QTest::qSleep(1000); - testMutex.lock(); + tst_QThreadPool::functionTestMutex->lock(); ++testFunctionCount; - testMutex.unlock(); + tst_QThreadPool::functionTestMutex->unlock(); } void noSleepTestFunctionMutex() { - static QMutex testMutex; - testMutex.lock(); + Q_ASSERT(tst_QThreadPool::functionTestMutex); + tst_QThreadPool::functionTestMutex->lock(); ++testFunctionCount; - testMutex.unlock(); + tst_QThreadPool::functionTestMutex->unlock(); } void tst_QThreadPool::runFunction() diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 478747bf15..c89d553112 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -709,40 +709,40 @@ void tst_QChar::lineBreakClass() void tst_QChar::script() { - QVERIFY(QUnicodeTables::script(0x0020u) == QUnicodeTables::Common); - QVERIFY(QUnicodeTables::script(0x0041u) == QUnicodeTables::Common); // ### Latin - QVERIFY(QUnicodeTables::script(0x0375u) == QUnicodeTables::Greek); - QVERIFY(QUnicodeTables::script(0x0400u) == QUnicodeTables::Cyrillic); - QVERIFY(QUnicodeTables::script(0x0531u) == QUnicodeTables::Armenian); - QVERIFY(QUnicodeTables::script(0x0591u) == QUnicodeTables::Hebrew); - QVERIFY(QUnicodeTables::script(0x0600u) == QUnicodeTables::Arabic); - QVERIFY(QUnicodeTables::script(0x0700u) == QUnicodeTables::Syriac); - QVERIFY(QUnicodeTables::script(0x0780u) == QUnicodeTables::Thaana); - QVERIFY(QUnicodeTables::script(0x07c0u) == QUnicodeTables::Nko); - QVERIFY(QUnicodeTables::script(0x0900u) == QUnicodeTables::Devanagari); - QVERIFY(QUnicodeTables::script(0x0981u) == QUnicodeTables::Bengali); - QVERIFY(QUnicodeTables::script(0x0a01u) == QUnicodeTables::Gurmukhi); - QVERIFY(QUnicodeTables::script(0x0a81u) == QUnicodeTables::Gujarati); - QVERIFY(QUnicodeTables::script(0x0b01u) == QUnicodeTables::Oriya); - QVERIFY(QUnicodeTables::script(0x0b82u) == QUnicodeTables::Tamil); - QVERIFY(QUnicodeTables::script(0x0c01u) == QUnicodeTables::Telugu); - QVERIFY(QUnicodeTables::script(0x0c82u) == QUnicodeTables::Kannada); - QVERIFY(QUnicodeTables::script(0x0d02u) == QUnicodeTables::Malayalam); - QVERIFY(QUnicodeTables::script(0x0d82u) == QUnicodeTables::Sinhala); - QVERIFY(QUnicodeTables::script(0x0e01u) == QUnicodeTables::Thai); - QVERIFY(QUnicodeTables::script(0x0e81u) == QUnicodeTables::Lao); - QVERIFY(QUnicodeTables::script(0x0f00u) == QUnicodeTables::Tibetan); - QVERIFY(QUnicodeTables::script(0x1000u) == QUnicodeTables::Myanmar); - QVERIFY(QUnicodeTables::script(0x10a0u) == QUnicodeTables::Georgian); - QVERIFY(QUnicodeTables::script(0x1100u) == QUnicodeTables::Hangul); - QVERIFY(QUnicodeTables::script(0x1680u) == QUnicodeTables::Ogham); - QVERIFY(QUnicodeTables::script(0x16a0u) == QUnicodeTables::Runic); - QVERIFY(QUnicodeTables::script(0x1780u) == QUnicodeTables::Khmer); - QVERIFY(QUnicodeTables::script(0x200cu) == QUnicodeTables::Inherited); - QVERIFY(QUnicodeTables::script(0x200du) == QUnicodeTables::Inherited); - QVERIFY(QUnicodeTables::script(0x1018au) == QUnicodeTables::Greek); - QVERIFY(QUnicodeTables::script(0x1f130u) == QUnicodeTables::Common); - QVERIFY(QUnicodeTables::script(0xe0100u) == QUnicodeTables::Inherited); + QVERIFY(QChar::script(0x0020u) == QChar::Script_Common); + QVERIFY(QChar::script(0x0041u) == QChar::Script_Latin); + QVERIFY(QChar::script(0x0375u) == QChar::Script_Greek); + QVERIFY(QChar::script(0x0400u) == QChar::Script_Cyrillic); + QVERIFY(QChar::script(0x0531u) == QChar::Script_Armenian); + QVERIFY(QChar::script(0x0591u) == QChar::Script_Hebrew); + QVERIFY(QChar::script(0x0600u) == QChar::Script_Arabic); + QVERIFY(QChar::script(0x0700u) == QChar::Script_Syriac); + QVERIFY(QChar::script(0x0780u) == QChar::Script_Thaana); + QVERIFY(QChar::script(0x07c0u) == QChar::Script_Nko); + QVERIFY(QChar::script(0x0900u) == QChar::Script_Devanagari); + QVERIFY(QChar::script(0x0981u) == QChar::Script_Bengali); + QVERIFY(QChar::script(0x0a01u) == QChar::Script_Gurmukhi); + QVERIFY(QChar::script(0x0a81u) == QChar::Script_Gujarati); + QVERIFY(QChar::script(0x0b01u) == QChar::Script_Oriya); + QVERIFY(QChar::script(0x0b82u) == QChar::Script_Tamil); + QVERIFY(QChar::script(0x0c01u) == QChar::Script_Telugu); + QVERIFY(QChar::script(0x0c82u) == QChar::Script_Kannada); + QVERIFY(QChar::script(0x0d02u) == QChar::Script_Malayalam); + QVERIFY(QChar::script(0x0d82u) == QChar::Script_Sinhala); + QVERIFY(QChar::script(0x0e01u) == QChar::Script_Thai); + QVERIFY(QChar::script(0x0e81u) == QChar::Script_Lao); + QVERIFY(QChar::script(0x0f00u) == QChar::Script_Tibetan); + QVERIFY(QChar::script(0x1000u) == QChar::Script_Myanmar); + QVERIFY(QChar::script(0x10a0u) == QChar::Script_Georgian); + QVERIFY(QChar::script(0x1100u) == QChar::Script_Hangul); + QVERIFY(QChar::script(0x1680u) == QChar::Script_Ogham); + QVERIFY(QChar::script(0x16a0u) == QChar::Script_Runic); + QVERIFY(QChar::script(0x1780u) == QChar::Script_Khmer); + QVERIFY(QChar::script(0x200cu) == QChar::Script_Inherited); + QVERIFY(QChar::script(0x200du) == QChar::Script_Inherited); + QVERIFY(QChar::script(0x1018au) == QChar::Script_Greek); + QVERIFY(QChar::script(0x1f130u) == QChar::Script_Common); + QVERIFY(QChar::script(0xe0100u) == QChar::Script_Inherited); } void tst_QChar::normalization_data() diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp index 9700f91128..80311079d4 100644 --- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp +++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp @@ -50,6 +50,7 @@ class tst_QMargins : public QObject private slots: void getSetCheck(); void dataStreamCheck(); + void operators(); }; // Testing get/set functions @@ -75,6 +76,49 @@ void tst_QMargins::getSetCheck() QCOMPARE(margins, QMargins(5, 0, 5, 0)); } +void tst_QMargins::operators() +{ + const QMargins m1(12, 14, 16, 18); + const QMargins m2(2, 3, 4, 5); + + const QMargins added = m1 + m2; + QCOMPARE(added, QMargins(14, 17, 20, 23)); + QMargins a = m1; + a += m2; + QCOMPARE(a, added); + + const QMargins subtracted = m1 - m2; + QCOMPARE(subtracted, QMargins(10, 11, 12, 13)); + a = m1; + a -= m2; + QCOMPARE(a, subtracted); + + const QMargins doubled = m1 * 2; + QCOMPARE(doubled, QMargins(24, 28, 32, 36)); + QCOMPARE(2 * m1, doubled); + QCOMPARE(qreal(2) * m1, doubled); + QCOMPARE(m1 * qreal(2), doubled); + + a = m1; + a *= 2; + QCOMPARE(a, doubled); + a = m1; + a *= qreal(2); + QCOMPARE(a, doubled); + + const QMargins halved = m1 / 2; + QCOMPARE(halved, QMargins(6, 7, 8, 9)); + + a = m1; + a /= 2; + QCOMPARE(a, halved); + a = m1; + a /= qreal(2); + QCOMPARE(a, halved); + + QCOMPARE(m1 + (-m1), QMargins()); +} + // Testing QDataStream operators void tst_QMargins::dataStreamCheck() { diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore new file mode 100644 index 0000000000..bfd53f437b --- /dev/null +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore @@ -0,0 +1 @@ +tst_qmessageauthenticationcode diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro new file mode 100644 index 0000000000..1ea23915b7 --- /dev/null +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro @@ -0,0 +1,7 @@ +CONFIG += testcase parallel_test +TARGET = tst_qmessageauthenticationcode +QT = core testlib +SOURCES = tst_qmessageauthenticationcode.cpp + +TESTDATA += data/* +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp new file mode 100644 index 0000000000..0e243988e2 --- /dev/null +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtCore/QCoreApplication> +#include <QtTest/QtTest> + +class tst_QMessageAuthenticationCode : public QObject +{ + Q_OBJECT +private slots: + void result_data(); + void result(); + void result_incremental_data(); + void result_incremental(); +}; + +Q_DECLARE_METATYPE(QCryptographicHash::Algorithm) + +void tst_QMessageAuthenticationCode::result_data() +{ + QTest::addColumn<QCryptographicHash::Algorithm>("algo"); + QTest::addColumn<QByteArray>("key"); + QTest::addColumn<QByteArray>("message"); + QTest::addColumn<QByteArray>("code"); + + // Empty values + QTest::newRow("md5-empty") << QCryptographicHash::Md5 + << QByteArray() + << QByteArray() + << QByteArray::fromHex("74e6f7298a9c2d168935f58c001bad88"); + QTest::newRow("sha1-empty") << QCryptographicHash::Sha1 + << QByteArray() + << QByteArray() + << QByteArray::fromHex("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d"); + QTest::newRow("sha256-empty") << QCryptographicHash::Sha256 + << QByteArray() + << QByteArray() + << QByteArray::fromHex("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad"); + + // Some not-empty + QTest::newRow("md5") << QCryptographicHash::Md5 + << QByteArray("key") + << QByteArray("The quick brown fox jumps over the lazy dog") + << QByteArray::fromHex("80070713463e7749b90c2dc24911e275"); + QTest::newRow("sha1") << QCryptographicHash::Sha1 + << QByteArray("key") + << QByteArray("The quick brown fox jumps over the lazy dog") + << QByteArray::fromHex("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"); + QTest::newRow("sha256") << QCryptographicHash::Sha256 + << QByteArray("key") + << QByteArray("The quick brown fox jumps over the lazy dog") + << QByteArray::fromHex("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"); + + // Some from rfc-2104 + QTest::newRow("rfc-md5-1") << QCryptographicHash::Md5 + << QByteArray::fromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b") + << QByteArray("Hi There") + << QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d"); + QTest::newRow("rfc-md5-2") << QCryptographicHash::Md5 + << QByteArray("Jefe") + << QByteArray("what do ya want for nothing?") + << QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738"); + QTest::newRow("rfc-md5-3") << QCryptographicHash::Md5 + << QByteArray::fromHex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + << QByteArray(50, 0xdd) + << QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6"); +} + +void tst_QMessageAuthenticationCode::result() +{ + QFETCH(QCryptographicHash::Algorithm, algo); + QFETCH(QByteArray, key); + QFETCH(QByteArray, message); + QFETCH(QByteArray, code); + + QMessageAuthenticationCode mac(algo); + mac.setKey(key); + mac.addData(message); + QByteArray result = mac.result(); + + QCOMPARE(result, code); +} + +void tst_QMessageAuthenticationCode::result_incremental_data() +{ + result_data(); +} + +void tst_QMessageAuthenticationCode::result_incremental() +{ + QFETCH(QCryptographicHash::Algorithm, algo); + QFETCH(QByteArray, key); + QFETCH(QByteArray, message); + QFETCH(QByteArray, code); + + int index = message.length() / 2; + QByteArray leftPart(message.mid(0, index)); + QByteArray rightPart(message.mid(index)); + + QCOMPARE(leftPart + rightPart, message); + + QMessageAuthenticationCode mac(algo); + mac.setKey(key); + mac.addData(leftPart); + mac.addData(rightPart); + QByteArray result = mac.result(); + + QCOMPARE(result, code); +} + +QTEST_MAIN(tst_QMessageAuthenticationCode) +#include "tst_qmessageauthenticationcode.moc" diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index b3fc8b0759..1b11673bd1 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -41,6 +41,7 @@ #include <QtTest/QtTest> #include <qrect.h> +#include <qmargins.h> #include <limits.h> #include <qdebug.h> @@ -133,6 +134,7 @@ private slots: void newMoveTopLeft(); void newMoveBottomRight_data(); void newMoveBottomRight(); + void margins(); void translate_data(); void translate(); @@ -3484,6 +3486,25 @@ void tst_QRect::newMoveBottomRight() QCOMPARE(r,nr); } +void tst_QRect::margins() +{ + const QRect rectangle = QRect(QPoint(10, 10), QSize(50 ,50)); + const QMargins margins = QMargins(2, 3, 4, 5); + + const QRect added = rectangle + margins; + QCOMPARE(added, QRect(QPoint(8, 7), QSize(56, 58))); + QCOMPARE(added, margins + rectangle); + QCOMPARE(added, rectangle.marginsAdded(margins)); + + QRect a = rectangle; + a += margins; + QCOMPARE(added, a); + + a = rectangle; + a -= margins; + QCOMPARE(a, QRect(QPoint(12, 13), QSize(44, 42))); + QCOMPARE(a, rectangle.marginsRemoved(margins)); +} void tst_QRect::translate_data() { diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 7073805db4..139f831b3d 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -126,8 +126,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &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) { @@ -293,6 +291,31 @@ void tst_QRegularExpression::provideRegularExpressions() | QRegularExpression::InvertedGreedinessOption); } +void tst_QRegularExpression::defaultConstructors() +{ + QRegularExpression re; + QCOMPARE(re.pattern(), QString()); + QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); + + QRegularExpressionMatch match; + QCOMPARE(match.regularExpression(), QRegularExpression()); + QCOMPARE(match.regularExpression(), re); + QCOMPARE(match.matchType(), QRegularExpression::NoMatch); + QCOMPARE(match.matchOptions(), QRegularExpression::NoMatchOption); + QCOMPARE(match.hasMatch(), false); + QCOMPARE(match.hasPartialMatch(), false); + QCOMPARE(match.isValid(), true); + QCOMPARE(match.lastCapturedIndex(), -1); + + QRegularExpressionMatchIterator iterator; + QCOMPARE(iterator.regularExpression(), QRegularExpression()); + QCOMPARE(iterator.regularExpression(), re); + QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch); + QCOMPARE(iterator.matchOptions(), QRegularExpression::NoMatchOption); + QCOMPARE(iterator.isValid(), true); + QCOMPARE(iterator.hasNext(), false); +} + void tst_QRegularExpression::gettersSetters_data() { provideRegularExpressions(); @@ -693,12 +716,31 @@ void tst_QRegularExpression::normalMatch() QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(Match, match); - QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); - consistencyCheck(m); - QVERIFY(m == match); + { + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NormalMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + Match realMatch; + realMatch.clear(); + realMatch.isValid = match.isValid; + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == realMatch); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NoMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } } - void tst_QRegularExpression::partialMatch_data() { QTest::addColumn<QRegularExpression>("regexp"); @@ -952,9 +994,29 @@ void tst_QRegularExpression::partialMatch() QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(Match, match); - QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); - consistencyCheck(m); - QVERIFY(m == match); + { + QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), matchType); + QCOMPARE(m.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + Match realMatch; + realMatch.clear(); + realMatch.isValid = match.isValid; + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == realMatch); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NoMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } } void tst_QRegularExpression::globalMatch_data() @@ -1223,10 +1285,28 @@ void tst_QRegularExpression::globalMatch() 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); + QCOMPARE(iterator.regularExpression(), regexp); + QCOMPARE(iterator.matchType(), matchType); + QCOMPARE(iterator.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + QList<Match> realMatchList; + + QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(iterator); + QVERIFY(iterator == realMatchList); + QCOMPARE(iterator.regularExpression(), regexp); + QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch); + QCOMPARE(iterator.matchOptions(), matchOptions); + } - QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions); - consistencyCheck(iterator); - QVERIFY(iterator == matchList); } void tst_QRegularExpression::serialize_data() diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h index d6f9312411..6df7b80ac4 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -51,6 +51,7 @@ class tst_QRegularExpression : public QObject Q_OBJECT private slots: + void defaultConstructors(); void gettersSetters_data(); void gettersSetters(); void escape_data(); diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 8e10b757c8..5b1a2cf076 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -97,6 +97,7 @@ private slots: void lambdaCustomDeleter(); #endif void creating(); + void creatingVariadic(); void creatingQObject(); void mixTrackingPointerCode(); void reentrancyWhileDestructing(); @@ -176,6 +177,49 @@ public: int Data::generationCounter = 0; int Data::destructorCounter = 0; +struct NoDefaultConstructor1 +{ + int i; + NoDefaultConstructor1(int i) : i(i) {} + NoDefaultConstructor1(uint j) : i(j + 42) {} +}; + +struct NoDefaultConstructorRef1 +{ + int &i; + NoDefaultConstructorRef1(int &i) : i(i) {} +}; + +struct NoDefaultConstructor2 +{ + void *ptr; + int i; + NoDefaultConstructor2(void *ptr, int i) : ptr(ptr), i(i) {} +}; + +struct NoDefaultConstructorRef2 +{ + QString str; + int i; + NoDefaultConstructorRef2(QString &str, int i) : str(str), i(i) {} +}; + +struct NoDefaultConstructorConstRef2 +{ + QString str; + int i; + NoDefaultConstructorConstRef2(const QString &str, int i) : str(str), i(i) {} + NoDefaultConstructorConstRef2(const QByteArray &ba, int i = 42) : str(QString::fromLatin1(ba)), i(i) {} +}; + +#ifdef Q_COMPILER_RVALUE_REFS +struct NoDefaultConstructorRRef1 +{ + int &i; + NoDefaultConstructorRRef1(int &&i) : i(i) {} +}; +#endif + void tst_QSharedPointer::basics_data() { QTest::addColumn<bool>("isNull"); @@ -1436,6 +1480,82 @@ void tst_QSharedPointer::creating() safetyCheck(); } +void tst_QSharedPointer::creatingVariadic() +{ +#if !defined(Q_COMPILER_RVALUE_REFS) || !defined(Q_COMPILER_VARIADIC_TEMPLATES) + QSKIP("This compiler is not in C++11 mode or it doesn't support rvalue refs and variadic templates"); +#else + int i = 42; + + { + NoDefaultConstructor1(1); // control check + QSharedPointer<NoDefaultConstructor1> ptr = QSharedPointer<NoDefaultConstructor1>::create(1); + QCOMPARE(ptr->i, 1); + + NoDefaultConstructor1(0u); // control check + ptr = QSharedPointer<NoDefaultConstructor1>::create(0u); + QCOMPARE(ptr->i, 42); + + NoDefaultConstructor1 x(i); // control check + ptr = QSharedPointer<NoDefaultConstructor1>::create(i); + QCOMPARE(ptr->i, i); + } + { + NoDefaultConstructor2((void*)0, 1); // control check + QSharedPointer<NoDefaultConstructor2> ptr = QSharedPointer<NoDefaultConstructor2>::create((void*)0, 1); + QCOMPARE(ptr->i, 1); + QCOMPARE(ptr->ptr, (void*)0); + + int *null = 0; + NoDefaultConstructor2(null, 2); // control check + ptr = QSharedPointer<NoDefaultConstructor2>::create(null, 2); + QCOMPARE(ptr->i, 2); + QCOMPARE(ptr->ptr, (void*)0); + +#ifdef Q_COMPILER_NULLPTR + NoDefaultConstructor2(nullptr, 3); // control check + ptr = QSharedPointer<NoDefaultConstructor2>::create(nullptr, 3); + QCOMPARE(ptr->i, 3); + QCOMPARE(ptr->ptr, (void*)nullptr); +#endif + } + { + NoDefaultConstructorRef1 x(i); // control check + QSharedPointer<NoDefaultConstructorRef1> ptr = QSharedPointer<NoDefaultConstructorRef1>::create(i); + QCOMPARE(ptr->i, i); + QCOMPARE(&ptr->i, &i); + } + { + NoDefaultConstructorRRef1(1); // control check + QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1); + QCOMPARE(ptr->i, 1); + + NoDefaultConstructorRRef1(std::move(i)); // control check + ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i)); + QCOMPARE(ptr->i, i); + } + { + QString text("Hello, World"); + NoDefaultConstructorRef2(text, 1); // control check + QSharedPointer<NoDefaultConstructorRef2> ptr = QSharedPointer<NoDefaultConstructorRef2>::create(text, 1); + QCOMPARE(ptr->str, text); + QCOMPARE(ptr->i, 1); + } + { + QSharedPointer<NoDefaultConstructorConstRef2> ptr; + NoDefaultConstructorConstRef2(QLatin1String("string"), 1); // control check + ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QLatin1String("string"), 1); + QCOMPARE(ptr->str, QString("string")); + QCOMPARE(ptr->i, 1); + + NoDefaultConstructorConstRef2(QByteArray("bytearray")); // control check + ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QByteArray("bytearray")); + QCOMPARE(ptr->str, QString("bytearray")); + QCOMPARE(ptr->i, 42); + } +#endif +} + void tst_QSharedPointer::creatingQObject() { { @@ -1876,7 +1996,7 @@ void tst_QSharedPointer::invalidConstructs() QByteArray body = code.toLatin1(); bool result = (test.*testFunction)(body); - if (qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) { + if (!result || qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) { qDebug("External test output:"); #ifdef Q_CC_MSVC // MSVC prints errors to stdout diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index f75d74c4b0..acdd2a9b64 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1003,10 +1003,12 @@ void tst_QString::sprintf() a.sprintf("%s%n%s", "hello", &n1, "goodbye"); QCOMPARE(n1, 5); QCOMPARE(a, QString("hellogoodbye")); +#ifndef Q_CC_MINGW // does not know %ll qlonglong n2; a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz"); QCOMPARE((int)n2, 6); QCOMPARE(a, QString("foobarwhiz")); +#endif } /* @@ -1425,6 +1427,55 @@ void tst_QString::contains() QVERIFY(a.contains(QRegularExpression("[FG][HI]"))); QVERIFY(a.contains(QRegularExpression("[G][HE]"))); + { + QRegularExpressionMatch match; + QVERIFY(!match.hasMatch()); + + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[G][HE]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[FG]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 15); + QCOMPARE(match.captured(), QString("fGEFG")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 14); + QCOMPARE(match.captured(1), QStringLiteral("GEF")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[F]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QString("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + QVERIFY(!a.contains(QRegularExpression("ZZZ"), &match)); + // doesn't match, but ensure match didn't change + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QStringLiteral("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + // don't crash with a null pointer + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), 0)); + QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0)); + } + CREATE_REF(QLatin1String("FG")); QVERIFY(a.contains(ref)); QVERIFY(a.contains(ref, Qt::CaseInsensitive)); @@ -5187,6 +5238,9 @@ void tst_QString::QCharRefDetaching() const void tst_QString::sprintfZU() const { +#ifdef Q_CC_MINGW + QSKIP("MinGW does not support '%zu'."); +#else { QString string; size_t s = 6; @@ -5215,6 +5269,7 @@ void tst_QString::sprintfZU() const string.sprintf("%zu %s\n", s, "foo"); QCOMPARE(string, QString::fromLatin1("6 foo\n")); } +#endif // !Q_CC_MINGW } void tst_QString::repeatedSignature() const diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index 100409e58b..f8b2437d35 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -22,6 +22,7 @@ SUBDIRS=\ qlocale \ qmap \ qmargins \ + qmessageauthenticationcode \ qpair \ qpoint \ qpointf \ |