diff options
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/global/qhooks/tst_qhooks.cpp | 70 | ||||
-rw-r--r-- | tests/auto/corelib/io/qdir/tst_qdir.cpp | 23 | ||||
-rw-r--r-- | tests/auto/corelib/io/qfile/tst_qfile.cpp | 8 | ||||
-rw-r--r-- | tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp | 15 | ||||
-rw-r--r-- | tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 14 | ||||
-rw-r--r-- | tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp | 20 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 50 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 40 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 114 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qthread/tst_qthread.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qchar/tst_qchar.cpp | 5 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 17 |
13 files changed, 336 insertions, 48 deletions
diff --git a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp index f0685d64c5..5fa7566e86 100644 --- a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp +++ b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp @@ -35,10 +35,18 @@ class tst_QHooks: public QObject Q_OBJECT private slots: + void cleanup(); void testVersion(); void testAddRemoveObject(); + void testChaining(); }; +void tst_QHooks::cleanup() +{ + qtHookData[QHooks::AddQObject] = 0; + qtHookData[QHooks::RemoveQObject] = 0; +} + void tst_QHooks::testVersion() { QVERIFY(qtHookData[QHooks::HookDataVersion] >= 3); @@ -73,5 +81,67 @@ void tst_QHooks::testAddRemoveObject() QCOMPARE(objectCount, 0); } +static QVector<QString> hookOrder; + +static QHooks::AddQObjectCallback existingAddHook = 0; +static QHooks::RemoveQObjectCallback existingRemoveHook = 0; + +static void firstAddHook(QObject *) +{ + hookOrder.append(QLatin1String("firstAddHook")); +} + +static void firstRemoveHook(QObject *) +{ + hookOrder.append(QLatin1String("firstRemoveHook")); +} + +static void secondAddHook(QObject *object) +{ + if (existingAddHook) + existingAddHook(object); + + hookOrder.append(QLatin1String("secondAddHook")); +} + +static void secondRemoveHook(QObject *object) +{ + if (existingRemoveHook) + existingRemoveHook(object); + + hookOrder.append(QLatin1String("secondRemoveHook")); +} + +// Tests that it's possible to "chain" hooks together (i.e. have multiple hooks) +void tst_QHooks::testChaining() +{ + QCOMPARE(qtHookData[QHooks::AddQObject], (quintptr)0); + QCOMPARE(qtHookData[QHooks::RemoveQObject], (quintptr)0); + + // Set the add and remove hooks (could just skip this and go straight to the next step, + // but it's for illustrative purposes). + qtHookData[QHooks::AddQObject] = (quintptr)&firstAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&firstRemoveHook; + + // Store them so that we can call them later. + existingAddHook = reinterpret_cast<QHooks::AddQObjectCallback>(qtHookData[QHooks::AddQObject]); + existingRemoveHook = reinterpret_cast<QHooks::RemoveQObjectCallback>(qtHookData[QHooks::RemoveQObject]); + + // Overide them with hooks that call them first. + qtHookData[QHooks::AddQObject] = (quintptr)&secondAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&secondRemoveHook; + + QObject *obj = new QObject; + QCOMPARE(hookOrder.size(), 2); + QCOMPARE(hookOrder.at(0), QLatin1String("firstAddHook")); + QCOMPARE(hookOrder.at(1), QLatin1String("secondAddHook")); + delete obj; + QCOMPARE(hookOrder.size(), 4); + QCOMPARE(hookOrder.at(2), QLatin1String("firstRemoveHook")); + QCOMPARE(hookOrder.at(3), QLatin1String("secondRemoveHook")); + + hookOrder.clear(); +} + QTEST_APPLESS_MAIN(tst_QHooks) #include "tst_qhooks.moc" diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 294a53645e..b86c6e4dfa 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -58,7 +58,8 @@ #ifdef QT_BUILD_INTERNAL QT_BEGIN_NAMESPACE -extern Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &, bool); +extern Q_AUTOTEST_EXPORT QString + qt_normalizePathSegments(const QString &path, bool allowUncPaths, bool *ok = nullptr); QT_END_NAMESPACE #endif @@ -1149,6 +1150,8 @@ tst_QDir::cleanPath_data() QTest::newRow("data0") << "/Users/sam/troll/qt4.0//.." << "/Users/sam/troll"; QTest::newRow("data1") << "/Users/sam////troll/qt4.0//.." << "/Users/sam/troll"; QTest::newRow("data2") << "/" << "/"; + QTest::newRow("data2-up") << "/path/.." << "/"; + QTest::newRow("data2-above-root") << "/.." << "/.."; QTest::newRow("data3") << QDir::cleanPath("../.") << ".."; QTest::newRow("data4") << QDir::cleanPath("../..") << "../.."; #if defined(Q_OS_WIN) @@ -1178,13 +1181,19 @@ tst_QDir::cleanPath_data() QTest::newRow("data14") << "c://foo" << "c:/foo"; // Drive letters and unc path in one string -#ifndef Q_OS_WINRT -#ifdef Q_OS_WIN +#if defined(Q_OS_WINRT) + const QString root = QDir::rootPath(); // has trailing slash + QTest::newRow("root-up") << (root + "path/..") << root; + QTest::newRow("above-root") << (root + "..") << (root + ".."); +#elif defined(Q_OS_WIN) QTest::newRow("data15") << "//c:/foo" << "//c:/foo"; + QTest::newRow("drive-up") << "A:/path/.." << "A:/"; + QTest::newRow("drive-above-root") << "A:/.." << "A:/.."; + QTest::newRow("unc-server-up") << "//server/path/.." << "//server"; + QTest::newRow("unc-server-above-root") << "//server/.." << "//server/.."; #else QTest::newRow("data15") << "//c:/foo" << "/c:/foo"; -#endif -#endif // !Q_OS_WINRT +#endif // non-windows QTest::newRow("QTBUG-23892_0") << "foo/.." << "."; QTest::newRow("QTBUG-23892_1") << "foo/../" << "."; @@ -2238,6 +2247,10 @@ void tst_QDir::cdBelowRoot_data() const QString systemRoot = QString::fromLocal8Bit(qgetenv("SystemRoot")); QTest::newRow("windows-drive") << systemDrive << systemRoot.mid(3) << QDir::cleanPath(systemRoot); + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + const QString testDirectory = QStringLiteral("testshare"); + QTest::newRow("windows-share") + << uncRoot << testDirectory << QDir::cleanPath(uncRoot + QLatin1Char('/') + testDirectory); #endif // Windows } diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index eeba882c70..2ef4c2c6a1 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -2618,9 +2618,10 @@ void tst_QFile::appendAndRead() // Write blocks and read them back for (int j = 0; j < 18; ++j) { - writeFile.write(QByteArray(1 << j, '@')); + const int size = 1 << j; + writeFile.write(QByteArray(size, '@')); writeFile.flush(); - QCOMPARE(readFile.read(1 << j).size(), 1 << j); + QCOMPARE(readFile.read(size).size(), size); } readFile.close(); @@ -2658,7 +2659,8 @@ void tst_QFile::handle() QVERIFY(fd > 2); QCOMPARE(int(file.handle()), fd); char c = '\0'; - QT_READ(int(file.handle()), &c, 1); + const auto readResult = QT_READ(int(file.handle()), &c, 1); + QCOMPARE(readResult, static_cast<decltype(readResult)>(1)); QCOMPARE(c, '/'); // test if the QFile and the handle remain in sync diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 561ab193c6..7fdd00876f 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -55,6 +55,7 @@ private slots: void searchPath(); void doubleSlashInRoot(); void setLocale(); + void lastModified(); private: const QString m_runtimeResourceRcc; @@ -489,6 +490,20 @@ void tst_QResourceEngine::setLocale() QLocale::setDefault(QLocale::system()); } +void tst_QResourceEngine::lastModified() +{ + { + QFileInfo fi(":/"); + QVERIFY(fi.exists()); + QVERIFY2(!fi.lastModified().isValid(), qPrintable(fi.lastModified().toString())); + } + { + QFileInfo fi(":/search_file.txt"); + QVERIFY(fi.exists()); + QVERIFY(fi.lastModified().isValid()); + } +} + QTEST_MAIN(tst_QResourceEngine) #include "tst_qresourceengine.moc" diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 0b536f26de..0a00e00d83 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -33,6 +33,9 @@ #include <qfileinfo.h> #include <qsysinfo.h> #include <qregexp.h> +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) +# include <qt_windows.h> +#endif #ifdef Q_OS_UNIX #include <unistd.h> @@ -126,6 +129,16 @@ static const char * const enumNames[MaxStandardLocation + 1 - int(QStandardPaths void tst_qstandardpaths::initTestCase() { +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) + // Disable WOW64 redirection, see testFindExecutable() + if (QSysInfo::buildCpuArchitecture() != QSysInfo::currentCpuArchitecture()) { + void *oldMode; + const bool disabledDisableWow64FsRedirection = Wow64DisableWow64FsRedirection(&oldMode) == TRUE; + if (!disabledDisableWow64FsRedirection) + qErrnoWarning("Wow64DisableWow64FsRedirection() failed"); + QVERIFY(disabledDisableWow64FsRedirection); + } +#endif // Q_OS_WIN && !Q_OS_WINRT && !Q_OS_WINCE QVERIFY2(m_localConfigTempDir.isValid(), qPrintable(m_localConfigTempDir.errorString())); QVERIFY2(m_globalConfigTempDir.isValid(), qPrintable(m_globalConfigTempDir.errorString())); QVERIFY2(m_localAppTempDir.isValid(), qPrintable(m_localAppTempDir.errorString())); @@ -375,6 +388,7 @@ void tst_qstandardpaths::testFindExecutable_data() if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8) { // The logo executable on Windows 8 is perfectly suited for testing that the // suffix mechanism is not thrown off by dots in the name. + // Note: Requires disabling WOW64 redirection, see initTestCase() const QString logo = QLatin1String("microsoft.windows.softwarelogo.showdesktop"); const QString logoPath = cmdFi.absolutePath() + QLatin1Char('/') + logo + QLatin1String(".exe"); QTest::newRow("win8-logo") diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 9533989b9d..7f29e2a7d7 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -2023,13 +2023,13 @@ void tst_QTextStream::generateNaturalNumbersData(bool for_QString) QTest::newRow("2147483648") << QByteArray("2147483648") << Q_UINT64_C(2147483648); QTest::newRow("-2147483646") << QByteArray("-2147483646") << qulonglong(-2147483646); QTest::newRow("-2147483647") << QByteArray("-2147483647") << qulonglong(-2147483647); - QTest::newRow("-2147483648") << QByteArray("-2147483648") << Q_UINT64_C(-2147483648); + QTest::newRow("-2147483648") << QByteArray("-2147483648") << quint64(-2147483648LL); QTest::newRow("4294967296") << QByteArray("4294967296") << Q_UINT64_C(4294967296); QTest::newRow("4294967297") << QByteArray("4294967297") << Q_UINT64_C(4294967297); QTest::newRow("4294967298") << QByteArray("4294967298") << Q_UINT64_C(4294967298); - QTest::newRow("-4294967296") << QByteArray("-4294967296") << Q_UINT64_C(-4294967296); - QTest::newRow("-4294967297") << QByteArray("-4294967297") << Q_UINT64_C(-4294967297); - QTest::newRow("-4294967298") << QByteArray("-4294967298") << Q_UINT64_C(-4294967298); + QTest::newRow("-4294967296") << QByteArray("-4294967296") << quint64(-4294967296); + QTest::newRow("-4294967297") << QByteArray("-4294967297") << quint64(-4294967297); + QTest::newRow("-4294967298") << QByteArray("-4294967298") << quint64(-4294967298); QTest::newRow("9223372036854775807") << QByteArray("9223372036854775807") << Q_UINT64_C(9223372036854775807); QTest::newRow("9223372036854775808") << QByteArray("9223372036854775808") << Q_UINT64_C(9223372036854775808); QTest::newRow("9223372036854775809") << QByteArray("9223372036854775809") << Q_UINT64_C(9223372036854775809); @@ -2286,7 +2286,7 @@ void tst_QTextStream::signedShort_write_operator_ToDevice_data() QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("-1") << quint64(-1) << QByteArray("-1") << QByteArray("-1"); QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("-32768") << QByteArray("-32,768"); QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("-32767") << QByteArray("-32,767"); @@ -2306,7 +2306,7 @@ void tst_QTextStream::unsignedShort_write_operator_ToDevice_data() QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("65535") << QByteArray("65,535"); + QTest::newRow("-1") << quint64(-1) << QByteArray("65535") << QByteArray("65,535"); QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); @@ -2326,7 +2326,7 @@ void tst_QTextStream::signedInt_write_operator_ToDevice_data() QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("-1") << quint64(-1) << QByteArray("-1") << QByteArray("-1"); QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); @@ -2352,7 +2352,7 @@ void tst_QTextStream::unsignedInt_write_operator_ToDevice_data() QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("4294967295") << QByteArray("4,294,967,295"); + QTest::newRow("-1") << quint64(-1) << QByteArray("4294967295") << QByteArray("4,294,967,295"); QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); @@ -2378,7 +2378,7 @@ void tst_QTextStream::qlonglong_write_operator_ToDevice_data() QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("-1") << QByteArray("-1"); + QTest::newRow("-1") << quint64(-1) << QByteArray("-1") << QByteArray("-1"); QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); @@ -2408,7 +2408,7 @@ void tst_QTextStream::qulonglong_write_operator_ToDevice_data() QTest::newRow("0") << Q_UINT64_C(0) << QByteArray("0") << QByteArray("0"); QTest::newRow("1") << Q_UINT64_C(1) << QByteArray("1") << QByteArray("1"); - QTest::newRow("-1") << Q_UINT64_C(-1) << QByteArray("18446744073709551615") << QByteArray("18,446,744,073,709,551,615"); + QTest::newRow("-1") << quint64(-1) << QByteArray("18446744073709551615") << QByteArray("18,446,744,073,709,551,615"); QTest::newRow("32767") << Q_UINT64_C(32767) << QByteArray("32767") << QByteArray("32,767"); QTest::newRow("32768") << Q_UINT64_C(32768) << QByteArray("32768") << QByteArray("32,768"); QTest::newRow("32769") << Q_UINT64_C(32769) << QByteArray("32769") << QByteArray("32,769"); diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index f589fe1d6d..a4461a12d3 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -177,6 +177,8 @@ private slots: void streaming(); void detach(); void testThreading(); + void matches_data(); + void matches(); private: void testThreadingHelper(); @@ -4020,6 +4022,54 @@ void tst_QUrl::testThreading() delete s_urlStorage; } +void tst_QUrl::matches_data() +{ + QTest::addColumn<QString>("urlStrOne"); + QTest::addColumn<QString>("urlStrTwo"); + QTest::addColumn<uint>("options"); + QTest::addColumn<bool>("matches"); + + QTest::newRow("matchingString-none") << "http://www.website.com/directory/?#ref" + << "http://www.website.com/directory/?#ref" + << uint(QUrl::None) << true; + QTest::newRow("nonMatchingString-none") << "http://www.website.com/directory/?#ref" + << "http://www.nomatch.com/directory/?#ref" + << uint(QUrl::None) << false; + QTest::newRow("matchingHost-removePath") << "http://www.website.com/directory" + << "http://www.website.com/differentdir" + << uint(QUrl::RemovePath) << true; + QTest::newRow("nonMatchingHost-removePath") << "http://www.website.com/directory" + << "http://www.different.com/differentdir" + << uint(QUrl::RemovePath) << false; + QTest::newRow("matchingHost-removePathAuthority") << "http://user:pass@www.website.com/directory" + << "http://www.website.com/differentdir" + << uint(QUrl::RemovePath | QUrl::RemoveAuthority) + << true; + QTest::newRow("nonMatchingHost-removePathAuthority") << "http://user:pass@www.website.com/directory" + << "http://user:pass@www.different.com/differentdir" + << uint(QUrl::RemovePath | QUrl::RemoveAuthority) + << true; + QTest::newRow("matchingHostAuthority-removePathAuthority") + << "http://user:pass@www.website.com/directory" << "http://www.website.com/differentdir" + << uint(QUrl::RemovePath | QUrl::RemoveAuthority) << true; + QTest::newRow("nonMatchingAuthority-removePathAuthority") + << "http://user:pass@www.website.com/directory" + << "http://otheruser:otherpass@www.website.com/directory" + << uint(QUrl::RemovePath | QUrl::RemoveAuthority) << true; +} + +void tst_QUrl::matches() +{ + QFETCH(QString, urlStrOne); + QFETCH(QString, urlStrTwo); + QFETCH(uint, options); + QFETCH(bool, matches); + + QUrl urlOne(urlStrOne); + QUrl urlTwo(urlStrTwo); + QCOMPARE(urlOne.matches(urlTwo, QUrl::FormattingOptions(options)), matches); +} + QTEST_MAIN(tst_QUrl) #include "tst_qurl.moc" diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index fea185c48f..5eea858107 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6967,10 +6967,10 @@ void tst_QObject::checkArgumentsForNarrowing() QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, signed char>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, short>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, int>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned short>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned int>::value)); @@ -6978,23 +6978,23 @@ void tst_QObject::checkArgumentsForNarrowing() QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, short>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, int>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned int>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, int>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, long long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<unsigned int, long>::value), sizeof(int) >= sizeof(long)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long long>::value), sizeof(long) >= sizeof(long long)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, long long>::value)); @@ -7204,28 +7204,28 @@ void tst_QObject::checkArgumentsForNarrowing() QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, signed char>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, short>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, int>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, signed char>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, short>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, int>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, signed char>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, short>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, int>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long>::value), sizeof(ScopedEnumBackedByUInt) >= sizeof(long)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long long>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, signed char>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, short>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, int>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long>::value)); - QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long long>::value), sizeof(ScopedEnumBackedByULong) >= sizeof(long long)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, signed char>::value)); QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, short>::value)); diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index b24ecfcd43..bf778e9fd1 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -44,8 +44,19 @@ class tst_QMutex : public QObject { Q_OBJECT +public: + enum class TimeUnit { + Nanoseconds, + Microseconds, + Milliseconds, + Seconds, + }; + Q_ENUM(TimeUnit); + private slots: void initTestCase(); + void convertToMilliseconds_data(); + void convertToMilliseconds(); void tryLock_non_recursive(); void try_lock_for_non_recursive(); void try_lock_until_non_recursive(); @@ -122,6 +133,109 @@ void tst_QMutex::initTestCase() initializeSystemTimersResolution(); } +void tst_QMutex::convertToMilliseconds_data() +{ + QTest::addColumn<TimeUnit>("unit"); + QTest::addColumn<double>("doubleValue"); + QTest::addColumn<qint64>("intValue"); + QTest::addColumn<qint64>("expected"); + + + auto add = [](TimeUnit unit, double d, long long i, qint64 expected) { + const QScopedArrayPointer<char> enumName(QTest::toString(unit)); + QTest::newRow(qPrintable(QString::asprintf("%s:%f:%lld", enumName.data(), d, i))) + << unit << d << qint64(i) << expected; + }; + + auto forAllUnitsAdd = [=](double d, long long i, qint64 expected) { + for (auto unit : {TimeUnit::Nanoseconds, TimeUnit::Microseconds, TimeUnit::Milliseconds, TimeUnit::Seconds}) + add(unit, d, i, expected); + }; + + forAllUnitsAdd(-0.5, -1, 0); // all negative values result in 0 + + forAllUnitsAdd(0, 0, 0); + + add(TimeUnit::Nanoseconds, 1, 1, 1); + add(TimeUnit::Nanoseconds, 1000 * 1000, 1000 * 1000, 1); + add(TimeUnit::Nanoseconds, 1000 * 1000 + 0.5, 1000 * 1000 + 1, 2); + + add(TimeUnit::Microseconds, 1, 1, 1); + add(TimeUnit::Microseconds, 1000, 1000, 1); + add(TimeUnit::Microseconds, 1000 + 0.5, 1000 + 1, 2); + + add(TimeUnit::Milliseconds, 1, 1, 1); + add(TimeUnit::Milliseconds, 1.5, 2, 2); + + add(TimeUnit::Seconds, 0.9991, 1, 1000); + + // + // overflowing int results in INT_MAX (equivalent to a spurious wakeup after ~24 days); check it: + // + + // spot on: + add(TimeUnit::Nanoseconds, INT_MAX * 1000. * 1000, INT_MAX * Q_INT64_C(1000) * 1000, INT_MAX); + add(TimeUnit::Microseconds, INT_MAX * 1000., INT_MAX * Q_INT64_C(1000), INT_MAX); + add(TimeUnit::Milliseconds, INT_MAX, INT_MAX, INT_MAX); + + // minimally above: + add(TimeUnit::Nanoseconds, INT_MAX * 1000. * 1000 + 1, INT_MAX * Q_INT64_C(1000) * 1000 + 1, INT_MAX); + add(TimeUnit::Microseconds, INT_MAX * 1000. + 1, INT_MAX * Q_INT64_C(1000) + 1, INT_MAX); + add(TimeUnit::Milliseconds, INT_MAX + 1., INT_MAX + Q_INT64_C(1), INT_MAX); + add(TimeUnit::Seconds, INT_MAX / 1000. + 1, INT_MAX / 1000 + 1, INT_MAX); + + // minimally below: + add(TimeUnit::Nanoseconds, INT_MAX * 1000. * 1000 - 1, INT_MAX * Q_INT64_C(1000) * 1000 - 1, INT_MAX); + add(TimeUnit::Microseconds, INT_MAX * 1000. - 1, INT_MAX * Q_INT64_C(1000) - 1, INT_MAX); + add(TimeUnit::Milliseconds, INT_MAX - 0.1, INT_MAX , INT_MAX); + +} + +void tst_QMutex::convertToMilliseconds() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#else + QFETCH(TimeUnit, unit); + QFETCH(double, doubleValue); + QFETCH(qint64, intValue); + QFETCH(qint64, expected); + + Q_CONSTEXPR qint64 maxShort = std::numeric_limits<short>::max(); + Q_CONSTEXPR qint64 maxInt = std::numeric_limits<int>::max(); + Q_CONSTEXPR qint64 maxUInt = std::numeric_limits<uint>::max(); + + switch (unit) { +#define CASE(Unit, Period) \ + case TimeUnit::Unit: \ + DO(double, Period, doubleValue); \ + if (intValue < maxShort) \ + DO(short, Period, short(intValue)); \ + if (intValue < maxInt) \ + DO(int, Period, int(intValue)); \ + DO(qint64, Period, intValue); \ + if (intValue >= 0) { \ + if (intValue < maxUInt) \ + DO(uint, Period, uint(intValue)); \ + DO(quint64, Period, quint64(intValue)); \ + } \ + break +#define DO(Rep, Period, val) \ + do { \ + const std::chrono::duration<Rep, Period> wait((val)); \ + QCOMPARE(QMutex::convertToMilliseconds(wait), expected); \ + } while (0) + + CASE(Nanoseconds, std::nano); + CASE(Microseconds, std::micro); + CASE(Milliseconds, std::milli); + CASE(Seconds, std::ratio<1>); +#undef DO +#undef CASE + } +#endif +} + void tst_QMutex::tryLock_non_recursive() { class Thread : public QThread diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index 06b27f79cd..0efbc5d01e 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -1059,8 +1059,8 @@ void tst_QThread::wait2() thread.start(); timer.start(); QVERIFY(!thread.wait(Waiting_Thread::WaitTime)); - qint64 elapsed = timer.elapsed(); // On Windows, we sometimes get (WaitTime - 1). - QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 1, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); + qint64 elapsed = timer.elapsed(); // On Windows, we sometimes get (WaitTime - 9). + QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 10, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); timer.start(); thread.cond1.wakeOne(); diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 65887e50d3..ba2adddca0 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -801,8 +801,8 @@ void tst_QArrayData::alignment_data() { QTest::addColumn<size_t>("alignment"); - for (int i = 1; i < 10; ++i) { - size_t alignment = 1u << i; + for (size_t i = 1; i < 10; ++i) { + size_t alignment = size_t(1u) << i; QTest::newRow(qPrintable(QString::number(alignment))) << alignment; } } diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 92585fd471..fb436b67d6 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -72,6 +72,9 @@ private slots: void unicodeVersion(); }; +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + void tst_QChar::operator_eqeq_int() { { @@ -96,6 +99,8 @@ void tst_QChar::operator_eqeq_int() } } +QT_WARNING_POP + void tst_QChar::operators_data() { QTest::addColumn<QChar>("lhs"); diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index a0a872710c..414ba2d8cf 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1255,6 +1255,11 @@ void tst_QString::fill() QCOMPARE(f, QLatin1String("FFF")); } +static inline const void *ptrValue(quintptr v) +{ + return reinterpret_cast<const void *>(v); +} + void tst_QString::sprintf() { QString a; @@ -1266,21 +1271,21 @@ void tst_QString::sprintf() QCOMPARE(a.sprintf("X%9iY", 50000 ), QLatin1String("X 50000Y")); QCOMPARE(a.sprintf("X%-9sY","hello"), QLatin1String("Xhello Y")); QCOMPARE(a.sprintf("X%-9iY", 50000 ), QLatin1String("X50000 Y")); - QCOMPARE(a.sprintf("%lf", 1.23), QString("1.230000")); - QCOMPARE(a.sprintf("%lf", 1.23456789), QString("1.234568")); - QCOMPARE(a.sprintf("%p", (void *)0xbfffd350), QString("0xbfffd350")); - QCOMPARE(a.sprintf("%p", (void *)0), QString("0x0")); + QCOMPARE(a.sprintf("%lf", 1.23), QLatin1String("1.230000")); + QCOMPARE(a.sprintf("%lf", 1.23456789), QLatin1String("1.234568")); + QCOMPARE(a.sprintf("%p", ptrValue(0xbfffd350)), QLatin1String("0xbfffd350")); + QCOMPARE(a.sprintf("%p", ptrValue(0)), QLatin1String("0x0")); int i = 6; long l = -2; float f = 4.023f; QString S1; S1.sprintf("%d %ld %f",i,l,f); - QCOMPARE(S1,QString("6 -2 4.023000")); + QCOMPARE(S1, QLatin1String("6 -2 4.023000")); double d = -514.25683; S1.sprintf("%f",d); - QCOMPARE(S1, QString("-514.256830")); + QCOMPARE(S1, QLatin1String("-514.256830")); } void tst_QString::sprintfS() |