diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-08-31 01:01:42 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-08-31 01:01:42 +0200 |
commit | a2a4c3a5ff50dc68f6931917c8f017f9b4d69b6b (patch) | |
tree | 5888fed53d5b747e122ade9517ce750ffba23eca /tests | |
parent | a5ba29b79d4793a3c18aaf64f24582d93c0fe4e8 (diff) | |
parent | 65dfc485adc1c5de4840f217c47c6ad79d26ae82 (diff) |
Merge remote-tracking branch 'origin/5.14' into dev
Change-Id: I525112b5afbbe8f7fbb54da527bddb94a0c2c242
Diffstat (limited to 'tests')
4 files changed, 406 insertions, 250 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 6fcfe87c83..921847a087 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -236,6 +236,13 @@ private slots: void isSymLink_data(); void isSymLink(); + + void isSymbolicLink_data(); + void isSymbolicLink(); + + void isShortcut_data(); + void isShortcut(); + void link_data(); void link(); @@ -279,9 +286,6 @@ private slots: void invalidState(); void nonExistingFile(); - void type_data(); - void type(); - private: const QString m_currentDir; QString m_sourceFile; @@ -1342,7 +1346,92 @@ void tst_QFileInfo::isSymLink() #endif } -Q_DECLARE_METATYPE(QFileInfo::FileType) +void tst_QFileInfo::isShortcut_data() +{ + QFile::remove("link.lnk"); + QFile::remove("symlink.lnk"); + QFile::remove("link"); + QFile::remove("symlink"); + QFile::remove("directory.lnk"); + QFile::remove("directory"); + + QTest::addColumn<QString>("path"); + QTest::addColumn<bool>("isShortcut"); + + QFile regularFile(m_sourceFile); + QTest::newRow("regular") + << regularFile.fileName() << false; + QTest::newRow("directory") + << QDir::currentPath() << false; +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + // windows shortcuts + QVERIFY(regularFile.link("link.lnk")); + QTest::newRow("shortcut") + << "link.lnk" << true; + QVERIFY(regularFile.link("link")); + QTest::newRow("invalid-shortcut") + << "link" << false; + QVERIFY(QFile::link(QDir::currentPath(), "directory.lnk")); + QTest::newRow("directory-shortcut") + << "directory.lnk" << true; +#endif +} + +void tst_QFileInfo::isShortcut() +{ + QFETCH(QString, path); + QFETCH(bool, isShortcut); + + QFileInfo fi(path); + QCOMPARE(fi.isShortcut(), isShortcut); +} + +void tst_QFileInfo::isSymbolicLink_data() +{ + QTest::addColumn<QString>("path"); + QTest::addColumn<bool>("isSymbolicLink"); + + QFile regularFile(m_sourceFile); + QTest::newRow("regular") + << regularFile.fileName() << false; + QTest::newRow("directory") + << QDir::currentPath() << false; + +#ifndef Q_NO_SYMLINKS +#if defined(Q_OS_WIN) +#if !defined(Q_OS_WINRT) + QString errorMessage; + const DWORD creationResult = createSymbolicLink("symlink", m_sourceFile, &errorMessage); + if (creationResult == ERROR_PRIVILEGE_NOT_HELD) { + QWARN(msgInsufficientPrivileges(errorMessage)); + } else { + QVERIFY2(creationResult == ERROR_SUCCESS, qPrintable(errorMessage)); + QTest::newRow("NTFS-symlink") + << "symlink" << true; + } +#endif // !Q_OS_WINRT +#else // Unix: + QVERIFY(regularFile.link("symlink.lnk")); + QTest::newRow("symlink.lnk") + << "symlink.lnk" << true; + QVERIFY(regularFile.link("symlink")); + QTest::newRow("symlink") + << "symlink" << true; + QVERIFY(QFile::link(QDir::currentPath(), "directory")); + QTest::newRow("directory-symlink") + << "directory" << true; +#endif +#endif // !Q_NO_SYMLINKS +} + +void tst_QFileInfo::isSymbolicLink() +{ + QFETCH(QString, path); + QFETCH(bool, isSymbolicLink); + + QFileInfo fi(path); + QCOMPARE(fi.isSymbolicLink(), isSymbolicLink); +} void tst_QFileInfo::link_data() { @@ -1354,23 +1443,24 @@ void tst_QFileInfo::link_data() QFile::remove("relative/link"); QTest::addColumn<QString>("path"); - QTest::addColumn<QFileInfo::FileType>("linkType"); + QTest::addColumn<bool>("isShortcut"); + QTest::addColumn<bool>("isSymbolicLink"); QTest::addColumn<QString>("linkTarget"); QFile file1(m_sourceFile); QFile file2("dummyfile"); file2.open(QIODevice::WriteOnly); - QTest::newRow("existent file") << m_sourceFile << QFileInfo::Unknown << ""; + QTest::newRow("existent file") << m_sourceFile << false << false << ""; #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // windows shortcuts QVERIFY(file1.link("link.lnk")); QTest::newRow("link.lnk") - << "link.lnk" << QFileInfo::Shortcut << QFileInfo(m_sourceFile).absoluteFilePath(); + << "link.lnk" << true << false << QFileInfo(m_sourceFile).absoluteFilePath(); QVERIFY(file2.link("brokenlink.lnk")); QTest::newRow("broken link.lnk") - << "brokenlink.lnk" << QFileInfo::Shortcut << QFileInfo("dummyfile").absoluteFilePath(); + << "brokenlink.lnk" << true << false << QFileInfo("dummyfile").absoluteFilePath(); #endif #ifndef Q_NO_SYMLINKS @@ -1383,7 +1473,7 @@ void tst_QFileInfo::link_data() } else { QVERIFY2(creationResult == ERROR_SUCCESS, qPrintable(errorMessage)); QTest::newRow("link") - << "link" << QFileInfo::SymbolicLink << QFileInfo(m_sourceFile).absoluteFilePath(); + << "link" << false << true << QFileInfo(m_sourceFile).absoluteFilePath(); } creationResult = createSymbolicLink("brokenlink", "dummyfile", &errorMessage); @@ -1392,22 +1482,22 @@ void tst_QFileInfo::link_data() } else { QVERIFY2(creationResult == ERROR_SUCCESS, qPrintable(errorMessage)); QTest::newRow("broken link") - << "brokenlink" << QFileInfo::SymbolicLink << QFileInfo("dummyfile").absoluteFilePath(); + << "brokenlink" << false << true << QFileInfo("dummyfile").absoluteFilePath(); } #endif // !Q_OS_WINRT #else // Unix: QVERIFY(file1.link("link")); QTest::newRow("link") - << "link" << QFileInfo::SymbolicLink << QFileInfo(m_sourceFile).absoluteFilePath(); + << "link" << false << true << QFileInfo(m_sourceFile).absoluteFilePath(); QVERIFY(file2.link("brokenlink")); QTest::newRow("broken link") - << "brokenlink" << QFileInfo::SymbolicLink << QFileInfo("dummyfile").absoluteFilePath(); + << "brokenlink" << false << true << QFileInfo("dummyfile").absoluteFilePath(); QDir::current().mkdir("relative"); QFile::link("../dummyfile", "relative/link"); QTest::newRow("relative link") - << "relative/link" << QFileInfo::SymbolicLink << QFileInfo("dummyfile").absoluteFilePath(); + << "relative/link" << false << true << QFileInfo("dummyfile").absoluteFilePath(); #endif #endif // !Q_NO_SYMLINKS file2.remove(); @@ -1416,11 +1506,13 @@ void tst_QFileInfo::link_data() void tst_QFileInfo::link() { QFETCH(QString, path); - QFETCH(QFileInfo::FileType, linkType); + QFETCH(bool, isShortcut); + QFETCH(bool, isSymbolicLink); QFETCH(QString, linkTarget); QFileInfo fi(path); - QCOMPARE(fi.type() & QFileInfo::LinkTypeMask, linkType); + QCOMPARE(fi.isShortcut(), isShortcut); + QCOMPARE(fi.isSymbolicLink(), isSymbolicLink); QCOMPARE(fi.symLinkTarget(), linkTarget); } @@ -2179,73 +2271,6 @@ void tst_QFileInfo::nonExistingFile() stateCheck(info, dirname, filename); } -Q_DECLARE_METATYPE(QFileInfo::FileTypes) - -void tst_QFileInfo::type_data() -{ - QFile::remove("link.lnk"); - QFile::remove("symlink.lnk"); - QFile::remove("link"); - QFile::remove("symlink"); - QFile::remove("directory.lnk"); - QFile::remove("directory"); - - QTest::addColumn<QString>("path"); - QTest::addColumn<QFileInfo::FileTypes>("type"); - - QFile regularFile(m_sourceFile); - QTest::newRow("regular") - << regularFile.fileName() << QFileInfo::FileTypes(QFileInfo::Regular); - QTest::newRow("directory") - << QDir::currentPath() << QFileInfo::FileTypes(QFileInfo::Directory); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) - // windows shortcuts - QVERIFY(regularFile.link("link.lnk")); - QTest::newRow("shortcut") - << "link.lnk" << QFileInfo::FileTypes(QFileInfo::Shortcut | QFileInfo::Regular); - QVERIFY(regularFile.link("link")); - QTest::newRow("invalid-shortcut") - << "link" << QFileInfo::FileTypes(QFileInfo::Regular); - QVERIFY(QFile::link(QDir::currentPath(), "directory.lnk")); - QTest::newRow("directory-shortcut") - << "directory.lnk" << QFileInfo::FileTypes(QFileInfo::Shortcut | QFileInfo::Directory); -#endif - -#ifndef Q_NO_SYMLINKS -#if defined(Q_OS_WIN) -#if !defined(Q_OS_WINRT) - QString errorMessage; - const DWORD creationResult = createSymbolicLink("symlink", m_sourceFile, &errorMessage); - if (creationResult == ERROR_PRIVILEGE_NOT_HELD) { - QWARN(msgInsufficientPrivileges(errorMessage)); - } else { - QVERIFY2(creationResult == ERROR_SUCCESS, qPrintable(errorMessage)); - QTest::newRow("NTFS-symlink") - << "symlink" << QFileInfo::FileTypes(QFileInfo::SymbolicLink | QFileInfo::Regular); - } -#endif // !Q_OS_WINRT -#else // Unix: - QVERIFY(regularFile.link("symlink.lnk")); - QTest::newRow("symlink.lnk") - << "symlink.lnk" << QFileInfo::FileTypes(QFileInfo::SymbolicLink | QFileInfo::Regular); - QVERIFY(regularFile.link("symlink")); - QTest::newRow("symlink") - << "symlink" << QFileInfo::FileTypes(QFileInfo::SymbolicLink | QFileInfo::Regular); - QVERIFY(QFile::link(QDir::currentPath(), "directory")); - QTest::newRow("directory-symlink") - << "directory" << QFileInfo::FileTypes(QFileInfo::SymbolicLink | QFileInfo::Directory); -#endif -#endif // !Q_NO_SYMLINKS -} - -void tst_QFileInfo::type() -{ - QFETCH(QString, path); - QFETCH(QFileInfo::FileTypes, type); - - QFileInfo info(path); - QCOMPARE(info.type(), type); -} QTEST_MAIN(tst_QFileInfo) #include "tst_qfileinfo.moc" diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index 810f081b73..26b4b7d020 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -348,8 +348,7 @@ static QLatin1String sectionToName(const QDateTimeEdit::Section section) } } -static QDate stepDate(const QDate& startDate, const QDateTimeEdit::Section section, - const int steps) +static QDate stepDate(QDate startDate, const QDateTimeEdit::Section section, const int steps) { switch (section) { case QDateTimeEdit::DaySection: @@ -364,8 +363,7 @@ static QDate stepDate(const QDate& startDate, const QDateTimeEdit::Section secti } } -static QTime stepTime(const QTime& startTime, const QDateTimeEdit::Section section, - const int steps) +static QTime stepTime(QTime startTime, const QDateTimeEdit::Section section, const int steps) { switch (section) { case QDateTimeEdit::SecondSection: diff --git a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp index 399ac44065..10c013c080 100644 --- a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp +++ b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp @@ -26,27 +26,187 @@ ** ****************************************************************************/ -#include <QDateTime> +#include <QDate> #include <QTest> +#include <QVector> class tst_QDate : public QObject { Q_OBJECT + enum : qint64 + { + JULIAN_DAY_2010 = 2455198, + JULIAN_DAY_2011 = 2455563, + JULIAN_DAY_2020 = 2458850, + }; + + static QVector<QDate> daily(qint64 start, qint64 end); + static QVector<QDate> yearly(qint32 first, qint32 last); + private Q_SLOTS: - void monthLengths(); + void create(); + void year(); + void month(); + void day(); + void dayOfWeek(); + void dayOfYear(); + void monthLengths(); // isValid() and daysInMonth() + void daysInYear(); + void isLeapYear(); + void getSetDate(); + void addDays(); + void addMonths(); + void addYears(); }; +QVector<QDate> tst_QDate::daily(qint64 start, qint64 end) +{ + QVector<QDate> list; + list.reserve(end - start); + for (qint64 jd = start; jd < end; ++jd) + list.append(QDate::fromJulianDay(jd)); + return list; +} + +QVector<QDate> tst_QDate::yearly(qint32 first, qint32 last) +{ + QVector<QDate> list; + list.reserve(last + 1 - first); + for (qint32 year = first; year <= last; ++year) + list.append(QDate(year, 3, 21)); + return list; +} + +void tst_QDate::create() +{ + QDate test; + QBENCHMARK { + for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) + test = QDate::fromJulianDay(jd); + } + Q_UNUSED(test); +} + +void tst_QDate::year() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDate &test : list) + test.year(); + } +} + +void tst_QDate::month() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDate &test : list) + test.month(); + } +} + +void tst_QDate::day() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDate &test : list) + test.day(); + } +} + +void tst_QDate::dayOfWeek() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDate &test : list) + test.dayOfWeek(); + } +} + +void tst_QDate::dayOfYear() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDate &test : list) + test.dayOfYear(); + } +} + void tst_QDate::monthLengths() { + bool check = true; QBENCHMARK { for (int year = 1900; year <= 2100; year++) { - bool check = true; for (int month = 1; month <= 12; month++) - check &= QDate::isValid(year, month, QDate(year, month, 1).daysInMonth()); - Q_UNUSED(check); + check = QDate::isValid(year, month, QDate(year, month, 1).daysInMonth()); + } + } + Q_UNUSED(check); +} + +void tst_QDate::daysInYear() +{ + const auto list = yearly(1601, 2401); + QBENCHMARK { + for (const QDate date : list) + date.daysInYear(); + } +} + +void tst_QDate::isLeapYear() +{ + QBENCHMARK { + for (qint32 year = 1601; year <= 2401; year++) + QDate::isLeapYear(year); + } +} + +void tst_QDate::getSetDate() +{ + QDate store; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const auto test : list) { + int year, month, day; + test.getDate(&year, &month, &day); + store.setDate(year, month, day); } } + Q_UNUSED(store); +} + +void tst_QDate::addDays() +{ + QDate store; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const auto test : list) + store = test.addDays(17); + } + Q_UNUSED(store); +} + +void tst_QDate::addMonths() +{ + QDate store; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const auto test : list) + store = test.addMonths(17); + } + Q_UNUSED(store); +} + +void tst_QDate::addYears() +{ + QDate store; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const auto test : list) + store = test.addYears(17); + } + Q_UNUSED(store); } QTEST_MAIN(tst_QDate) diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp index b693400376..740e08cc46 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp @@ -29,6 +29,7 @@ #include <QDateTime> #include <QTimeZone> #include <QTest> +#include <QVector> #include <qdebug.h> class tst_QDateTime : public QObject @@ -41,6 +42,7 @@ class tst_QDateTime : public QObject MSECS_PER_DAY = 86400000, JULIAN_DAY_1950 = 2433283, JULIAN_DAY_1960 = 2436935, + JULIAN_DAY_1970 = 2440588, // Epoch JULIAN_DAY_2010 = 2455198, JULIAN_DAY_2011 = 2455563, JULIAN_DAY_2020 = 2458850, @@ -48,6 +50,9 @@ class tst_QDateTime : public QObject JULIAN_DAY_2060 = 2473460 }; + static QVector<QDateTime> daily(qint64 start, qint64 end); + static QVector<QDateTime> norse(qint64 start, qint64 end); + private Q_SLOTS: void create(); void isNull(); @@ -97,6 +102,25 @@ private Q_SLOTS: void fromMSecsSinceEpochTz(); }; +QVector<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end) +{ + QVector<QDateTime> list; + list.reserve(end - start); + for (int jd = start; jd < end; ++jd) + list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + return list; +} + +QVector<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end) +{ + const QTimeZone cet("Europe/Oslo"); + QVector<QDateTime> list; + list.reserve(end - start); + for (int jd = start; jd < end; ++jd) + list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + return list; +} + void tst_QDateTime::create() { QBENCHMARK { @@ -109,339 +133,286 @@ void tst_QDateTime::create() void tst_QDateTime::isNull() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.isNull(); } } void tst_QDateTime::isValid() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.isValid(); } } void tst_QDateTime::date() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.date(); } } void tst_QDateTime::time() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.time(); } } void tst_QDateTime::timeSpec() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.timeSpec(); } } void tst_QDateTime::offsetFromUtc() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.offsetFromUtc(); } } void tst_QDateTime::timeZoneAbbreviation() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.timeZoneAbbreviation(); } } void tst_QDateTime::toMSecsSinceEpoch() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } void tst_QDateTime::toMSecsSinceEpoch1950() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_1950; jd < JULIAN_DAY_1960; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } void tst_QDateTime::toMSecsSinceEpoch2050() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2050; jd < JULIAN_DAY_2060; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } void tst_QDateTime::toMSecsSinceEpochTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + qint64 result; + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) - qint64 result = test.toMSecsSinceEpoch(); + for (const QDateTime &test : list) + result = test.toMSecsSinceEpoch(); } + Q_UNUSED(result); } void tst_QDateTime::toMSecsSinceEpoch1950Tz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_1950; jd < JULIAN_DAY_1960; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + qint64 result; + const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); QBENCHMARK { - foreach (const QDateTime &test, list) - qint64 result = test.toMSecsSinceEpoch(); + for (const QDateTime &test : list) + result = test.toMSecsSinceEpoch(); } + Q_UNUSED(result); } void tst_QDateTime::toMSecsSinceEpoch2050Tz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2050; jd < JULIAN_DAY_2060; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + qint64 result; + const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { - foreach (const QDateTime &test, list) - qint64 result = test.toMSecsSinceEpoch(); + for (const QDateTime &test : list) + result = test.toMSecsSinceEpoch(); } + Q_UNUSED(result); } void tst_QDateTime::setDate() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setDate(QDate::fromJulianDay(JULIAN_DAY_2010)); } } void tst_QDateTime::setTime() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setTime(QTime(12, 0, 0)); } } void tst_QDateTime::setTimeSpec() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setTimeSpec(Qt::UTC); } } void tst_QDateTime::setOffsetFromUtc() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setOffsetFromUtc(3600); } } void tst_QDateTime::setMSecsSinceEpoch() { - qint64 msecs = qint64(JULIAN_DAY_2010 + 180) * MSECS_PER_DAY; - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setMSecsSinceEpoch(msecs); } } void tst_QDateTime::setMSecsSinceEpochTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) - test.setMSecsSinceEpoch((JULIAN_DAY_2010 + 180) * MSECS_PER_DAY); + for (QDateTime test : list) + test.setMSecsSinceEpoch(msecs); } } void tst_QDateTime::toString() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2011; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toString(QStringLiteral("yyy-MM-dd hh:mm:ss.zzz t")); } } void tst_QDateTime::toStringTextFormat() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2011; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toString(Qt::TextDate); } } void tst_QDateTime::toStringIsoFormat() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2011; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toString(Qt::ISODate); } } void tst_QDateTime::addDays() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QDateTime next; QBENCHMARK { - foreach (const QDateTime &test, list) - test.addDays(1); + for (const QDateTime &test : list) + next = test.addDays(1); } + Q_UNUSED(next); } void tst_QDateTime::addDaysTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) QDateTime result = test.addDays(1); } } void tst_QDateTime::addMSecs() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QDateTime next; QBENCHMARK { - foreach (const QDateTime &test, list) - test.addMSecs(1); + for (const QDateTime &test : list) + next = test.addMSecs(1); } + Q_UNUSED(next); } void tst_QDateTime::addMSecsTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) QDateTime result = test.addMSecs(1); } } void tst_QDateTime::toTimeSpec() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toTimeSpec(Qt::UTC); } } void tst_QDateTime::toOffsetFromUtc() { - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toOffsetFromUtc(3600); } } void tst_QDateTime::daysTo() { - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.daysTo(other); } } void tst_QDateTime::msecsTo() { - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.msecsTo(other); } } @@ -449,12 +420,11 @@ void tst_QDateTime::msecsTo() void tst_QDateTime::equivalent() { bool result; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = (test == other); } Q_UNUSED(result) @@ -463,12 +433,11 @@ void tst_QDateTime::equivalent() void tst_QDateTime::equivalentUtc() { bool result = false; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY, Qt::UTC); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = (test == other); } Q_UNUSED(result) @@ -477,12 +446,11 @@ void tst_QDateTime::equivalentUtc() void tst_QDateTime::lessThan() { bool result = false; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = (test < other); } Q_UNUSED(result) @@ -491,12 +459,11 @@ void tst_QDateTime::lessThan() void tst_QDateTime::lessThanUtc() { bool result = false; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY, Qt::UTC); - QList<QDateTime> list; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = (test < other); } Q_UNUSED(result) @@ -573,25 +540,31 @@ void tst_QDateTime::fromStringIso() void tst_QDateTime::fromMSecsSinceEpoch() { + const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; + const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; QBENCHMARK { - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) + for (int jd = start; jd < end; ++jd) QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::LocalTime); } } void tst_QDateTime::fromMSecsSinceEpochUtc() { + const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; + const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; QBENCHMARK { - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) + for (int jd = start; jd < end; ++jd) QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::UTC); } } void tst_QDateTime::fromMSecsSinceEpochTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); + const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; + const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; + const QTimeZone cet("Europe/Oslo"); QBENCHMARK { - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) + for (int jd = start; jd < end; ++jd) QDateTime test = QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, cet); } } |